|
| 1 | +/** |
| 2 | + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. |
| 3 | + * |
| 4 | + * This source code is licensed under the BSD-style license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. An additional grant |
| 6 | + * of patent rights can be found in the PATENTS file in the same directory. |
| 7 | + * |
| 8 | + * @flow |
| 9 | + */ |
| 10 | + |
| 11 | +'use strict'; |
| 12 | + |
| 13 | +import runJest from '../runJest'; |
| 14 | +import {cleanup, writeFiles} from '../utils'; |
| 15 | +import os from 'os'; |
| 16 | +import path from 'path'; |
| 17 | + |
| 18 | +const skipOnWindows = require('../../scripts/skip_on_windows'); |
| 19 | +const DIR = path.resolve(os.tmpdir(), 'run_tests_by_path_test'); |
| 20 | + |
| 21 | +skipOnWindows.suite(); |
| 22 | + |
| 23 | +beforeEach(() => cleanup(DIR)); |
| 24 | +afterEach(() => cleanup(DIR)); |
| 25 | + |
| 26 | +test('runs tests by exact path', () => { |
| 27 | + writeFiles(DIR, { |
| 28 | + '.watchmanconfig': '', |
| 29 | + '__tests__/t1.test.js': 'it("foo", () => {})', |
| 30 | + '__tests__/t2.test.js': 'it("bar", () => {})', |
| 31 | + 'package.json': JSON.stringify({jest: {testEnvironment: 'node'}}), |
| 32 | + }); |
| 33 | + |
| 34 | + // Passing an exact path executes only the given test. |
| 35 | + const run1 = runJest(DIR, ['--runTestsByPath', '__tests__/t1.test.js']); |
| 36 | + expect(run1.stderr).toMatch('PASS __tests__/t1.test.js'); |
| 37 | + expect(run1.stderr).not.toMatch('PASS __tests__/t2.test.js'); |
| 38 | + |
| 39 | + // When running with thte flag and a pattern, no test is found. |
| 40 | + const run2 = runJest(DIR, ['--runTestsByPath', '__tests__/t']); |
| 41 | + expect(run2.stdout).toMatch(/no tests found/i); |
| 42 | + |
| 43 | + // When ran without the flag and a pattern, both tests are found. |
| 44 | + const run3 = runJest(DIR, ['__tests__/t']); |
| 45 | + expect(run3.stderr).toMatch('PASS __tests__/t1.test.js'); |
| 46 | + expect(run3.stderr).toMatch('PASS __tests__/t2.test.js'); |
| 47 | +}); |
0 commit comments