Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #79 from github/only-output-on-failure
Only output anything from tests when there's a failure
Robert authored and GitHub committed Jun 24, 2020
2 parents 04adf2b + b3ffa76 commit 5bb9e6e
Showing 27 changed files with 171 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/analysis-paths.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analysis-paths.test.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/config-utils.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.test.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/external-queries.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/external-queries.test.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/fingerprints.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/fingerprints.test.js.map
2 changes: 2 additions & 0 deletions lib/setup-tools.test.js
2 changes: 1 addition & 1 deletion lib/setup-tools.test.js.map
22 changes: 22 additions & 0 deletions lib/test-utils.js
1 change: 1 addition & 0 deletions lib/test-utils.js.map
48 changes: 48 additions & 0 deletions lib/testing-utils.js
1 change: 1 addition & 0 deletions lib/testing-utils.js.map
2 changes: 2 additions & 0 deletions lib/upload-lib.test.js
2 changes: 1 addition & 1 deletion lib/upload-lib.test.js.map
2 changes: 2 additions & 0 deletions lib/util.test.js
2 changes: 1 addition & 1 deletion lib/util.test.js.map
2 changes: 1 addition & 1 deletion package.json
@@ -5,7 +5,7 @@
"description": "CodeQL action",
"scripts": {
"build": "tsc",
"test": "ava src/** --serial",
"test": "ava src/** --serial --verbose",
"lint": "tslint -p . -c tslint.json 'src/**/*.ts'",
"removeNPMAbsolutePaths": "removeNPMAbsolutePaths . --force"
},
3 changes: 3 additions & 0 deletions src/analysis-paths.test.ts
@@ -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 changes: 3 additions & 0 deletions src/config-utils.test.ts
@@ -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
3 changes: 3 additions & 0 deletions src/external-queries.test.ts
@@ -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 = [
3 changes: 3 additions & 0 deletions src/fingerprints.test.ts
@@ -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;
3 changes: 3 additions & 0 deletions src/setup-tools.test.ts
@@ -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 changes: 56 additions & 0 deletions src/testing-utils.ts
@@ -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);
}
});
}
3 changes: 3 additions & 0 deletions src/upload-lib.test.ts
@@ -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));
3 changes: 3 additions & 0 deletions src/util.test.ts
@@ -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);

0 comments on commit 5bb9e6e

Please sign in to comment.