diff --git a/__tests__/commands/_helpers.js b/__tests__/commands/_helpers.js index 8a4e4ba757..97d845c757 100644 --- a/__tests__/commands/_helpers.js +++ b/__tests__/commands/_helpers.js @@ -12,7 +12,6 @@ import Config from '../../src/config.js'; const stream = require('stream'); const path = require('path'); -const os = require('os'); const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'install'); @@ -79,13 +78,15 @@ export async function run( const reporter = new Reporter({stdout, stderr: stdout}); - const dir = path.join(fixturesLoc, name); - const cwd = path.join( - os.tmpdir(), - `yarn-${path.basename(dir)}-${Math.random()}`, - ); - await fs.unlink(cwd); - await fs.copy(dir, cwd, reporter); + let cwd; + if (fixturesLoc) { + const dir = path.join(fixturesLoc, name); + cwd = await fs.makeTempDir(path.basename(dir)); + await fs.copy(dir, cwd, reporter); + } else { + // if fixture loc is not set then CWD is some empty temp dir + cwd = await fs.makeTempDir(); + } for (const {basename, absolute} of await fs.walk(cwd)) { if (basename.toLowerCase() === '.ds_store') { diff --git a/__tests__/commands/cache.js b/__tests__/commands/cache.js index 27ed74a4cf..a169a64067 100644 --- a/__tests__/commands/cache.js +++ b/__tests__/commands/cache.js @@ -8,8 +8,6 @@ import * as fs from '../../src/util/fs.js'; const path = require('path'); -jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; - const runConfig = buildRun.bind( null, reporters.ConsoleReporter, diff --git a/__tests__/commands/global.js b/__tests__/commands/global.js index 46d5f15145..a8a9d6f80a 100644 --- a/__tests__/commands/global.js +++ b/__tests__/commands/global.js @@ -6,6 +6,7 @@ import {run as buildRun} from './_helpers.js'; import {run as global} from '../../src/cli/commands/global.js'; import * as fs from '../../src/util/fs.js'; import assert from 'assert'; +const isCI = require('is-ci'); jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; @@ -34,12 +35,15 @@ function getTempGlobalFolder(): string { return path.join(os.tmpdir(), `yarn-global-${Math.random()}`); } -test.concurrent('add without flag', (): Promise => { - return runGlobal(['add', 'react-native-cli'], {}, 'add-without-flag', async (config) => { - assert.ok(await fs.exists(path.join(config.globalFolder, 'node_modules', 'react-native-cli'))); - assert.ok(await fs.exists(path.join(config.globalFolder, 'node_modules', '.bin', 'react-native'))); +// this test has global folder side 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) => { + assert.ok(await fs.exists(path.join(config.globalFolder, 'node_modules', 'react-native-cli'))); + assert.ok(await fs.exists(path.join(config.globalFolder, 'node_modules', '.bin', 'react-native'))); + }); }); -}); +} test.concurrent('add with prefix flag', (): Promise => { const tmpGlobalFolder = getTempGlobalFolder(); diff --git a/__tests__/commands/install/integration.js b/__tests__/commands/install/integration.js index bb5ad56dbd..9618029795 100644 --- a/__tests__/commands/install/integration.js +++ b/__tests__/commands/install/integration.js @@ -174,19 +174,20 @@ test.concurrent('writes a lockfile even when there are no dependencies', (): Pro }); }); -test.concurrent("throws an error if existing lockfile isn't satisfied with --frozen-lockfile", (): Promise => { - const reporter = new reporters.ConsoleReporter({}); +test.concurrent( + "throws an error if existing lockfile isn't satisfied with --frozen-lockfile", + async (): Promise => { + const reporter = new reporters.ConsoleReporter({}); - return new Promise((resolve) => { + let thrown = false; try { - runInstall({frozenLockfile: true}, 'install-throws-error-if-not-satisfied-and-frozen-lockfile', () => {}); + await runInstall({frozenLockfile: true}, 'install-throws-error-if-not-satisfied-and-frozen-lockfile', () => {}); } catch (err) { + thrown = true; expect(err.message).toContain(reporter.lang('frozenLockfileError')); - } finally { - resolve(); } + assert(thrown); }); -}); test.concurrent('install transitive optional dependency from lockfile', (): Promise => { return runInstall({}, 'install-optional-dep-from-lockfile', (config, reporter, install) => { diff --git a/src/util/fs.js b/src/util/fs.js index 19c57a9dea..d47b783fa5 100644 --- a/src/util/fs.js +++ b/src/util/fs.js @@ -510,3 +510,14 @@ export async function writeFilePreservingEol(path: string, data: string) : Promi } await promisify(fs.writeFile)(path, data); } + +// not a strict polyfill for Node's fs.mkdtemp +export async function makeTempDir(prefix?: string): Promise { + const dir = path.join( + os.tmpdir(), + `yarn-${prefix || ''}-${Date.now()}-${Math.random()}`, + ); + await unlink(dir); + await mkdirp(dir); + return dir; +}