Skip to content

Commit

Permalink
fix(jest-runner): Support Jest v27 (#2861)
Browse files Browse the repository at this point in the history
Support new defaults for Jest 27 yet still supporting Jest <27 with those defaults.
  • Loading branch information
Garethp committed May 28, 2021
1 parent ecc53ee commit 8d3560b
Show file tree
Hide file tree
Showing 50 changed files with 9,311 additions and 4,485 deletions.
4,867 changes: 1,550 additions & 3,317 deletions e2e/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions e2e/package.json
Expand Up @@ -19,7 +19,7 @@
"grunt": "~1.0.4",
"jasmine": "~3.6.2",
"jasmine-core": "~3.6.0",
"jest": "~26.6.1",
"jest": "~27.0.1",
"jest-environment-jsdom-sixteen": "^1.0.3",
"karma": "~6.0.1",
"karma-chai": "~0.1.0",
Expand All @@ -34,7 +34,7 @@
"mutation-testing-metrics": "1.7.2",
"rxjs": "~6.5.3",
"semver": "~6.3.0",
"ts-jest": "~26.3.0",
"ts-jest": "~27.0.1",
"ts-loader": "~8.0.3",
"ts-node": "~7.0.0",
"typescript": "~3.9.2",
Expand Down
37 changes: 22 additions & 15 deletions e2e/tasks/run-e2e-tests.ts
Expand Up @@ -5,50 +5,57 @@ import semver from 'semver';
import os from 'os';
import { from, defer } from 'rxjs';
import { tap, mergeAll, map } from 'rxjs/operators';
import minimatch from 'minimatch';

const testRootDir = path.resolve(__dirname, '..', 'test');

function runE2eTests() {
const testDirs = fs.readdirSync(testRootDir).filter(dir => fs.statSync(path.join(testRootDir, dir)).isDirectory());
const pattern = process.argv[2] ?? '*';
const testDirs = fs
.readdirSync(testRootDir, { withFileTypes: true })
.filter((dir) => dir.isDirectory())
.map((dir) => dir.name)
.filter(minimatch.filter(pattern));

console.log(`Running e2e test in ${testDirs.length ? testDirs.join(', ') : '<none>'}`);
console.log(`(matched with ${pattern})`);
// Create test$, an observable of test runs
const test$ = from(testDirs).pipe(map(testDir => defer(() => runTest(testDir))));
const test$ = from(testDirs).pipe(map((testDir) => defer(() => runTest(testDir))));

let testsRan = 0;
return test$.pipe(
mergeAll(os.cpus().length && 2), // use mergeAll to limit concurrent test runs
tap(testDir => console.log(`\u2714 ${testDir} tested (${++testsRan}/${testDirs.length})`)),
tap((testDir) => console.log(`\u2714 ${testDir} tested (${++testsRan}/${testDirs.length})`))
);
}

runE2eTests()
.subscribe({
complete: () => console.log('✅ Done'),
error: err => {
console.error(err);
process.exit(1);
},
});
runE2eTests().subscribe({
complete: () => console.log('✅ Done'),
error: (err) => {
console.error(err);
process.exit(1);
},
});

function execNpm(command: string, testDir: string, stream: boolean) {
const currentTestDir = path.resolve(testRootDir, testDir);
console.log(`Exec ${testDir} npm ${command}`);
const testProcess = execa('npm', [command], { timeout: 500000, cwd: currentTestDir, stdio: 'pipe' });
let stderr = '';
let stdout = '';
testProcess.stderr!.on('data', chunk => {
testProcess.stderr!.on('data', (chunk) => {
stderr += chunk.toString();
if (stream) {
console.error(chunk.toString());
}
});
testProcess.stdout!.on('data', chunk => {
stdout += chunk.toString()
testProcess.stdout!.on('data', (chunk) => {
stdout += chunk.toString();
if (stream) {
console.log(chunk.toString());
}
});
return testProcess.catch(error => {
return testProcess.catch((error) => {
console.log(`X ${testDir}`);
console.log(stdout);
console.error(stderr);
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/jest-custom-env/src/calculator-element.test.js
@@ -1,5 +1,5 @@
/**
* @jest-environment @stryker-mutator/jest-runner/jest-env/jsdom-sixteen
* @jest-environment @stryker-mutator/jest-runner/jest-env/jsdom
*/
import './calculator-element';

Expand Down

0 comments on commit 8d3560b

Please sign in to comment.