diff --git a/package.json b/package.json index c9168072799ef..f701c60d0b6b4 100644 --- a/package.json +++ b/package.json @@ -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 .", diff --git a/test/jest/dot.js b/test/jest/dot.js new file mode 100644 index 0000000000000..ee0493b7bd893 --- /dev/null +++ b/test/jest/dot.js @@ -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); +});