Skip to content

Commit 9c6f584

Browse files
kentaromiuraFacebook Github Bot 8
authored andcommitted
Fixes for windows
Summary:- postinstall breaks npm install on windows, moving the logic inside a javascript file and run it through node - utils-normalizeConfig-test.js was failing on windows because of difference in path separator and root Closes jestjs#828 Differential Revision: D3088644 fb-gh-sync-id: 91cc19fd3c173069097c070f71bd1cc802c7a63c shipit-source-id: 91cc19fd3c173069097c070f71bd1cc802c7a63c
1 parent da9aabb commit 9c6f584

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"scripts": {
4242
"jasmine1": "node bin/jest.js --testRunner=jasmine1",
4343
"lint": "eslint .",
44-
"postinstall": "[ \"$NODE_ENV\" != production ] && ./setup.sh",
44+
"postinstall": "node postinstall.js",
4545
"prepublish": "npm test",
4646
"test": "npm run lint && node bin/jest.js && npm run jasmine1"
4747
},

postinstall.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
3+
*
4+
* This source code is licensed under the BSD-style license found in the
5+
* LICENSE file in the root directory of this source tree. An additional grant
6+
* of patent rights can be found in the PATENTS file in the same directory.
7+
*/
8+
'use strict';
9+
10+
if (
11+
process.platform !== 'win32' &&
12+
process.env.NODE_ENV !== 'production'
13+
) {
14+
const exec = require('child_process').exec;
15+
exec('./setup.sh', (err, stdout, stderr) => {
16+
if (err) {
17+
console.error(err);
18+
return;
19+
}
20+
console.log(stdout);
21+
});
22+
}

src/lib/__tests__/utils-normalizeConfig-test.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ describe('utils-normalizeConfig', () => {
3434
);
3535
}
3636

37+
// this helper takes a path starting from root and normalize it to unix style
38+
function uniformPath(pathToUniform) {
39+
const resolved = path.resolve(pathToUniform);
40+
return '/' + resolved.replace(root, '').split(path.sep).join('/');
41+
}
42+
3743
beforeEach(() => {
3844
path = require('path');
3945
root = path.resolve('/');
@@ -399,14 +405,15 @@ describe('utils-normalizeConfig', () => {
399405
});
400406

401407
it('correctly identifies and uses babel-jest', () => {
408+
402409
const config = normalizeConfig({
403410
rootDir: '/root',
404411
});
405412

406413
expect(config.usesBabelJest).toBe(true);
407-
expect(config.scriptPreprocessor)
408-
.toEqual('/root/node_modules/babel-jest');
409-
expect(config.setupFiles).toEqual(['/root/node_modules/babel-polyfill']);
414+
const preprocessorPath = uniformPath(config.scriptPreprocessor);
415+
expect(preprocessorPath).toEqual('/root/node_modules/babel-jest');
416+
expect(config.setupFiles.map(uniformPath)).toEqual(['/root/node_modules/babel-polyfill']);
410417
});
411418

412419
it(`doesn't use babel-jest if its not available`, () => {
@@ -428,7 +435,8 @@ describe('utils-normalizeConfig', () => {
428435
});
429436

430437
expect(config.usesBabelJest).toBe(true);
431-
expect(config.setupFiles).toEqual(['/root/node_modules/babel-polyfill']);
438+
expect(config.setupFiles.map(uniformPath))
439+
.toEqual(['/root/node_modules/babel-polyfill']);
432440
});
433441

434442
it('correctly identifies react-native', () => {
@@ -445,8 +453,8 @@ describe('utils-normalizeConfig', () => {
445453
rootDir: '/root',
446454
});
447455

448-
expect(config.preprocessorIgnorePatterns)
449-
.toEqual([path.sep + 'node_modules' + path.sep]);
456+
expect(config.preprocessorIgnorePatterns.map(uniformPath))
457+
.toEqual(['/node_modules']);
450458
});
451459
});
452460
});

0 commit comments

Comments
 (0)