Skip to content

Commit

Permalink
move tests with side-effects under isCI branch; the other tests now a…
Browse files Browse the repository at this point in the history
…re side-effects free
  • Loading branch information
voxsim committed Apr 23, 2017
1 parent d0bddc6 commit 0d0f3ed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
1 change: 1 addition & 0 deletions __tests__/commands/_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export async function run<T, R>(
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);

Expand Down
63 changes: 37 additions & 26 deletions __tests__/commands/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,39 @@ async function createTempGlobalFolder(): Promise<string> {
return await mkdir('yarn-global');
}

// this test has global folder side effects, run it only in CI
async function createTempPrefixFolder(): Promise<string> {
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<void> => {
return runGlobal(['add', 'react-native-cli'], {}, 'add-without-flag', async (config) => {
expect(await fs.exists(path.join(config.globalFolder, 'node_modules', 'react-native-cli'))).toEqual(true);
expect(await fs.exists(path.join(config.globalFolder, 'node_modules', '.bin', 'react-native'))).toEqual(true);
});
});
}

test.concurrent('add with prefix flag', (): Promise<void> => {
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<void> => {
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<void> => {
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<void> => {
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<void> => {
const tmpGlobalFolder = getTempGlobalFolder();
Expand All @@ -78,39 +83,45 @@ test.concurrent('bin', (): Promise<void> => {

test.concurrent('add', async (): Promise<void> => {
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);
});
});

test.concurrent('remove', async (): Promise<void> => {
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);
});
});
});

test.concurrent('ls', async (): Promise<void> => {
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');
});
});
});

test.concurrent('upgrade', async (): Promise<void> => {
const tmpGlobalFolder = await createTempGlobalFolder();
return runGlobal(['add', '[email protected]'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', () => {})
const tmpPrefixFolder = await createTempPrefixFolder();
const flags = {globalFolder: tmpGlobalFolder, prefix: tmpPrefixFolder};
return runGlobal(['add', '[email protected]'], 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('[email protected]');
Expand Down

0 comments on commit 0d0f3ed

Please sign in to comment.