From 0d0f3ed79bc7bdb9ecc1b43e48bafb93b99b22e7 Mon Sep 17 00:00:00 2001 From: Simon Vocella Date: Sun, 23 Apr 2017 18:34:00 +0200 Subject: [PATCH] move tests with side-effects under isCI branch; the other tests now are side-effects free --- __tests__/commands/_helpers.js | 1 + __tests__/commands/global.js | 63 ++++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/__tests__/commands/_helpers.js b/__tests__/commands/_helpers.js index d14de81f62..04d6ef8ca4 100644 --- a/__tests__/commands/_helpers.js +++ b/__tests__/commands/_helpers.js @@ -125,6 +125,7 @@ export async function run( globalFolder: flags.globalFolder || path.join(cwd, '.yarn-global'), cacheFolder: flags.cacheFolder || path.join(cwd, '.yarn-cache'), linkFolder: path.join(cwd, '.yarn-link'), + prefix: flags.prefix, production: flags.production, }, reporter); diff --git a/__tests__/commands/global.js b/__tests__/commands/global.js index 7f54c00fd1..5e22d1cb59 100644 --- a/__tests__/commands/global.js +++ b/__tests__/commands/global.js @@ -39,7 +39,12 @@ async function createTempGlobalFolder(): Promise { return await mkdir('yarn-global'); } -// this test has global folder side effects, run it only in CI +async function createTempPrefixFolder(): Promise { + const prefixFolder = await mkdir('yarn-prefix'); + return path.join(prefixFolder, 'bin'); +} + +// these tests have global folder side or prefix folder effects, run it only in CI if (isCI) { test.concurrent('add without flag', (): Promise => { return runGlobal(['add', 'react-native-cli'], {}, 'add-without-flag', async (config) => { @@ -47,26 +52,26 @@ if (isCI) { expect(await fs.exists(path.join(config.globalFolder, 'node_modules', '.bin', 'react-native'))).toEqual(true); }); }); -} -test.concurrent('add with prefix flag', (): Promise => { - const tmpGlobalFolder = getTempGlobalFolder(); - return runGlobal(['add', 'react-native-cli'], {prefix: tmpGlobalFolder}, 'add-with-prefix-flag', async (config) => { - expect(await fs.exists(getGlobalPath(tmpGlobalFolder, 'react-native'))).toEqual(true); + test.concurrent('add with prefix flag', (): Promise => { + const tmpGlobalFolder = getTempGlobalFolder(); + return runGlobal(['add', 'react-native-cli'], {prefix: tmpGlobalFolder}, 'add-with-prefix-flag', async (config) => { + expect(await fs.exists(getGlobalPath(tmpGlobalFolder, 'react-native'))).toEqual(true); + }); }); -}); -// don't run this test in `concurrent`, it will affect other tests -test('add with PREFIX enviroment variable', (): Promise => { - const tmpGlobalFolder = getTempGlobalFolder(); - const envPrefix = process.env.PREFIX; - process.env.PREFIX = tmpGlobalFolder; - return runGlobal(['add', 'react-native-cli'], {}, 'add-with-prefix-env', async (config) => { - expect(await fs.exists(getGlobalPath(tmpGlobalFolder, 'react-native'))).toEqual(true); - // restore env - process.env.PREFIX = envPrefix; + // don't run this test in `concurrent`, it will affect other tests + test('add with PREFIX enviroment variable', (): Promise => { + const tmpGlobalFolder = getTempGlobalFolder(); + const envPrefix = process.env.PREFIX; + process.env.PREFIX = tmpGlobalFolder; + return runGlobal(['add', 'react-native-cli'], {}, 'add-with-prefix-env', async (config) => { + expect(await fs.exists(getGlobalPath(tmpGlobalFolder, 'react-native'))).toEqual(true); + // restore env + process.env.PREFIX = envPrefix; + }); }); -}); +} test.concurrent('bin', (): Promise => { const tmpGlobalFolder = getTempGlobalFolder(); @@ -78,7 +83,9 @@ test.concurrent('bin', (): Promise => { test.concurrent('add', async (): Promise => { const tmpGlobalFolder = await createTempGlobalFolder(); - return runGlobal(['add', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', + const tmpPrefixFolder = await createTempPrefixFolder(); + const flags = {globalFolder: tmpGlobalFolder, prefix: tmpPrefixFolder}; + return runGlobal(['add', 'react-native-cli'], flags, 'add-with-prefix-flag', async (config) => { expect(await fs.exists(path.join(tmpGlobalFolder, 'node_modules', 'react-native-cli'))).toEqual(true); }); @@ -86,10 +93,11 @@ test.concurrent('add', async (): Promise => { test.concurrent('remove', async (): Promise => { const tmpGlobalFolder = await createTempGlobalFolder(); - return runGlobal(['add', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', () => {}) + const tmpPrefixFolder = await createTempPrefixFolder(); + const flags = {globalFolder: tmpGlobalFolder, prefix: tmpPrefixFolder}; + return runGlobal(['add', 'react-native-cli'], flags, 'add-with-prefix-flag', () => {}) .then(() => { - return runGlobal(['remove', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', - async (config) => { + return runGlobal(['remove', 'react-native-cli'], flags, 'add-with-prefix-flag', async (config) => { expect(await fs.exists(path.join(tmpGlobalFolder, 'node_modules', 'react-native-cli'))).toEqual(false); }); }); @@ -97,10 +105,11 @@ test.concurrent('remove', async (): Promise => { test.concurrent('ls', async (): Promise => { const tmpGlobalFolder = await createTempGlobalFolder(); - return runGlobal(['add', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', () => {}) + const tmpPrefixFolder = await createTempPrefixFolder(); + const flags = {globalFolder: tmpGlobalFolder, prefix: tmpPrefixFolder}; + return runGlobal(['add', 'react-native-cli'], flags, 'add-with-prefix-flag', () => {}) .then(() => { - return runGlobal(['ls'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', - (config, reporter, install, getStdout) => { + return runGlobal(['ls'], flags, 'add-with-prefix-flag', (config, reporter, install, getStdout) => { expect(getStdout()).toContain('react-native-cli'); }); }); @@ -108,9 +117,11 @@ test.concurrent('ls', async (): Promise => { test.concurrent('upgrade', async (): Promise => { const tmpGlobalFolder = await createTempGlobalFolder(); - return runGlobal(['add', 'react-native-cli@2.0.0'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', () => {}) + const tmpPrefixFolder = await createTempPrefixFolder(); + const flags = {globalFolder: tmpGlobalFolder, prefix: tmpPrefixFolder}; + return runGlobal(['add', 'react-native-cli@2.0.0'], flags, 'add-with-prefix-flag', () => {}) .then(() => { - return runGlobal(['upgrade', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', + return runGlobal(['upgrade', 'react-native-cli'], flags, 'add-with-prefix-flag', (config, reporter, install, getStdout) => { expect(getStdout()).toContain('react-native-cli'); expect(getStdout()).not.toContain('react-native-cli@2.0.0');