Skip to content

Commit

Permalink
test: Fail early if the local yarn build is missing (#6351)
Browse files Browse the repository at this point in the history
Previously if the tests were run without first having run `yarn build`,
these three test suites would fail with over 1000 lines of unclear
console output.

Now, later tests are stopped from running to reduce verbosity, and a
more contributor-friendly error message displayed instead.

We unfortunately can't handle this case in `beforeAll()`, since even
if it throws, later tests in the same file are still run:
jestjs/jest#2713
  • Loading branch information
edmorley authored and arcanis committed Sep 3, 2018
1 parent 196fa94 commit 602c895
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions __tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* @flow */

import {existsSync} from 'fs';

import NoopReporter from '../src/reporters/base-reporter.js';
import makeTemp from './_temp';
import * as fs from '../src/util/fs.js';
Expand All @@ -16,6 +18,10 @@ ver = ver.split('-')[0];

jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;

if (!existsSync(path.resolve(__dirname, '../lib'))) {
throw new Error('These tests require `yarn build` to have been run first.');
}

async function execCommand(
cmd: string,
args: Array<string>,
Expand Down
5 changes: 5 additions & 0 deletions __tests__/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint max-len: 0 */

import http from 'http';
import {existsSync} from 'fs';

import invariant from 'invariant';
import execa from 'execa';
Expand All @@ -16,6 +17,10 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;

const path = require('path');

if (!existsSync(path.resolve(__dirname, '../lib'))) {
throw new Error('These tests require `yarn build` to have been run first.');
}

function addTest(pattern, {strictPeers} = {strictPeers: false}, yarnArgs: Array<string> = []) {
test.concurrent(`yarn add ${pattern}`, async () => {
const cwd = await makeTemp();
Expand Down
6 changes: 6 additions & 0 deletions __tests__/lifecycle-scripts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* @flow */

import {existsSync} from 'fs';

import NoopReporter from '../src/reporters/base-reporter.js';
import makeTemp from './_temp';
import * as fs from '../src/util/fs.js';
Expand All @@ -12,6 +14,10 @@ const yarnBin = path.join(__dirname, '../bin/yarn.js');

jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;

if (!existsSync(path.resolve(__dirname, '../lib'))) {
throw new Error('These tests require `yarn build` to have been run first.');
}

async function execCommand(cmd: string, packageName: string, env = process.env): Promise<string> {
const srcPackageDir = path.join(fixturesLoc, packageName);
const packageDir = await makeTemp(packageName);
Expand Down

0 comments on commit 602c895

Please sign in to comment.