Skip to content

Commit

Permalink
feat(test): add dot report for aslushnikov (#3317)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Aug 6, 2020
1 parent 0a5d340 commit 5c0b88f
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"ctest": "cross-env BROWSER=chromium jest",
"ftest": "cross-env BROWSER=firefox jest",
"wtest": "cross-env BROWSER=webkit jest",
"ctestd": "cross-env BROWSER=chromium jest --reporters=./jest/dot.js --colors",
"ftestd": "cross-env BROWSER=firefox jest --reporters=./jest/dot.js --colors",
"wtestd": "cross-env BROWSER=webkit jest --reporters=./jest/dot.js --colors",
"test": "npm run ctest && npm run ftest && npm run wtest",
"eslint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe --ext js,ts ./src || eslint --ext js,ts ./src",
"tsc": "tsc -p .",
Expand Down
70 changes: 70 additions & 0 deletions test/jest/dot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Copyright Microsoft Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const colors = require('colors/safe');
const { runTestsByPath } = require('../../jest.config');
const failures = [];

module.exports = function Reporter() {
this.onRunStart = (results, options) => {
process.stdout.write('\n');
}

this.onRunComplete = (test, runResults) => {
process.stdout.write('\n');

const ranTests = runResults.numFailedTests + runResults.numPassedTests;
const summary = [`ok - ${colors.green(runResults.numPassedTests)}`];
if (runResults.numFailedTests)
summary.push(`failed - ${colors.red(runResults.numFailedTests)}`);
if (ranTests < runResults.numTotalTests)
summary.push(`skipped - ${colors.yellow(runResults.numTotalTests - ranTests)}`);
const summaryText = `Ran ${ranTests} of ${runResults.numTotalTests} (${summary.join(', ')})`;
process.stdout.write('\n');
process.stdout.write(summaryText);
process.stdout.write('\n');

for (let i = 0; i < failures.length; ++i) {
const [test, testCaseResult] = failures[i];
const path = test.path.replace(/.*test/, 'test');
const name = colors.yellow(path) + ' — ' + colors.bold(colors.yellow(testCaseResult.fullName));
process.stderr.write(`\n${i + 1}) ${colors.red('[FAIL]')} ${name}\n\n`);
process.stderr.write(testCaseResult.failureMessages + '\n');
}

};

this.onTestCaseResult = (test, testCaseResult) => {
const status = testCaseResult.status;
if (status === 'passed')
process.stdout.write(colors.green('\u00B7'));
if (status === 'failed')
process.stdout.write(colors.red('F'));
if (testCaseResult.status === 'failed')
failures.push([test, testCaseResult]);
}
}

process.on('SIGINT', async () => {
for (let i = 0; i < failures.length; ++i) {
const [test, testCaseResult] = failures[i];
const path = test.path.replace(/.*test/, 'test');
const name = colors.yellow(path) + ' — ' + colors.bold(colors.yellow(testCaseResult.fullName));
process.stderr.write(`\n${i + 1}) ${colors.red('[FAIL]')} ${name}\n\n`);
process.stderr.write(testCaseResult.failureMessages + '\n');
}
process.exit(130);
});

0 comments on commit 5c0b88f

Please sign in to comment.