Skip to content

Commit

Permalink
Add concurrent e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
madcapnmckay committed Nov 15, 2024
1 parent 9d167c6 commit f650b5f
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
84 changes: 84 additions & 0 deletions e2e/__tests__/__snapshots__/circusConcurrent.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`runs the tests in the correct order 1`] = `
" console.log
[[beforeAll]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[test one start]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[test three start]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[test five start]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[test six start]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[test seven (fails) start]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[test three end]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[test eight start]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[test one end]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[test nine start]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[test six end]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[test ten (fails) start]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[test eight end]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[test nine end]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[test five end]]
at log (__tests__/concurrent.test.js:12:29)
console.log
[[afterAll]]
at log (__tests__/concurrent.test.js:12:29)
"
`;
24 changes: 24 additions & 0 deletions e2e/__tests__/circusConcurrent.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {skipSuiteOnJasmine} from '@jest/test-utils';
import runJest, {json as runWithJson} from '../runJest';

skipSuiteOnJasmine();

it('runs the correct number of tests', () => {
const {json} = runWithJson('circus-concurrent', ['concurrent.test.js']);

expect(json.numTotalTests).toBe(10);
expect(json.numPassedTests).toBe(6);
expect(json.numFailedTests).toBe(2);
expect(json.numPendingTests).toBe(2);
});

it('runs the tests in the correct order', () => {
const {stdout} = runJest('circus-concurrent', ['concurrent.test.js']);
expect(stdout).toMatchSnapshot();

Check failure on line 23 in e2e/__tests__/circusConcurrent.test.ts

View workflow job for this annotation

GitHub Actions / Node LTS on Ubuntu with coverage (3/4)

runs the tests in the correct order

expect(received).toMatchSnapshot() Snapshot name: `runs the tests in the correct order 1` - Snapshot - 2 + Received + 2 @@ -57,16 +57,16 @@ [[test ten (fails) start]] at log (__tests__/concurrent.test.js:12:29) console.log - [[test eight end]] + [[test nine end]] at log (__tests__/concurrent.test.js:12:29) console.log - [[test nine end]] + [[test eight end]] at log (__tests__/concurrent.test.js:12:29) console.log [[test five end]] at Object.toMatchSnapshot (e2e/__tests__/circusConcurrent.test.ts:23:18)
});
58 changes: 58 additions & 0 deletions e2e/circus-concurrent/__tests__/concurrent.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const {setTimeout} = require('timers/promises');

const marker = s => console.log(`[[${s}]]`);

beforeAll(() => marker('beforeAll'));
afterAll(() => marker('afterAll'));

beforeEach(() => marker('beforeEach'));
afterEach(() => marker('afterEach'));

const testFn = (name, delay, fail) => {
return async () => {
marker(`test ${name} start`);
await setTimeout(delay);
if (fail) {
throw new Error(`${name} failed`);
}
expect(name).toBe(name);
expect.assertions(1);
marker(`test ${name} end`);
};
};

it.concurrent('one', testFn('one', 100));
it.concurrent.skip('two (skipped)', testFn('two (skipped)', 100));

describe('level 1', () => {
beforeEach(() => marker('beforeEach level 1'));
afterEach(() => marker('afterEach level 1'));

it.concurrent('three', testFn('three', 60));

it.concurrent.skip('four (skipped)', testFn('four (skipped)', 100));

describe('level 2', () => {
beforeEach(() => marker('beforeEach level 2'));
afterEach(() => marker('afterEach level 2'));
it.concurrent('five', testFn('five', 150));

it.concurrent('six', testFn('six', 100));
});

it.concurrent('seven (fails)', testFn('seven (fails)', 100, true));
it.concurrent('eight', testFn('eight', 50));
});

it.concurrent('nine', testFn('nine', 20));

it.concurrent('ten (fails)', testFn('ten (fails)', 30, true));

0 comments on commit f650b5f

Please sign in to comment.