-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw when moduleNameMapper points to inexistent module #3567
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Can you also add a test to verify throwing error works?
packages/jest-resolve/src/index.js
Outdated
@@ -16,6 +16,8 @@ import type {ModuleMap} from 'types/HasteMap'; | |||
const path = require('path'); | |||
const nodeModulesPaths = require('resolve/lib/node-modules-paths'); | |||
const isBuiltinModule = require('is-builtin-module'); | |||
const chalk = require('chalk'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to add chalk
to jest-resolve
's dependencies.
packages/jest-resolve/src/index.js
Outdated
}) | ||
); | ||
}); | ||
if(!module) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to run npm run prettier
to fix some styling issues.
Commited prettier and chalk dependencies change. |
@thymikee Working on the test but not sure on how to implement the test. it('Should throw error when provided module that dont exist', () => { But this get undefined error in ModuleMap. Not sure on what i should pass down to getMockModule so it reaches this._resolveStubModuleName(from, name); Any hint on where i could look? |
You need to feed Resolver with some data in constructor (e.g. |
@thymikee Not sure if the integration test is in the correct place or correct written, but its a start. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I've left some inline comments but it's heading in the right direction. Make sure to remove 'use strict' and @flow calls from test files.
* 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. | ||
* | ||
* @emails oncall+jsinfra |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this
* | ||
* @emails oncall+jsinfra | ||
*/ | ||
'use strict'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use strict is no longer necessary, babel transform adds this for us
test('moduleNameMapper wrong configuration', () => { | ||
const result = runJest('moduleNameMapper-wrong-config'); | ||
// Should fail because that wrong configuration will throw | ||
expect(result.status).toBe(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also catch a snapshot if this error? It's great that we know it fails, but even better if we see what's thrown
|
||
test('moduleNameMapping correct configuration', () => { | ||
importedFn(); | ||
expect(importedFn.mock.calls.length).toBe(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather like not to mock here, but meh, I guess it's fine
"\\.(css|less)$": "./__mocks__/styleMock.js" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline
@@ -0,0 +1,23 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use camelCase name for this file?
* 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flow is not necessary here
@thymikee Thx for the feedback! Think i managed to fix the things you pointed out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more round and after merging #3587 and we're good to go. Please rebase your branch to master.
Configuration error: | ||
|
||
Unknown module in configuration option moduleNameMapper | ||
Please check: /\\\\.(css|less)$/: module-that-dont-exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This double error is fixed here: #3587
@@ -0,0 +1,18 @@ | |||
const runJest = require('../runJest'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add copyright headers to every JS file. I mean just like this:
/**
* 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.
*/
Without 'use strict';
(rebase to master to see why) without @flow
(we're currently not type-checking our tests) and without @emails...
*/ | ||
|
||
'use strict'; | ||
// Inlcude style so moduleNameMapping triggers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is unnecessary
@@ -0,0 +1,7 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indentation, change to 2 per tab instead of 4.
*/ | ||
|
||
'use strict'; | ||
// Inlcude style so moduleNameMapping triggers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment
@@ -0,0 +1,7 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indentation
{ | ||
"jest": { | ||
"moduleNameMapper": { | ||
"\\.(css|less)$": "module-that-dont-exist" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"module-that-dont-exist"
-> "no-such-module"
maybe? Your name has grammar issues.
@thymikee First time doing a rebase. |
When on your branch you should be good with: git pull -r upstream master Assuming |
Looks like i messed that up somehow. |
Exactly |
Just checking so im not heading in the wrong direction.
Just do a git push? |
Meh, just push it then. |
Ty, back on track! |
Looks like #3587 didn't merge. Still got double Configuration in the snapshot. |
Ahh it haven't been merged yet :) |
Hey @lindgr3n, I've fixed some little nits and rebased your work on top of master properly, hope you don't mind. We still need to figure out why some errors are having duplicated messages, but it's definitely not in scope of this PR. You'll be better off to hard reset to this branch to avoid local conflicts:
|
Nice, no problem. Good work! |
|
|
Ahh ty! Should have guessed that it should have been a / in the command. |
@thymikee Did i fix the changes you wanted or should i fix something more? |
Could someone from JEST please look at this? A silently failing jest config is still something many newcomers to JEST are running into (many |
There's an issue with this message being added twice, which we yet have to figure out: https://github.com/facebook/jest/pull/3567/files#diff-0454b3bf8e9e55c3655f3be2ff46cf28R19 |
@lindgr3n sorry about that, but I've fixed the branch for you. However, you could definitely use some training in git rebasing. I also fixed the message, it looks like this now: Thanks for your work on that! Appreciated 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's wait for CI to pass.
CI is unhappy, needs prettier. |
Failing on windows. |
Thanks again @thymikee . Appreciate the help! Checked the commits and i'm unsure why "integration_tests/tests/auto_clear_mocks.test.js" is changed. Feels like it should not have been changed? Also the snapshots for "module_name_mapper.test.js" need to be updated. |
Skipping the test on Windows. Feature works, it's just the test output differs between UNIX and Windows. I'm not going to fix this now, as other tests may be skipped for the same reason. |
Big thanks @thymikee for helping me with my first contribution to OSS! :) Keep up the good work! |
* 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
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Fixes #1888
Should get error and test fail if the module configured in moduleNameMapper is not found.
Right now if the module is not found the test still passes. Test should fail so user is aware that the configuration is wrong.
Test plan
Need to add two test.
Tried to get something to work but could need some pointers on how to mock out some parts. So left it out for now.