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

Integrated with Yarn workspaces #3906

Merged
merged 6 commits into from
Jul 7, 2017
Merged
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
2 changes: 2 additions & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

workspaces-experimental true
8 changes: 5 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ environment:
install:
- ps: Install-Product node $env:nodejs_version x64
- node --version
- yarn --version
- yarn install
- curl -fsSL -o yarn.js https://github.com/yarnpkg/yarn/releases/download/v0.27.5/yarn-0.27.5.js
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't npm install --global yarn@0.27.5 be nicer here than node ./yarn.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then we would need to be sure that npm global dir precedes appveyor's global Yarn installation in PATH.
I don't have a strong opinion on this and happy to change to anything that maintainers think is best.

Copy link
Contributor

Choose a reason for hiding this comment

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

To me it is just more standard to rely on a global yarn installation. I hope appveyour global Yarn installation will be overridden by a npm install -g.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So what should I do here, npm install -g?

- node ./yarn.js --version
- node ./yarn.js install
- node ./yarn.js run build

cache:
- node_modules
- .eslintcache

test_script:
- yarn run jest -- --color
- node ./yarn.js run jest -- --color

# Don't actually build.
build: off
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
machine:
environment:
YARN_VERSION: 0.20.3
YARN_VERSION: 0.27.5
PATH: "${PATH}:${HOME}/.yarn/bin:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"
node:
version: 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports[`jest --showConfig outputs config info and exits 1`] = `
"/mocked/root/path/jest/node_modules/regenerator-runtime/runtime.js"
],
"snapshotSerializers": [],
"testEnvironment": "/mocked/root/path/jest/packages/jest-environment-node/build/index.js",
"testEnvironment": "/mocked/root/path/jest/node_modules/jest-environment-node/build/index.js",
"testMatch": [
"**/__tests__/**/*.js?(x)",
"**/?(*.)(spec|test).js?(x)"
Expand All @@ -52,7 +52,7 @@ exports[`jest --showConfig outputs config info and exits 1`] = `
"transform": [
[
"^.+\\\\.jsx?$",
"/mocked/root/path/jest/integration_tests/verbose_reporter/node_modules/babel-jest/build/index.js"
"/mocked/root/path/jest/node_modules/babel-jest/build/index.js"
]
],
"transformIgnorePatterns": [
Expand Down
4 changes: 1 addition & 3 deletions integration_tests/__tests__/babel_plugin_jest_hoist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

const path = require('path');
const skipOnWindows = require('skipOnWindows');
const {linkJestPackage, run} = require('../utils');
const {run} = require('../utils');
const runJest = require('../runJest');

const DIR = path.resolve(__dirname, '..', 'babel-plugin-jest-hoist');
Expand All @@ -21,8 +21,6 @@ skipOnWindows.suite();
if (process.platform !== 'win32') {
beforeEach(() => {
run('yarn', DIR);
linkJestPackage('babel-plugin-jest-hoist', DIR);
linkJestPackage('babel-jest', DIR);
});
}

Expand Down
6 changes: 1 addition & 5 deletions integration_tests/__tests__/coverage_report.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@
const fs = require('fs');
const path = require('path');
const skipOnWindows = require('skipOnWindows');
const {extractSummary, linkJestPackage} = require('../utils');
const {extractSummary} = require('../utils');
const runJest = require('../runJest');

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

if (process.platform !== 'win32') {
beforeEach(() => linkJestPackage('babel-jest', DIR));
}

skipOnWindows.suite();

test('outputs coverage report', () => {
Expand Down
7 changes: 0 additions & 7 deletions integration_tests/__tests__/debug.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@

const path = require('path');
const skipOnWindows = require('skipOnWindows');
const {linkJestPackage} = require('../utils');
const runJest = require('../runJest');

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

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

beforeEach(() => {
if (process.platform !== 'win32') {
linkJestPackage('babel-jest', dir);
}
});

it('outputs debugging info before running the test', () => {
const {stdout} = runJest(dir, ['--debug', '--no-cache']);
expect(stdout).toMatch('"version": "');
Expand Down
3 changes: 1 addition & 2 deletions integration_tests/__tests__/native_async_mock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

const path = require('path');
const skipOnWindows = require('skipOnWindows');
const {linkJestPackage, run, extractSummary} = require('../utils');
const {run, extractSummary} = require('../utils');
const runJest = require('../runJest');

skipOnWindows.suite();
Expand All @@ -22,7 +22,6 @@ test('mocks async functions', () => {
}
if (process.platform !== 'win32') {
run('yarn', dir);
linkJestPackage('babel-jest', dir);
}
// --no-cache because babel can cache stuff and result in false green
const {stderr} = runJest(dir, ['--no-cache']);
Expand Down
7 changes: 0 additions & 7 deletions integration_tests/__tests__/show_config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@

const path = require('path');
const skipOnWindows = require('skipOnWindows');
const {linkJestPackage} = require('../utils');
const runJest = require('../runJest');

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

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

beforeEach(() => {
if (process.platform !== 'win32') {
linkJestPackage('babel-jest', dir);
}
});

it('outputs config info and exits', () => {
const root = path.join(__dirname, '..', '..', '..');
expect.addSnapshotSerializer({
Expand Down
32 changes: 26 additions & 6 deletions integration_tests/__tests__/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@

const path = require('path');
const skipOnWindows = require('skipOnWindows');
const {linkJestPackage, run} = require('../utils');
const {
run,
cleanup,
createEmptyPackage,
linkJestPackage,
copyDir,
} = require('../utils');
const runJest = require('../runJest');
const os = require('os');

describe('babel-jest', () => {
skipOnWindows.suite();
Expand All @@ -18,7 +25,6 @@ describe('babel-jest', () => {
beforeEach(() => {
if (process.platform !== 'win32') {
run('yarn', dir);
linkJestPackage('babel-jest', dir);
}
});

Expand All @@ -39,17 +45,32 @@ describe('babel-jest', () => {
});
});

// babel-jest is automatically linked at the root because it is a workspace now
// a way to test this in isolation is to move the test suite into a temp folder
describe('no babel-jest', () => {
const dir = path.resolve(__dirname, '..', 'transform/no-babel-jest');
// doing test in a temp directory because we don't want jest node_modules affect it
const tempDir = path.resolve(os.tmpdir(), 'transform-no-babel-jest');

beforeEach(() => {
cleanup(tempDir);
createEmptyPackage(tempDir);
copyDir(dir, tempDir);
linkJestPackage('babel-jest', tempDir);
});

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

test('instrumentation with no babel-jest', () => {
const {stdout} = runJest(dir, ['--no-cache', '--coverage']);
const {stdout} = runJest(tempDir, [
'--no-cache',
'--coverage',
'--no-watchman',
]);
expect(stdout).toMatch('covered.js');
expect(stdout).not.toMatch('excluded_from_coverage.js');
// coverage result should not change
Expand Down Expand Up @@ -87,7 +108,6 @@ describe('multiple-transformers', () => {
beforeEach(() => {
if (process.platform !== 'win32') {
run('yarn', dir);
linkJestPackage('babel-jest', dir);
}
});

Expand Down
15 changes: 15 additions & 0 deletions integration_tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ const writeFiles = (directory: string, files: {[filename: string]: string}) => {
});
};

const copyDir = (src: string, dest: string) => {
const srcStat = fs.lstatSync(src);
if (srcStat.isDirectory()) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest);
}
fs.readdirSync(src).map(filePath => {
return copyDir(path.join(src, filePath), path.join(dest, filePath));
});
} else {
fs.writeFileSync(dest, fs.readFileSync(src));
}
};

const createEmptyPackage = (directory, packageJson) => {
const DEFAULT_PACKAGE_JSON = {
description: 'THIS IS AN AUTOGENERATED FILE AND SHOULD NOT BE ADDED TO GIT',
Expand Down Expand Up @@ -147,6 +161,7 @@ const cleanupStackTrace = (output: string) => {
module.exports = {
cleanup,
cleanupStackTrace,
copyDir,
createEmptyPackage,
extractSummary,
fileExists,
Expand Down
6 changes: 2 additions & 4 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"lerna": "2.0.0-rc.4",
"lerna": "2.0.0",
"version": "20.0.4",
"npmClient": "yarn",
"packages": [
"packages/*"
]
"useWorkspaces": true
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-flowtype": "^2.34.0",
"eslint-plugin-import": "^2.6.0",
"eslint-plugin-jest": "^20.0.3",
"eslint-plugin-markdown": "^1.0.0-beta.6",
"eslint-plugin-prettier": "^2.1.2",
"eslint-plugin-react": "^7.1.0",
Expand All @@ -45,7 +46,7 @@
"karma-chrome-launcher": "^2.1.1",
"karma-mocha": "^1.3.0",
"left-pad": "^1.1.1",
"lerna": "2.0.0-rc.4",
"lerna": "2.0.0",
"micromatch": "^2.3.11",
"mkdirp": "^0.5.1",
"mocha": "^3.4.2",
Expand Down Expand Up @@ -78,7 +79,7 @@
"jest-coverage": "yarn run jest --silent -- --coverage",
"lint": "eslint . --cache --ext js,md",
"lint-es5-build": "eslint --no-eslintrc --no-ignore --env=browser packages/*/build-es5",
"postinstall": "node ./scripts/postinstall.js && yarn run build --silent && (cd packages/eslint-plugin-jest && yarn link --silent) && yarn link eslint-plugin-jest --silent",
"postinstall": "yarn run build --silent",
"publish": "yarn run build-clean --silent && yarn run build --silent && lerna publish --silent",
"test-ci-es5-build-in-browser": "karma start --single-run",
"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",
Expand All @@ -89,6 +90,9 @@
"typecheck": "flow check",
"watch": "yarn run build --silent && node ./scripts/watch.js"
},
"workspaces": [
"packages/*"
],
"jest": {
"modulePathIgnorePatterns": [
"examples/.*",
Expand Down
Loading