-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move tests with side-effects under isCI branch; the other tests now a…
…re side-effects free
- Loading branch information
Showing
2 changed files
with
38 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
|
@@ -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]'); | ||
|