|
| 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 path from 'path'; |
| 9 | +import os from 'os'; |
| 10 | +import {cleanup, writeFiles} from '../Utils'; |
| 11 | +import runJest from '../runJest'; |
| 12 | + |
| 13 | +const DIR = path.resolve(os.tmpdir(), 'fatal-worker-error'); |
| 14 | + |
| 15 | +beforeEach(() => cleanup(DIR)); |
| 16 | +afterAll(() => cleanup(DIR)); |
| 17 | + |
| 18 | +const NUMBER_OF_TESTS_TO_FORCE_USING_WORKERS = 25; |
| 19 | + |
| 20 | +test('fails a test that terminates the worker with a fatal error', () => { |
| 21 | + const testFiles = { |
| 22 | + '__tests__/fatalWorkerError.test.js': ` |
| 23 | + test('fatal worker error', () => { |
| 24 | + process.exit(134); |
| 25 | + }); |
| 26 | + `, |
| 27 | + }; |
| 28 | + |
| 29 | + for (let i = 0; i <= NUMBER_OF_TESTS_TO_FORCE_USING_WORKERS; i++) { |
| 30 | + testFiles[`__tests__/test${i}.test.js`] = ` |
| 31 | + test('test ${i}', () => {}); |
| 32 | + `; |
| 33 | + } |
| 34 | + |
| 35 | + writeFiles(DIR, { |
| 36 | + ...testFiles, |
| 37 | + 'package.json': '{}', |
| 38 | + }); |
| 39 | + |
| 40 | + const {status, stderr} = runJest(DIR, ['--maxWorkers=2']); |
| 41 | + |
| 42 | + const numberOfTestsPassed = (stderr.match(/\bPASS\b/g) || []).length; |
| 43 | + |
| 44 | + expect(status).not.toBe(0); |
| 45 | + expect(numberOfTestsPassed).toBe(Object.keys(testFiles).length - 1); |
| 46 | + expect(stderr).toContain('FAIL __tests__/fatalWorkerError.test.js'); |
| 47 | + expect(stderr).toContain('Call retries were exceeded'); |
| 48 | +}); |
0 commit comments