Skip to content

Commit e6704bf

Browse files
authored
Integrated with Yarn workspaces (jestjs#3906)
* enabled workspaces * updated lerna to 2.0.0 with workspaces support
1 parent a49c09a commit e6704bf

File tree

37 files changed

+388
-5449
lines changed

37 files changed

+388
-5449
lines changed

.yarnrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
workspaces-experimental true

appveyor.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ environment:
55
install:
66
- ps: Install-Product node $env:nodejs_version x64
77
- node --version
8-
- yarn --version
9-
- yarn install
8+
- curl -fsSL -o yarn.js https://github.com/yarnpkg/yarn/releases/download/v0.27.5/yarn-0.27.5.js
9+
- node ./yarn.js --version
10+
- node ./yarn.js install
11+
- node ./yarn.js run build
1012

1113
cache:
1214
- node_modules
1315
- .eslintcache
1416

1517
test_script:
16-
- yarn run jest -- --color
18+
- node ./yarn.js run jest -- --color
1719

1820
# Don't actually build.
1921
build: off

circle.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
machine:
22
environment:
3-
YARN_VERSION: 0.20.3
3+
YARN_VERSION: 0.27.5
44
PATH: "${PATH}:${HOME}/.yarn/bin:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"
55
node:
66
version: 8

integration_tests/__tests__/__snapshots__/show_config.test.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ exports[`jest --showConfig outputs config info and exits 1`] = `
3737
"/mocked/root/path/jest/node_modules/regenerator-runtime/runtime.js"
3838
],
3939
"snapshotSerializers": [],
40-
"testEnvironment": "/mocked/root/path/jest/packages/jest-environment-node/build/index.js",
40+
"testEnvironment": "/mocked/root/path/jest/node_modules/jest-environment-node/build/index.js",
4141
"testMatch": [
4242
"**/__tests__/**/*.js?(x)",
4343
"**/?(*.)(spec|test).js?(x)"
@@ -52,7 +52,7 @@ exports[`jest --showConfig outputs config info and exits 1`] = `
5252
"transform": [
5353
[
5454
"^.+\\\\.jsx?$",
55-
"/mocked/root/path/jest/integration_tests/verbose_reporter/node_modules/babel-jest/build/index.js"
55+
"/mocked/root/path/jest/node_modules/babel-jest/build/index.js"
5656
]
5757
],
5858
"transformIgnorePatterns": [

integration_tests/__tests__/babel_plugin_jest_hoist.test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
const path = require('path');
1313
const skipOnWindows = require('skipOnWindows');
14-
const {linkJestPackage, run} = require('../utils');
14+
const {run} = require('../utils');
1515
const runJest = require('../runJest');
1616

1717
const DIR = path.resolve(__dirname, '..', 'babel-plugin-jest-hoist');
@@ -21,8 +21,6 @@ skipOnWindows.suite();
2121
if (process.platform !== 'win32') {
2222
beforeEach(() => {
2323
run('yarn', DIR);
24-
linkJestPackage('babel-plugin-jest-hoist', DIR);
25-
linkJestPackage('babel-jest', DIR);
2624
});
2725
}
2826

integration_tests/__tests__/coverage_report.test.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@
1212
const fs = require('fs');
1313
const path = require('path');
1414
const skipOnWindows = require('skipOnWindows');
15-
const {extractSummary, linkJestPackage} = require('../utils');
15+
const {extractSummary} = require('../utils');
1616
const runJest = require('../runJest');
1717

1818
const DIR = path.resolve(__dirname, '../coverage_report');
1919

20-
if (process.platform !== 'win32') {
21-
beforeEach(() => linkJestPackage('babel-jest', DIR));
22-
}
23-
2420
skipOnWindows.suite();
2521

2622
test('outputs coverage report', () => {

integration_tests/__tests__/debug.test.js

-7
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,13 @@
88

99
const path = require('path');
1010
const skipOnWindows = require('skipOnWindows');
11-
const {linkJestPackage} = require('../utils');
1211
const runJest = require('../runJest');
1312

1413
describe('jest --debug', () => {
1514
skipOnWindows.suite();
1615

1716
const dir = path.resolve(__dirname, '..', 'verbose_reporter');
1817

19-
beforeEach(() => {
20-
if (process.platform !== 'win32') {
21-
linkJestPackage('babel-jest', dir);
22-
}
23-
});
24-
2518
it('outputs debugging info before running the test', () => {
2619
const {stdout} = runJest(dir, ['--debug', '--no-cache']);
2720
expect(stdout).toMatch('"version": "');

integration_tests/__tests__/native_async_mock.test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
const path = require('path');
1212
const skipOnWindows = require('skipOnWindows');
13-
const {linkJestPackage, run, extractSummary} = require('../utils');
13+
const {run, extractSummary} = require('../utils');
1414
const runJest = require('../runJest');
1515

1616
skipOnWindows.suite();
@@ -22,7 +22,6 @@ test('mocks async functions', () => {
2222
}
2323
if (process.platform !== 'win32') {
2424
run('yarn', dir);
25-
linkJestPackage('babel-jest', dir);
2625
}
2726
// --no-cache because babel can cache stuff and result in false green
2827
const {stderr} = runJest(dir, ['--no-cache']);

integration_tests/__tests__/show_config.test.js

-7
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,13 @@
1010

1111
const path = require('path');
1212
const skipOnWindows = require('skipOnWindows');
13-
const {linkJestPackage} = require('../utils');
1413
const runJest = require('../runJest');
1514

1615
describe('jest --showConfig', () => {
1716
skipOnWindows.suite();
1817

1918
const dir = path.resolve(__dirname, '..', 'verbose_reporter');
2019

21-
beforeEach(() => {
22-
if (process.platform !== 'win32') {
23-
linkJestPackage('babel-jest', dir);
24-
}
25-
});
26-
2720
it('outputs config info and exits', () => {
2821
const root = path.join(__dirname, '..', '..', '..');
2922
expect.addSnapshotSerializer({

integration_tests/__tests__/transform.test.js

+26-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@
88

99
const path = require('path');
1010
const skipOnWindows = require('skipOnWindows');
11-
const {linkJestPackage, run} = require('../utils');
11+
const {
12+
run,
13+
cleanup,
14+
createEmptyPackage,
15+
linkJestPackage,
16+
copyDir,
17+
} = require('../utils');
1218
const runJest = require('../runJest');
19+
const os = require('os');
1320

1421
describe('babel-jest', () => {
1522
skipOnWindows.suite();
@@ -18,7 +25,6 @@ describe('babel-jest', () => {
1825
beforeEach(() => {
1926
if (process.platform !== 'win32') {
2027
run('yarn', dir);
21-
linkJestPackage('babel-jest', dir);
2228
}
2329
});
2430

@@ -39,17 +45,32 @@ describe('babel-jest', () => {
3945
});
4046
});
4147

48+
// babel-jest is automatically linked at the root because it is a workspace now
49+
// a way to test this in isolation is to move the test suite into a temp folder
4250
describe('no babel-jest', () => {
4351
const dir = path.resolve(__dirname, '..', 'transform/no-babel-jest');
52+
// doing test in a temp directory because we don't want jest node_modules affect it
53+
const tempDir = path.resolve(os.tmpdir(), 'transform-no-babel-jest');
54+
55+
beforeEach(() => {
56+
cleanup(tempDir);
57+
createEmptyPackage(tempDir);
58+
copyDir(dir, tempDir);
59+
linkJestPackage('babel-jest', tempDir);
60+
});
4461

4562
it('fails with syntax error on flow types', () => {
46-
const {stderr} = runJest(dir, ['--no-cache']);
63+
const {stderr} = runJest(tempDir, ['--no-cache', '--no-watchman']);
4764
expect(stderr).toMatch(/FAIL.*fails_with_syntax_error/);
48-
expect(stderr).toMatch('SyntaxError: Unexpected token :');
65+
expect(stderr).toMatch('Unexpected token');
4966
});
5067

5168
test('instrumentation with no babel-jest', () => {
52-
const {stdout} = runJest(dir, ['--no-cache', '--coverage']);
69+
const {stdout} = runJest(tempDir, [
70+
'--no-cache',
71+
'--coverage',
72+
'--no-watchman',
73+
]);
5374
expect(stdout).toMatch('covered.js');
5475
expect(stdout).not.toMatch('excluded_from_coverage.js');
5576
// coverage result should not change
@@ -87,7 +108,6 @@ describe('multiple-transformers', () => {
87108
beforeEach(() => {
88109
if (process.platform !== 'win32') {
89110
run('yarn', dir);
90-
linkJestPackage('babel-jest', dir);
91111
}
92112
});
93113

integration_tests/utils.js

+15
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ const writeFiles = (directory: string, files: {[filename: string]: string}) => {
8888
});
8989
};
9090

91+
const copyDir = (src: string, dest: string) => {
92+
const srcStat = fs.lstatSync(src);
93+
if (srcStat.isDirectory()) {
94+
if (!fs.existsSync(dest)) {
95+
fs.mkdirSync(dest);
96+
}
97+
fs.readdirSync(src).map(filePath => {
98+
return copyDir(path.join(src, filePath), path.join(dest, filePath));
99+
});
100+
} else {
101+
fs.writeFileSync(dest, fs.readFileSync(src));
102+
}
103+
};
104+
91105
const createEmptyPackage = (directory, packageJson) => {
92106
const DEFAULT_PACKAGE_JSON = {
93107
description: 'THIS IS AN AUTOGENERATED FILE AND SHOULD NOT BE ADDED TO GIT',
@@ -147,6 +161,7 @@ const cleanupStackTrace = (output: string) => {
147161
module.exports = {
148162
cleanup,
149163
cleanupStackTrace,
164+
copyDir,
150165
createEmptyPackage,
151166
extractSummary,
152167
fileExists,

lerna.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
2-
"lerna": "2.0.0-rc.4",
2+
"lerna": "2.0.0",
33
"version": "20.0.4",
44
"npmClient": "yarn",
5-
"packages": [
6-
"packages/*"
7-
]
5+
"useWorkspaces": true
86
}

package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"eslint-plugin-babel": "^4.1.1",
2828
"eslint-plugin-flowtype": "^2.34.0",
2929
"eslint-plugin-import": "^2.6.0",
30+
"eslint-plugin-jest": "^20.0.3",
3031
"eslint-plugin-markdown": "^1.0.0-beta.6",
3132
"eslint-plugin-prettier": "^2.1.2",
3233
"eslint-plugin-react": "^7.1.0",
@@ -45,7 +46,7 @@
4546
"karma-chrome-launcher": "^2.1.1",
4647
"karma-mocha": "^1.3.0",
4748
"left-pad": "^1.1.1",
48-
"lerna": "2.0.0-rc.4",
49+
"lerna": "2.0.0",
4950
"micromatch": "^2.3.11",
5051
"mkdirp": "^0.5.1",
5152
"mocha": "^3.4.2",
@@ -78,7 +79,7 @@
7879
"jest-coverage": "yarn run jest --silent -- --coverage",
7980
"lint": "eslint . --cache --ext js,md",
8081
"lint-es5-build": "eslint --no-eslintrc --no-ignore --env=browser packages/*/build-es5",
81-
"postinstall": "node ./scripts/postinstall.js && yarn run build --silent && (cd packages/eslint-plugin-jest && yarn link --silent) && yarn link eslint-plugin-jest --silent",
82+
"postinstall": "yarn run build --silent",
8283
"publish": "yarn run build-clean --silent && yarn run build --silent && lerna publish --silent",
8384
"test-ci-es5-build-in-browser": "karma start --single-run",
8485
"test-ci": "yarn run typecheck --silent && yarn run lint --silent && yarn run lint-es5-build && yarn run jest-coverage --silent -- -i && yarn run test-examples --silent && node scripts/mapCoverage.js && codecov",
@@ -89,6 +90,9 @@
8990
"typecheck": "flow check",
9091
"watch": "yarn run build --silent && node ./scripts/watch.js"
9192
},
93+
"workspaces": [
94+
"packages/*"
95+
],
9296
"jest": {
9397
"modulePathIgnorePatterns": [
9498
"examples/.*",

0 commit comments

Comments
 (0)