|
| 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 | +// eslint-disable-next-line import/named |
| 10 | +import {sync as spawnSync} from 'execa'; |
| 11 | +import {skipSuiteOnWindows} from '@jest/test-utils'; |
| 12 | + |
| 13 | +skipSuiteOnWindows(); |
| 14 | + |
| 15 | +const JEST_RUNTIME = path.resolve(__dirname, '../../bin/jest-runtime-cli.js'); |
| 16 | + |
| 17 | +const run = args => |
| 18 | + spawnSync(JEST_RUNTIME, args, { |
| 19 | + cwd: process.cwd(), |
| 20 | + env: process.env, |
| 21 | + reject: false, |
| 22 | + }); |
| 23 | + |
| 24 | +describe('Runtime CLI', () => { |
| 25 | + it('fails with no path', () => { |
| 26 | + const expectedOutput = |
| 27 | + 'Please provide a path to a script. (See --help for details)'; |
| 28 | + expect(run([]).stdout).toBe(expectedOutput); |
| 29 | + }); |
| 30 | + |
| 31 | + it('displays script output', () => { |
| 32 | + const scriptPath = path.resolve(__dirname, './test_root/logging.js'); |
| 33 | + expect(run([scriptPath, '--no-cache']).stdout).toMatch('Hello, world!'); |
| 34 | + }); |
| 35 | + |
| 36 | + it('always disables automocking', () => { |
| 37 | + const scriptPath = path.resolve(__dirname, './test_root/logging.js'); |
| 38 | + const output = run([ |
| 39 | + scriptPath, |
| 40 | + '--no-cache', |
| 41 | + '--config=' + |
| 42 | + JSON.stringify({ |
| 43 | + automock: true, |
| 44 | + }), |
| 45 | + ]); |
| 46 | + expect(output.stdout).toMatch('Hello, world!'); |
| 47 | + }); |
| 48 | + |
| 49 | + it('throws script errors', () => { |
| 50 | + const scriptPath = path.resolve(__dirname, './test_root/throwing.js'); |
| 51 | + expect(run([scriptPath, '--no-cache']).stderr).toMatch('Error: throwing'); |
| 52 | + }); |
| 53 | +}); |
0 commit comments