Skip to content

Commit 33c8601

Browse files
committed
e quiet test run
1 parent 09a6007 commit 33c8601

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

webapp/jest-quiet-reporter.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
class QuietReporter {
2+
constructor(globalConfig, options) {
3+
this._globalConfig = globalConfig;
4+
this._options = options;
5+
}
6+
7+
onRunStart() {
8+
}
9+
10+
onTestFileStart() {
11+
// Suppress test file start output
12+
}
13+
14+
onTestSuiteStart() {
15+
// Suppress test suite start output
16+
}
17+
18+
onTestStart() {
19+
// Suppress individual test start output
20+
}
21+
22+
onTestResult() {
23+
// Suppress individual test result output
24+
}
25+
26+
onRunComplete(contexts, results) {
27+
const { numFailedTests, numPassedTests, numTotalTests, testResults } = results;
28+
const numFailedTestSuites = testResults.filter(t => t.numFailingTests > 0).length;
29+
const numPassedTestSuites = testResults.filter(t => t.numFailingTests === 0).length;
30+
const numTotalTestSuites = testResults.length;
31+
32+
if (numFailedTests > 0) {
33+
// Show details only when tests fail
34+
testResults.forEach(testResult => {
35+
if (testResult.numFailingTests > 0) {
36+
console.log(`FAIL ${testResult.testFilePath}`);
37+
testResult.testResults.forEach(test => {
38+
if (test.status === 'failed') {
39+
console.log(` ✕ ${test.title}`);
40+
if (test.failureMessages && test.failureMessages.length > 0) {
41+
test.failureMessages.forEach(message => {
42+
console.log(` ${message}`);
43+
});
44+
}
45+
}
46+
});
47+
}
48+
});
49+
}
50+
51+
if (numFailedTests === 0) {
52+
console.log(`✅ All ${numTotalTests} tests passed!`);
53+
} else {
54+
console.log(`❌ ${numFailedTests} failed, ${numPassedTests} passed (${numTotalTests} total)`);
55+
}
56+
}
57+
}
58+
59+
module.exports = QuietReporter;

webapp/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"deploy": "gh-pages -d build",
2424
"start": "react-app-rewired start",
2525
"build": "react-app-rewired build",
26-
"test": "react-app-rewired test --watchAll=false",
26+
"test": "node run-tests-quiet.js",
2727
"test:watch": "react-app-rewired test",
2828
"eject": "react-scripts eject"
2929
},
@@ -45,6 +45,12 @@
4545
"last 1 safari version"
4646
]
4747
},
48+
"jest": {
49+
"reporters": [
50+
"<rootDir>/jest-quiet-reporter.js"
51+
],
52+
"verbose": false
53+
},
4854
"devDependencies": {
4955
"execa": "^5.1.1",
5056
"gh-pages": "^4.0.0",

webapp/run-tests-quiet.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { spawn } = require('child_process');
2+
3+
const child = spawn('npx', ['react-app-rewired', 'test', '--watchAll=false', '--verbose=false', '--noStackTrace'], {
4+
stdio: ['inherit', 'pipe', 'pipe'],
5+
shell: true
6+
});
7+
8+
child.stdout.on('data', (data) => {
9+
const output = data.toString();
10+
if (!output.includes('Determining test suites to run')) {
11+
process.stdout.write(output);
12+
}
13+
});
14+
15+
child.stderr.on('data', (data) => {
16+
const output = data.toString();
17+
if (!output.includes('Determining test suites to run')) {
18+
process.stderr.write(output);
19+
}
20+
});
21+
22+
child.on('close', (code) => {
23+
process.exit(code);
24+
});

0 commit comments

Comments
 (0)