-
-
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.
Implement 'jest.requireMock' (#4292)
Similar to #4260
- Loading branch information
1 parent
cb6bcba
commit 07855c3
Showing
5 changed files
with
73 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
const os = require('os'); | ||
const skipOnWindows = require('../../scripts/skip_on_windows'); | ||
const {cleanup, writeFiles} = require('../utils'); | ||
const runJest = require('../runJest'); | ||
|
||
const DIR = path.resolve(os.tmpdir(), 'jest_require_mock_test'); | ||
|
||
skipOnWindows.suite(); | ||
|
||
beforeEach(() => cleanup(DIR)); | ||
afterAll(() => cleanup(DIR)); | ||
|
||
test('understands dependencies using require.requireMock', () => { | ||
writeFiles(DIR, { | ||
'.watchmanconfig': '', | ||
'__tests__/a.test.js': ` | ||
const a = require.requireMock('../a'); | ||
test('a', () => {}); | ||
`, | ||
'__tests__/b.test.js': `test('b', () => {});`, | ||
'a.js': `module.exports = {}`, | ||
'package.json': JSON.stringify({jest: {}}), | ||
}); | ||
|
||
let stdout; | ||
let stderr; | ||
({stdout, stderr} = runJest(DIR, ['--findRelatedTests', 'a.js'])); | ||
|
||
expect(stdout).not.toMatch('No tests found'); | ||
expect(stderr).toMatch('PASS __tests__/a.test.js'); | ||
expect(stderr).not.toMatch('PASS __tests__/b.test.js'); | ||
|
||
// change to jest.requireMock | ||
writeFiles(DIR, { | ||
'__tests__/a.test.js': ` | ||
const a = jest.requireMock('../a'); | ||
test('a', () => {}); | ||
`, | ||
}); | ||
|
||
({stderr, stdout} = runJest(DIR, ['--findRelatedTests', 'a.js'])); | ||
expect(stdout).not.toMatch('No tests found'); | ||
expect(stderr).toMatch('PASS __tests__/a.test.js'); | ||
expect(stderr).not.toMatch('PASS __tests__/b.test.js'); | ||
}); |
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