Permalink
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/lib/testing-utils.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
48 lines (48 sloc)
1.81 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
Object.defineProperty(exports, "__esModule", { value: true }); | |
function wrapOutput(context) { | |
// Function signature taken from Socket.write. | |
// Note there are two overloads: | |
// write(buffer: Uint8Array | string, cb?: (err?: Error) => void): boolean; | |
// write(str: Uint8Array | string, encoding?: string, cb?: (err?: Error) => void): boolean; | |
return (chunk, encoding, cb) => { | |
// Work out which method overload we are in | |
if (cb === undefined && typeof encoding === 'function') { | |
cb = encoding; | |
encoding = undefined; | |
} | |
// Record the output | |
if (typeof chunk === 'string') { | |
context.testOutput += chunk; | |
} | |
else { | |
context.testOutput += new TextDecoder(encoding || 'utf-8').decode(chunk); | |
} | |
// Satisfy contract by calling callback when done | |
if (cb !== undefined && typeof cb === 'function') { | |
cb(); | |
} | |
return true; | |
}; | |
} | |
function silenceDebugOutput(test) { | |
const typedTest = test; | |
typedTest.beforeEach(t => { | |
t.context.testOutput = ""; | |
const processStdoutWrite = process.stdout.write.bind(process.stdout); | |
t.context.stdoutWrite = processStdoutWrite; | |
process.stdout.write = wrapOutput(t.context); | |
const processStderrWrite = process.stderr.write.bind(process.stderr); | |
t.context.stderrWrite = processStderrWrite; | |
process.stderr.write = wrapOutput(t.context); | |
}); | |
typedTest.afterEach.always(t => { | |
process.stdout.write = t.context.stdoutWrite; | |
process.stderr.write = t.context.stderrWrite; | |
if (!t.passed) { | |
process.stdout.write(t.context.testOutput); | |
} | |
}); | |
} | |
exports.silenceDebugOutput = silenceDebugOutput; | |
//# sourceMappingURL=testing-utils.js.map |