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

Use cross-spawn for running Yarn in integration tests #5550

Merged
merged 5 commits into from
Feb 13, 2018
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
11 changes: 3 additions & 8 deletions integration-tests/__tests__/babel_plugin_jest_hoist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@
'use strict';

const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {run} = require('../utils');
const runJest = require('../runJest');

const DIR = path.resolve(__dirname, '..', 'babel-plugin-jest-hoist');

SkipOnWindows.suite();

if (process.platform !== 'win32') {
beforeEach(() => {
run('yarn', DIR);
});
}
beforeEach(() => {
run('yarn', DIR);
});

it('sucessfully runs the tests inside `babel-plugin-jest-hoist/`', () => {
const {json} = runJest.json(DIR, ['--no-cache', '--coverage']);
Expand Down
8 changes: 3 additions & 5 deletions integration-tests/__tests__/native_async_mock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@
'use strict';

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

SkipOnWindows.suite();
const dir = path.resolve(__dirname, '..', 'native-async-mock');

test('mocks async functions', () => {
if (process.versions.node < '7.6.0') {
return;
}
if (process.platform !== 'win32') {
run('yarn', dir);
}

run('yarn', dir);

// --no-cache because babel can cache stuff and result in false green
const {stderr} = runJest(dir, ['--no-cache']);
expect(extractSummary(stderr).summary).toMatch(
Expand Down
12 changes: 3 additions & 9 deletions integration-tests/__tests__/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {
run,
cleanup,
Expand All @@ -20,13 +19,10 @@ const runJest = require('../runJest');
const os = require('os');

describe('babel-jest', () => {
SkipOnWindows.suite();
const dir = path.resolve(__dirname, '..', 'transform/babel-jest');

beforeEach(() => {
if (process.platform !== 'win32') {
run('yarn', dir);
}
run('yarn', dir);
});

it('runs transpiled code', () => {
Expand Down Expand Up @@ -60,7 +56,7 @@ describe('no babel-jest', () => {
linkJestPackage('babel-jest', tempDir);
});

it('fails with syntax error on flow types', () => {
test('fails with syntax error on flow types', () => {
const {stderr} = runJest(tempDir, ['--no-cache', '--no-watchman']);
expect(stderr).toMatch(/FAIL.*fails_with_syntax_error/);
expect(stderr).toMatch('Unexpected token');
Expand Down Expand Up @@ -107,9 +103,7 @@ describe('multiple-transformers', () => {
const dir = path.resolve(__dirname, '..', 'transform/multiple-transformers');

beforeEach(() => {
if (process.platform !== 'win32') {
run('yarn', dir);
}
run('yarn', dir);
});

it('transforms dependencies using specific transformers', () => {
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/typescript_coverage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
*/

const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {run} = require('../utils');
const runJest = require('../runJest');

SkipOnWindows.suite();

it('instruments and collects coverage for typescript files', () => {
const dir = path.resolve(__dirname, '../typescript-coverage');
run('yarn', dir);
Expand Down
7 changes: 4 additions & 3 deletions integration-tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import type {Path} from 'types/Config';

const {spawnSync} = require('child_process');
const {sync: spawnSync} = require('cross-spawn');
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
Expand Down Expand Up @@ -43,8 +43,9 @@ const linkJestPackage = (packageName: string, cwd: Path) => {
const packagesDir = path.resolve(__dirname, '../packages');
const packagePath = path.resolve(packagesDir, packageName);
const destination = path.resolve(cwd, 'node_modules/');
run(`mkdir -p ${destination}`);
return run(`ln -sf ${packagePath} ${destination}`);
mkdirp.sync(destination);
rimraf.sync(destination);
fs.symlinkSync(packagePath, destination, 'dir');
};

const fileExists = (filePath: Path) => {
Expand Down