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