Skip to content

Commit da9aabb

Browse files
cpojerFacebook Github Bot 5
authored andcommitted
Add developer environment setup script and fix symlink issues.
Summary:This diff adds a script after `postinstall` that sets up the dev environment using `lerna`. Once we move jest's source itself into a package, we can drop the custom calls to `npm link`. Linking `jest-util` pointed out a symlink unmocking bug in Jest I've been meaning to fix for a long time. After running the setup script, Jest would not be able to mock `chalk` properly if `jest-util` was linked into Jest. It turns out we are calling `fs.realpathSync`. I think this was necessary with for `node-haste1` support and is a leftover, however symlink unmocking was never properly supported then so I'm questioning why it was there in the first place. Closes jestjs#821 Reviewed By: vjeux Differential Revision: D3080727 fb-gh-sync-id: fd3780f9c30031eb2505c26fb5c944de3f7c948f shipit-source-id: fd3780f9c30031eb2505c26fb5c944de3f7c948f
1 parent 3affc4e commit da9aabb

File tree

12 files changed

+37
-17
lines changed

12 files changed

+37
-17
lines changed

.npmignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
.haste_cache
2+
__tests__
13
docs
24
examples
35
packages
6+
setup.sh
47
website
5-
__tests__
6-
.haste_cache

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Fixed `moduleNameMapper` config option when used with paths.
99
* Added `jest-util`, general code cleanup.
1010
* Fixed an error with Jasmine 2 and tests that `throw 'string errors'`.
11+
* Fixed issues with unmocking symlinked module names.
1112

1213
## jest-cli 0.9.2, babel-jest 9.0.3
1314

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,3 +735,10 @@ Indicates whether each individual test should be reported during the run. All er
735735
changes and is used by Jest for crawling for files. Disable this if you cannot
736736
use watchman or use the `--no-watchman` flag.
737737
<generated_api_end />
738+
739+
## Local Development
740+
741+
For local development the `setup.sh` file is run to link all packages together.
742+
On most platforms this will be run automatically after `npm install`, however if
743+
you find that Jest does not set up the development environment correctly, this
744+
script can also be run manually.

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9.0.3

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"diff": "^2.1.1",
1010
"graceful-fs": "^4.1.3",
1111
"istanbul": "^0.4.2",
12-
"jest-mock": "^1.0.0",
13-
"jest-util": "^1.0.0",
12+
"jest-mock": "^9.0.3",
13+
"jest-util": "^9.0.3",
1414
"jsdom": "^7.2.0",
1515
"json-stable-stringify": "^1.0.0",
1616
"lodash.template": "^3.6.2",
@@ -25,7 +25,8 @@
2525
"devDependencies": {
2626
"babel-eslint": "^4.1.3",
2727
"eslint": "^1.7.3",
28-
"fbjs-scripts": "^0.5.0"
28+
"fbjs-scripts": "^0.5.0",
29+
"lerna": "^1.1.2"
2930
},
3031
"bin": {
3132
"jest": "./bin/jest.js"
@@ -38,10 +39,11 @@
3839
"url": "https://github.com/facebook/jest"
3940
},
4041
"scripts": {
42+
"jasmine1": "node bin/jest.js --testRunner=jasmine1",
4143
"lint": "eslint .",
44+
"postinstall": "[ \"$NODE_ENV\" != production ] && ./setup.sh",
4245
"prepublish": "npm test",
43-
"test": "npm run lint && node bin/jest.js && npm run jasmine1",
44-
"jasmine1": "node bin/jest.js --testRunner=jasmine1"
46+
"test": "npm run lint && node bin/jest.js && npm run jasmine1"
4547
},
4648
"jest": {
4749
"rootDir": "src",

packages/babel-jest/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "babel-jest",
3-
"version": "9.0.4",
3+
"version": "9.0.3",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/facebook/jest.git"
@@ -9,6 +9,6 @@
99
"main": "src/index.js",
1010
"dependencies": {
1111
"babel-core": "^6.0.0",
12-
"babel-preset-jest": "^1.0.1"
12+
"babel-preset-jest": "^9.0.3"
1313
}
1414
}

packages/babel-plugin-jest-hoist/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "babel-plugin-jest-hoist",
3-
"version": "1.0.0",
3+
"version": "9.0.3",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/facebook/jest.git"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "babel-preset-jest",
3-
"version": "1.0.1",
3+
"version": "9.0.3",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/facebook/jest.git"
77
},
88
"license": "BSD-3-Clause",
99
"main": "index.js",
1010
"dependencies": {
11-
"babel-plugin-jest-hoist": "^1.0.0"
11+
"babel-plugin-jest-hoist": "^9.0.3"
1212
}
1313
}

packages/jest-mock/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jest-mock",
3-
"version": "0.0.2",
3+
"version": "9.0.3",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/facebook/jest.git"

packages/jest-util/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jest-util",
3-
"version": "1.0.0",
3+
"version": "9.0.3",
44
"main": "index.js",
55
"dependencies": {
66
"chalk": "^1.1.1",

setup.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
echo "Setting up Jest's development environment..."
4+
node_modules/.bin/lerna bootstrap
5+
6+
(cd packages/jest-mock && npm link)
7+
npm link jest-mock
8+
(cd packages/jest-util && npm link)
9+
npm link jest-util

src/HasteModuleLoader/HasteModuleLoader.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,7 @@ class Loader {
534534
throw e;
535535
}
536536

537-
const realPath = fs.realpathSync(modulePath);
538-
if (this._unmockList && this._unmockList.test(realPath)) {
537+
if (this._unmockList && this._unmockList.test(modulePath)) {
539538
shouldMockModuleCache[moduleName] = false;
540539
return false;
541540
}
@@ -544,7 +543,7 @@ class Loader {
544543
const currentModuleID = this._getNormalizedModuleID(currPath);
545544
if (
546545
currPath.includes(constants.NODE_MODULES) &&
547-
realPath.includes(constants.NODE_MODULES) &&
546+
modulePath.includes(constants.NODE_MODULES) &&
548547
(
549548
(this._unmockList && this._unmockList.test(currPath)) ||
550549
explicitShouldMock[currentModuleID] === false ||

0 commit comments

Comments
 (0)