Skip to content
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

Run all config filename patterns against rel paths #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/TutorialReact.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ Since we are writing code using JSX, a bit of one-time setup is required to make
"react-tools": "*"
},
"jest": {
"scriptPreprocessor": "<rootDir>/preprocessor.js",
"unmockedModulePathPatterns": ["<rootDir>/node_modules/react"],
"testPathIgnorePatterns": ["<rootDir>/node_modules"]
"scriptPreprocessor": "preprocessor.js",
"unmockedModulePathPatterns": ["^node_modules/react/"],
"testPathIgnorePatterns": ["^node_modules/"]
}
```

Expand Down
6 changes: 3 additions & 3 deletions examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"test": "node ../../bin/jest.js"
},
"jest": {
"scriptPreprocessor": "<rootDir>/preprocessor.js",
"unmockedModulePathPatterns": ["<rootDir>/node_modules/react"],
"testPathIgnorePatterns": ["<rootDir>/node_modules"]
"scriptPreprocessor": "preprocessor.js",
"unmockedModulePathPatterns": ["^node_modules/react/"],
"testPathIgnorePatterns": ["^node_modules/"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

}
}
12 changes: 8 additions & 4 deletions src/HasteModuleLoader/HasteModuleLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function _constructHasteInst(config, options) {
var HASTE_IGNORE_REGEX = new RegExp(
config.modulePathIgnorePatterns
? config.modulePathIgnorePatterns.join('|')
: '__NOT_EXIST__'
: '$.' // never matches
);

if (!fs.existsSync(CACHE_DIR_PATH)) {
Expand All @@ -100,8 +100,9 @@ function _constructHasteInst(config, options) {
_buildLoadersList(config),
(config.testPathDirs || []),
{
ignorePaths: function(path) {
return path.match(HASTE_IGNORE_REGEX);
ignorePaths: function(modulePath) {
var relPath = path.relative(config.rootDir, modulePath);
return HASTE_IGNORE_REGEX.test(relPath);
},
version: JSON.stringify(config),
useNativeFind: true,
Expand Down Expand Up @@ -529,7 +530,10 @@ Loader.prototype._shouldMock = function(currPath, moduleName) {
var manualMockResource =
this._getResource('JSMock', moduleName);
try {
var modulePath = this._moduleNameToPath(currPath, moduleName);
var modulePath = path.relative(
this._config.rootDir,
this._moduleNameToPath(currPath, moduleName)
);
} catch(e) {
// If there isn't a real module, we don't have a path to match
// against the unmockList regexps. If there is also not a manual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('nodeHasteModuleLoader', function() {

var CONFIG = {
name: 'nodeHasteModuleLoader-tests',
rootDir: __dirname,
testPathDirs: [path.resolve(__dirname, 'test_root')]
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('nodeHasteModuleLoader', function() {

var CONFIG = {
name: 'nodeHasteModuleLoader-tests',
rootDir: __dirname,
testPathDirs: [path.resolve(__dirname, 'test_root')]
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('nodeHasteModuleLoader', function() {

var CONFIG = {
name: 'nodeHasteModuleLoader-tests',
rootDir: __dirname,
testPathDirs: [path.resolve(__dirname, 'test_root')]
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('nodeHasteModuleLoader', function() {

var CONFIG = {
name: 'nodeHasteModuleLoader-tests',
rootDir: __dirname,
testPathDirs: [path.resolve(__dirname, 'test_root')]
};

Expand Down
13 changes: 7 additions & 6 deletions src/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function TestRunner(config, options) {
.join('|')
);
this._nodeHasteTestRegExp = new RegExp(
'/' + utils.escapeStrForRegex(config.testDirectoryName) + '/' +
'(?:^|/)' + utils.escapeStrForRegex(config.testDirectoryName) + '/' +
'.*\\.(' +
utils.escapeStrForRegex(config.testFileExtensions.join('|')) +
')$'
Expand Down Expand Up @@ -112,17 +112,18 @@ TestRunner.prototype._getModuleLoaderResourceMap = function() {
return this._moduleLoaderResourceMap;
};

TestRunner.prototype._isTestFilePath = function(filePath) {
TestRunner.prototype._isTestFilePath = function(absPath) {
var testPathIgnorePattern =
this._config.testPathIgnorePatterns
? new RegExp(this._config.testPathIgnorePatterns.join('|'))
: null;

var relPath = path.relative(this._config.rootDir, absPath);
return (
this._nodeHasteTestRegExp.test(filePath)
&& !HIDDEN_FILE_RE.test(filePath)
&& (!testPathIgnorePattern || !testPathIgnorePattern.test(filePath))
&& this._testPathDirsRegExp.test(filePath)
this._nodeHasteTestRegExp.test(relPath)
&& !HIDDEN_FILE_RE.test(relPath)
&& (!testPathIgnorePattern || !testPathIgnorePattern.test(relPath))
&& this._testPathDirsRegExp.test(absPath)
);
};

Expand Down