Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests stability improvements #2362

Merged
merged 11 commits into from
Jan 2, 2017
17 changes: 9 additions & 8 deletions __tests__/commands/_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -79,13 +78,15 @@ export async function run<T, R>(

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') {
Expand Down
2 changes: 0 additions & 2 deletions __tests__/commands/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 9 additions & 5 deletions __tests__/commands/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -34,12 +35,15 @@ function getTempGlobalFolder(): string {
return path.join(os.tmpdir(), `yarn-global-${Math.random()}`);
}

test.concurrent('add without flag', (): Promise<void> => {
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<void> => {
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<void> => {
const tmpGlobalFolder = getTempGlobalFolder();
Expand Down
15 changes: 8 additions & 7 deletions __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
const reporter = new reporters.ConsoleReporter({});
test.concurrent(
"throws an error if existing lockfile isn't satisfied with --frozen-lockfile",
async (): Promise<void> => {
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<void> => {
return runInstall({}, 'install-optional-dep-from-lockfile', (config, reporter, install) => {
Expand Down
11 changes: 11 additions & 0 deletions src/util/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
const dir = path.join(
os.tmpdir(),
`yarn-${prefix || ''}-${Date.now()}-${Math.random()}`,
);
await unlink(dir);
await mkdirp(dir);
return dir;
}