-
-
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.
Throw when moduleNameMapper points to inexistent module (#3567)
* Fixes issue-1888 * Prettier fix and chalk to package.json dependencies * Added integration test * Added integration test * Refactored test to use snapshot * Refactored test to use snapshot * Rename to camelCase * Fixed lint warnings * Fixed lint warnings * Minor fixes * Use strict on integration tests * Added integration test * Refactored test to use snapshot * Fixed lint warnings * Added integration test * Refactored test to use snapshot * Minor fixes * Use strict on integration tests * Use Error instead of ValidationError to avoid duplicate message * Add fb copyright back to auto_reset_mocks test * Removed jest-validate dep from jest-resolve * Run prettier * Revert auto_clear_mocks change * Revert auto_reset_mocks change * Normalize test paths on windows * Don't use slash to normalize summary * Skip test on windows
- Loading branch information
Showing
14 changed files
with
157 additions
and
5 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
integration_tests/__tests__/__snapshots__/module_name_mapper.test.js.snap
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,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`moduleNameMapper correct configuration 1`] = ` | ||
" PASS __tests__/index.js | ||
✓ moduleNameMapping correct configuration | ||
" | ||
`; | ||
|
||
exports[`moduleNameMapper wrong configuration 1`] = ` | ||
" FAIL __tests__/index.js | ||
● Test suite failed to run | ||
Configuration error: | ||
Unknown module in configuration option moduleNameMapper | ||
Please check: | ||
\\"moduleNameMapper\\": { | ||
\\"/\\\\.(css|less)$/\\": \\"no-such-module\\" | ||
} | ||
" | ||
`; |
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,31 @@ | ||
/** | ||
* 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. | ||
*/ | ||
'use strict'; | ||
|
||
const runJest = require('../runJest'); | ||
const {extractSummary} = require('../utils'); | ||
const skipOnWindows = require('skipOnWindows'); | ||
|
||
// Works on windows, we just need to adjust snapshot test output | ||
skipOnWindows.suite(); | ||
|
||
test('moduleNameMapper wrong configuration', () => { | ||
const {stderr, status} = runJest('module_name_mapper_wrong_config'); | ||
const {rest} = extractSummary(stderr); | ||
|
||
expect(status).toBe(1); | ||
expect(rest).toMatchSnapshot(); | ||
}); | ||
|
||
test('moduleNameMapper correct configuration', () => { | ||
const {stderr, status} = runJest('module_name_mapper_correct_config'); | ||
const {rest} = extractSummary(stderr); | ||
|
||
expect(status).toBe(0); | ||
expect(rest).toMatchSnapshot(); | ||
}); |
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
11 changes: 11 additions & 0 deletions
11
integration_tests/module_name_mapper_correct_config/__mocks__/style_mock.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = {}; |
15 changes: 15 additions & 0 deletions
15
integration_tests/module_name_mapper_correct_config/__tests__/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const importedFn = require('../'); | ||
|
||
test('moduleNameMapping correct configuration', () => { | ||
expect(importedFn).toBeDefined(); | ||
}); |
13 changes: 13 additions & 0 deletions
13
integration_tests/module_name_mapper_correct_config/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
require('./style.css'); | ||
|
||
module.exports = () => 'test'; |
7 changes: 7 additions & 0 deletions
7
integration_tests/module_name_mapper_correct_config/package.json
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,7 @@ | ||
{ | ||
"jest": { | ||
"moduleNameMapper": { | ||
"\\.(css|less)$": "./__mocks__/style_mock.js" | ||
} | ||
} | ||
} |
Empty file.
15 changes: 15 additions & 0 deletions
15
integration_tests/module_name_mapper_wrong_config/__tests__/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const importedFn = require('../'); | ||
|
||
test('moduleNameMapping wrong configuration', () => { | ||
expect(importedFn).toBeDefined(); | ||
}); |
13 changes: 13 additions & 0 deletions
13
integration_tests/module_name_mapper_wrong_config/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
require('./style.css'); | ||
|
||
module.exports = () => 'test'; |
7 changes: 7 additions & 0 deletions
7
integration_tests/module_name_mapper_wrong_config/package.json
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,7 @@ | ||
{ | ||
"jest": { | ||
"moduleNameMapper": { | ||
"\\.(css|less)$": "no-such-module" | ||
} | ||
} | ||
} |
Empty file.
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