Skip to content

Commit

Permalink
Use cross-spawn for running Yarn in integration tests (#5550)
Browse files Browse the repository at this point in the history
* Use cross-spawn for running Yarn in integration tests

* Unlock more windows tests

* Moar windows

* Use node api instead of spawning commands to link babel-jest

* Skip windows for coverage_remapping.test.js
  • Loading branch information
thymikee authored and cpojer committed Feb 13, 2018
1 parent 2df9e4c commit b69ac08
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 28 deletions.
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

0 comments on commit b69ac08

Please sign in to comment.