|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +import {tmpdir} from 'os'; |
| 9 | +import * as path from 'path'; |
| 10 | +import {wrap} from 'jest-snapshot-serializer-raw'; |
| 11 | +import { |
| 12 | + cleanup, |
| 13 | + createEmptyPackage, |
| 14 | + extractSortedSummary, |
| 15 | + writeFiles, |
| 16 | +} from '../Utils'; |
| 17 | +import {runContinuous} from '../runJest'; |
| 18 | + |
| 19 | +const tempDir = path.resolve(tmpdir(), 'circular-inequality-test'); |
| 20 | + |
| 21 | +beforeEach(() => { |
| 22 | + createEmptyPackage(tempDir); |
| 23 | +}); |
| 24 | + |
| 25 | +afterEach(() => { |
| 26 | + cleanup(tempDir); |
| 27 | +}); |
| 28 | + |
| 29 | +test('handles circular inequality properly', async () => { |
| 30 | + const testFileContent = ` |
| 31 | + it('test', () => { |
| 32 | + const foo = {}; |
| 33 | + foo.ref = foo; |
| 34 | +
|
| 35 | + expect(foo).toEqual({}); |
| 36 | + }); |
| 37 | +
|
| 38 | + it('test 2', () => { |
| 39 | + const foo = {}; |
| 40 | + foo.ref = foo; |
| 41 | +
|
| 42 | + expect(foo).toEqual({}); |
| 43 | + }); |
| 44 | + `; |
| 45 | + |
| 46 | + writeFiles(tempDir, { |
| 47 | + '__tests__/test-1.js': testFileContent, |
| 48 | + '__tests__/test-2.js': testFileContent, |
| 49 | + }); |
| 50 | + |
| 51 | + const {end, waitUntil} = runContinuous( |
| 52 | + tempDir, |
| 53 | + ['--no-watchman', '--watch-all'], |
| 54 | + // timeout in case the `waitUntil` below doesn't fire |
| 55 | + {stripAnsi: true, timeout: 5000}, |
| 56 | + ); |
| 57 | + |
| 58 | + await waitUntil(({stderr}) => { |
| 59 | + return stderr.includes('Ran all test suites.'); |
| 60 | + }); |
| 61 | + |
| 62 | + const {stderr} = await end(); |
| 63 | + |
| 64 | + const {summary, rest} = extractSortedSummary(stderr); |
| 65 | + expect(wrap(rest)).toMatchSnapshot(); |
| 66 | + expect(wrap(summary)).toMatchSnapshot(); |
| 67 | +}); |
0 commit comments