Merge branch 'main' into report-action-aborted
This commit is contained in:
commit
559e2600c1
27 changed files with 171 additions and 8 deletions
|
|
@ -2,6 +2,9 @@ import test from 'ava';
|
|||
|
||||
import * as analysisPaths from './analysis-paths';
|
||||
import * as configUtils from './config-utils';
|
||||
import {silenceDebugOutput} from './testing-utils';
|
||||
|
||||
silenceDebugOutput(test);
|
||||
|
||||
test("emptyPaths", async t => {
|
||||
let config = new configUtils.Config();
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@ import * as fs from 'fs';
|
|||
import * as path from 'path';
|
||||
|
||||
import * as configUtils from './config-utils';
|
||||
import {silenceDebugOutput} from './testing-utils';
|
||||
import * as util from './util';
|
||||
|
||||
silenceDebugOutput(test);
|
||||
|
||||
function setInput(name: string, value: string | undefined) {
|
||||
// Transformation copied from
|
||||
// https://github.com/actions/toolkit/blob/05e39f551d33e1688f61b209ab5cdd335198f1b8/packages/core/src/core.ts#L69
|
||||
|
|
|
|||
|
|
@ -4,8 +4,11 @@ import * as path from "path";
|
|||
|
||||
import * as configUtils from "./config-utils";
|
||||
import * as externalQueries from "./external-queries";
|
||||
import {silenceDebugOutput} from './testing-utils';
|
||||
import * as util from "./util";
|
||||
|
||||
silenceDebugOutput(test);
|
||||
|
||||
test("checkoutExternalQueries", async t => {
|
||||
let config = new configUtils.Config();
|
||||
config.externalQueries = [
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ import * as fs from 'fs';
|
|||
import * as path from 'path';
|
||||
|
||||
import * as fingerprints from './fingerprints';
|
||||
import {silenceDebugOutput} from './testing-utils';
|
||||
|
||||
silenceDebugOutput(test);
|
||||
|
||||
function testHash(t: ava.Assertions, input: string, expectedHashes: string[]) {
|
||||
let index = 0;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,11 @@ import nock from 'nock';
|
|||
import * as path from 'path';
|
||||
|
||||
import * as setupTools from './setup-tools';
|
||||
import {silenceDebugOutput} from './testing-utils';
|
||||
import * as util from './util';
|
||||
|
||||
silenceDebugOutput(test);
|
||||
|
||||
test('download codeql bundle cache', async t => {
|
||||
|
||||
await util.withTmpDir(async tmpDir => {
|
||||
|
|
|
|||
56
src/testing-utils.ts
Normal file
56
src/testing-utils.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import {TestInterface} from 'ava';
|
||||
|
||||
type TestContext = {stdoutWrite: any, stderrWrite: any, testOutput: string};
|
||||
|
||||
function wrapOutput(context: TestContext) {
|
||||
// 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: Uint8Array | string, encoding?: string, cb?: (err?: Error) => void): boolean => {
|
||||
// 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;
|
||||
};
|
||||
}
|
||||
|
||||
export function silenceDebugOutput(test: TestInterface<any>) {
|
||||
const typedTest = test as TestInterface<TestContext>;
|
||||
|
||||
typedTest.beforeEach(t => {
|
||||
t.context.testOutput = "";
|
||||
|
||||
const processStdoutWrite = process.stdout.write.bind(process.stdout);
|
||||
t.context.stdoutWrite = processStdoutWrite;
|
||||
process.stdout.write = wrapOutput(t.context) as any;
|
||||
|
||||
const processStderrWrite = process.stderr.write.bind(process.stderr);
|
||||
t.context.stderrWrite = processStderrWrite;
|
||||
process.stderr.write = wrapOutput(t.context) as any;
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
import test from 'ava';
|
||||
|
||||
import {silenceDebugOutput} from './testing-utils';
|
||||
import * as uploadLib from './upload-lib';
|
||||
|
||||
silenceDebugOutput(test);
|
||||
|
||||
test('validateSarifFileSchema - valid', t => {
|
||||
const inputFile = __dirname + '/../src/testdata/valid-sarif.sarif';
|
||||
t.true(uploadLib.validateSarifFileSchema(inputFile));
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@ import test from 'ava';
|
|||
import * as fs from 'fs';
|
||||
import * as os from "os";
|
||||
|
||||
import {silenceDebugOutput} from './testing-utils';
|
||||
import * as util from './util';
|
||||
|
||||
silenceDebugOutput(test);
|
||||
|
||||
test('getToolNames', t => {
|
||||
const input = fs.readFileSync(__dirname + '/../src/testdata/tool-names.sarif', 'utf8');
|
||||
const toolNames = util.getToolNames(input);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue