-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make --onlyfailures work in non-watch mode
- Loading branch information
1 parent
0eab327
commit 2b3630b
Showing
13 changed files
with
130 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {tmpdir} from 'os'; | ||
import * as path from 'path'; | ||
import * as fs from 'graceful-fs'; | ||
import {cleanup, writeFiles} from '../Utils'; | ||
import runJest from '../runJest'; | ||
|
||
const DIR = path.resolve(tmpdir(), 'non-watch-mode-onlyFailures'); | ||
|
||
beforeEach(() => cleanup(DIR)); | ||
afterEach(() => cleanup(DIR)); | ||
|
||
test('onlyFailures flag works in non-watch mode', () => { | ||
writeFiles(DIR, { | ||
'__tests__/a.js': ` | ||
test('bar', () => { expect('bar').toBe('foo'); }); | ||
`, | ||
'__tests__/b.js': ` | ||
test('foo', () => { expect('foo').toBe('foo'); }); | ||
`, | ||
'package.json': JSON.stringify({ | ||
jest: { | ||
testEnvironment: 'node', | ||
}, | ||
}), | ||
}); | ||
|
||
let stdout, stderr; | ||
|
||
({stdout, stderr} = runJest(DIR)); | ||
expect(stdout).toBe(''); | ||
expect(stderr).toMatch('FAIL __tests__/a.js'); | ||
expect(stderr).toMatch('PASS __tests__/b.js'); | ||
|
||
// only the failed test should run and it should fail | ||
({stdout, stderr} = runJest(DIR, ['--onlyFailures'])); | ||
expect(stdout).toBe(''); | ||
expect(stderr).toMatch('FAIL __tests__/a.js'); | ||
expect(stderr).not.toMatch('__tests__/b.js'); | ||
|
||
// fix the failing test | ||
const data = "test('bar 1', () => { expect('bar').toBe('bar'); })"; | ||
fs.writeFileSync(path.join(DIR, '__tests__/a.js'), data); | ||
|
||
// only the failed test should run and it should pass | ||
({stdout, stderr} = runJest(DIR, ['--onlyFailures'])); | ||
expect(stdout).toBe(''); | ||
expect(stderr).toMatch('PASS __tests__/a.js'); | ||
expect(stderr).not.toMatch('__tests__/b.js'); | ||
|
||
// No test should run | ||
({stdout, stderr} = runJest(DIR, ['--onlyFailures'])); | ||
expect(stdout).toBe('No failed test found.'); | ||
expect(stderr).toBe(''); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters