From 602c895a29077988abdc3851ae14d78ca96098bd Mon Sep 17 00:00:00 2001 From: Ed Morley <501702+edmorley@users.noreply.github.com> Date: Mon, 3 Sep 2018 23:33:13 +0100 Subject: [PATCH] test: Fail early if the local yarn build is missing (#6351) 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: https://github.com/facebook/jest/issues/2713 --- __tests__/index.js | 6 ++++++ __tests__/integration.js | 5 +++++ __tests__/lifecycle-scripts.js | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/__tests__/index.js b/__tests__/index.js index 7825d38cbd..6c1c73961f 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -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'; @@ -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, diff --git a/__tests__/integration.js b/__tests__/integration.js index e01a4aec26..c1b753e6ed 100644 --- a/__tests__/integration.js +++ b/__tests__/integration.js @@ -2,6 +2,7 @@ /* eslint max-len: 0 */ import http from 'http'; +import {existsSync} from 'fs'; import invariant from 'invariant'; import execa from 'execa'; @@ -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 = []) { test.concurrent(`yarn add ${pattern}`, async () => { const cwd = await makeTemp(); diff --git a/__tests__/lifecycle-scripts.js b/__tests__/lifecycle-scripts.js index 8f6660ef57..c9a8c22982 100644 --- a/__tests__/lifecycle-scripts.js +++ b/__tests__/lifecycle-scripts.js @@ -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'; @@ -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 { const srcPackageDir = path.join(fixturesLoc, packageName); const packageDir = await makeTemp(packageName);