diff --git a/e2e/__tests__/toMatchNamedSnapshot.test.ts b/e2e/__tests__/toMatchNamedSnapshot.test.ts index 906a295bd5be..dbf260ec1765 100644 --- a/e2e/__tests__/toMatchNamedSnapshot.test.ts +++ b/e2e/__tests__/toMatchNamedSnapshot.test.ts @@ -289,3 +289,51 @@ test('handles property matchers with deep properties', () => { expect(exitCode).toBe(1); } }); + +test('support concurrent testing', () => { + const filename = 'match-snapshot-when-test-concurrent.test.js'; + const template = makeTemplate(`describe('group 1', () => { + $1('concurrent 1', async () => { + expect('concurrent 1-1').toMatchNamedSnapshot('test1'); + $2 + }); + + $1('concurrent 2', async () => { + expect('concurrent 1-2').toMatchNamedSnapshot('test2'); + $2 + }); + }); + + describe('group 2', () => { + $1('concurrent 1', async () => { + expect('concurrent 2-1').toMatchNamedSnapshot('test3'); + $2 + }); + + $1('concurrent 2', async () => { + expect('concurrent 2-2').toMatchNamedSnapshot('test4'); + $2 + }); + }); + `); + { + writeFiles(TESTS_DIR, {[filename]: template(['test'])}); + const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]); + console.log(stderr); + + expect(exitCode).toBe(0); + } + + { + writeFiles(TESTS_DIR, { + [filename]: template([ + 'test.concurrent', + 'await new Promise(resolve => setTimeout(resolve, 5000));', + ]), + }); + const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]); + console.log(stderr); + + expect(exitCode).toBe(0); + } +}); diff --git a/e2e/__tests__/toMatchSnapshot.test.ts b/e2e/__tests__/toMatchSnapshot.test.ts index 7edc3c43cf2b..dd9715c6c38c 100644 --- a/e2e/__tests__/toMatchSnapshot.test.ts +++ b/e2e/__tests__/toMatchSnapshot.test.ts @@ -304,3 +304,51 @@ test('handles property matchers with deep properties', () => { expect(exitCode).toBe(1); } }); + +test('does not support concurrent testing', () => { + const filename = 'match-snapshot-when-test-concurrent.test.js'; + const template = makeTemplate(`describe('group 1', () => { + $1('concurrent 1', async () => { + expect('concurrent 1-1').toMatchSnapshot(); + $2 + }); + + $1('concurrent 2', async () => { + expect('concurrent 1-2').toMatchSnapshot(); + $2 + }); + }); + + describe('group 2', () => { + $1('concurrent 1', async () => { + expect('concurrent 2-1').toMatchSnapshot(); + $2 + }); + + $1('concurrent 2', async () => { + expect('concurrent 2-2').toMatchSnapshot(); + $2 + }); + }); + `); + { + writeFiles(TESTS_DIR, {[filename]: template(['test'])}); + const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]); + + expect(stderr).toMatch('4 snapshots written'); + expect(exitCode).toBe(0); + } + + { + writeFiles(TESTS_DIR, { + [filename]: template([ + 'test.concurrent', + 'await new Promise(resolve => setTimeout(resolve, 5000));', + ]), + }); + const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]); + + expect(stderr).toMatch('snapshots obsolete'); + expect(exitCode).toBe(1); + } +});