Skip to content

Commit

Permalink
Replaces assert w/ expect (yarnpkg#3014)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis authored and bestander committed Mar 29, 2017
1 parent f9c433d commit 76c9fc1
Show file tree
Hide file tree
Showing 13 changed files with 616 additions and 524 deletions.
422 changes: 229 additions & 193 deletions __tests__/commands/add.js

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions __tests__/commands/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {CLIFunctionReturn} from '../../src/types.js';
import * as reporters from '../../src/reporters/index.js';
import * as checkCmd from '../../src/cli/commands/check.js';
import {run as buildRun} from './_helpers.js';
import assert from 'assert';

const path = require('path');

Expand All @@ -26,7 +25,7 @@ test('--verify-tree should report wrong version ', async (): Promise<void> => {
} catch (e) {
thrown = true;
}
assert(thrown);
expect(thrown).toEqual(true);
});

test('--verify-tree should report missing dependency ',
Expand All @@ -37,7 +36,7 @@ async (): Promise<void> => {
} catch (e) {
thrown = true;
}
assert(thrown);
expect(thrown).toEqual(true);
});

test('--verify-tree should pass on hoisted dependency ',
Expand All @@ -53,7 +52,7 @@ async (): Promise<void> => {
} catch (e) {
thrown = true;
}
assert(thrown);
expect(thrown).toEqual(true);
});

test('--verify-tree should check skip dev dependencies if --production flag passed',
Expand All @@ -65,4 +64,3 @@ test('--verify-tree should check skip deeper dev dependencies',
async (): Promise<void> => {
await runCheck([], {verifyTree: true, production: true}, 'verify-tree-dev-deep');
});

9 changes: 4 additions & 5 deletions __tests__/commands/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {ConsoleReporter} from '../../src/reporters/index.js';
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 @@ -39,16 +38,16 @@ function getTempGlobalFolder(): string {
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')));
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) => {
assert.ok(await fs.exists(getGlobalPath(tmpGlobalFolder, 'react-native')));
expect(await fs.exists(getGlobalPath(tmpGlobalFolder, 'react-native'))).toEqual(true);
});
});

Expand All @@ -58,7 +57,7 @@ test('add with PREFIX enviroment variable', (): Promise<void> => {
const envPrefix = process.env.PREFIX;
process.env.PREFIX = tmpGlobalFolder;
return runGlobal(['add', 'react-native-cli'], {}, 'add-with-prefix-env', async (config) => {
assert.ok(await fs.exists(getGlobalPath(tmpGlobalFolder, 'react-native')));
expect(await fs.exists(getGlobalPath(tmpGlobalFolder, 'react-native'))).toEqual(true);
// restore env
process.env.PREFIX = envPrefix;
});
Expand Down
13 changes: 6 additions & 7 deletions __tests__/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {ConsoleReporter} from '../../src/reporters/index.js';
import {run as buildRun} from './_helpers.js';
import {getGitConfigInfo, run as runInit} from '../../src/cli/commands/init.js';
import * as fs from '../../src/util/fs.js';
import assert from 'assert';

const path = require('path');

Expand All @@ -27,17 +26,17 @@ test.concurrent('init --yes should create package.json with defaults', (): Prom
const manifestFile = await fs.readFile(path.join(cwd, 'package.json'));
const manifest = JSON.parse(manifestFile);

assert.equal(manifest.name, path.basename(cwd));
assert.equal(manifest.main, 'index.js');
assert.equal(manifest.version, String(config.getOption('init-version')));
assert.equal(manifest.license, String(config.getOption('init-license')));
expect(manifest.name).toEqual(path.basename(cwd));
expect(manifest.main).toEqual('index.js');
expect(manifest.version).toEqual(String(config.getOption('init-version')));
expect(manifest.license).toEqual(String(config.getOption('init-license')));
});
});

test.concurrent('getGitConfigInfo should not return the git config val', async (): Promise<void> => {
assert.equal('hi seb', await getGitConfigInfo('some-info', () => Promise.resolve('hi seb')));
expect('hi seb').toEqual(await getGitConfigInfo('some-info', () => Promise.resolve('hi seb')));
});

test.concurrent('getGitConfigInfo should not fail when git fails', async (): Promise<void> => {
assert.equal('', await getGitConfigInfo('some-info', () => Promise.reject(Error())));
expect('').toEqual(await getGitConfigInfo('some-info', () => Promise.reject(Error())));
});
120 changes: 59 additions & 61 deletions __tests__/commands/install/integration-deduping.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import {getPackageVersion, runInstall} from '../_helpers.js';
import * as fs from '../../../src/util/fs.js';

const assert = require('assert');
const path = require('path');

jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;
Expand All @@ -13,8 +12,8 @@ test.concurrent('install should dedupe dependencies avoiding conflicts 0', (): P
// B@1.0.0
// should result in B@2.0.0 not flattened
return runInstall({}, 'install-should-dedupe-avoiding-conflicts-0', async (config) => {
assert.equal(await getPackageVersion(config, 'dep-b'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-a/dep-b'), '2.0.0');
expect(await getPackageVersion(config, 'dep-b')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-a/dep-b')).toEqual('2.0.0');
});
});

Expand All @@ -23,8 +22,8 @@ test.concurrent('install should dedupe dependencies avoiding conflicts 1', (): P
// A@2.0.1 -> B@2.0.0
// should result in B@2.0.0 flattened
return runInstall({}, 'install-should-dedupe-avoiding-conflicts-1', async (config) => {
assert.equal(await getPackageVersion(config, 'dep-b'), '2.0.0');
assert.equal(await getPackageVersion(config, 'dep-a'), '2.0.1');
expect(await getPackageVersion(config, 'dep-b')).toEqual('2.0.0');
expect(await getPackageVersion(config, 'dep-a')).toEqual('2.0.1');
});
});

Expand All @@ -42,12 +41,12 @@ test.concurrent('install should dedupe dependencies avoiding conflicts 2', (): P
// B@1

return runInstall({}, 'install-should-dedupe-avoiding-conflicts-2', async (config) => {
assert.equal(await getPackageVersion(config, 'dep-a'), '2.0.0');
assert.equal(await getPackageVersion(config, 'dep-a/dep-b'), '2.0.0');
assert.equal(await getPackageVersion(config, 'dep-c'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-d'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-b'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-a/dep-c'), '2.0.0');
expect(await getPackageVersion(config, 'dep-a')).toEqual('2.0.0');
expect(await getPackageVersion(config, 'dep-a/dep-b')).toEqual('2.0.0');
expect(await getPackageVersion(config, 'dep-c')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-d')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-b')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-a/dep-c')).toEqual('2.0.0');
});
});

Expand All @@ -61,11 +60,11 @@ test.concurrent('install should dedupe dependencies avoiding conflicts 3', (): P
// C@1
// D@1
return runInstall({}, 'install-should-dedupe-avoiding-conflicts-3', async (config) => {
assert.equal(await getPackageVersion(config, 'dep-a'), '2.0.0');
assert.equal(await getPackageVersion(config, 'dep-c'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-d'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-b'), '2.0.0');
assert.equal(await getPackageVersion(config, 'dep-b/dep-c'), '2.0.0');
expect(await getPackageVersion(config, 'dep-a')).toEqual('2.0.0');
expect(await getPackageVersion(config, 'dep-c')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-d')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-b')).toEqual('2.0.0');
expect(await getPackageVersion(config, 'dep-b/dep-c')).toEqual('2.0.0');
});
});

Expand All @@ -80,11 +79,11 @@ test.concurrent('install should dedupe dependencies avoiding conflicts 4', (): P
// C@1
// B@2
return runInstall({}, 'install-should-dedupe-avoiding-conflicts-4', async (config) => {
assert.equal(await getPackageVersion(config, 'dep-a'), '2.0.0');
assert.equal(await getPackageVersion(config, 'dep-c'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-d'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-d/dep-c'), '2.0.0');
assert.equal(await getPackageVersion(config, 'dep-b'), '2.0.0');
expect(await getPackageVersion(config, 'dep-a')).toEqual('2.0.0');
expect(await getPackageVersion(config, 'dep-c')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-d')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-d/dep-c')).toEqual('2.0.0');
expect(await getPackageVersion(config, 'dep-b')).toEqual('2.0.0');
});
});

Expand All @@ -101,13 +100,12 @@ test.concurrent('install should dedupe dependencies avoiding conflicts 5', (): P
// -> B@2

return runInstall({}, 'install-should-dedupe-avoiding-conflicts-5', async (config) => {
assert.equal(await getPackageVersion(config, 'dep-a'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-b'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-c'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-d'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-d/dep-a'), '2.0.0');
assert.equal(await getPackageVersion(config, 'dep-d/dep-b'), '2.0.0');

expect(await getPackageVersion(config, 'dep-a')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-b')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-c')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-d')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-d/dep-a')).toEqual('2.0.0');
expect(await getPackageVersion(config, 'dep-d/dep-b')).toEqual('2.0.0');
});
});

Expand All @@ -128,13 +126,13 @@ test.concurrent(
// E@2

return runInstall({}, 'install-should-dedupe-avoiding-conflicts-6', async (config): Promise<void> => {
assert.equal(await getPackageVersion(config, 'dep-b'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-c'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-d'), '2.0.0');
assert.equal(await getPackageVersion(config, 'dep-e'), '2.0.0');
expect(await getPackageVersion(config, 'dep-b')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-c')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-d')).toEqual('2.0.0');
expect(await getPackageVersion(config, 'dep-e')).toEqual('2.0.0');

assert.equal(await getPackageVersion(config, 'dep-c/dep-d'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-c/dep-e'), '1.0.0');
expect(await getPackageVersion(config, 'dep-c/dep-d')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-c/dep-e')).toEqual('1.0.0');
});
},
);
Expand All @@ -159,19 +157,19 @@ test.concurrent('install should dedupe dependencies avoiding conflicts 7', (): P
// E@2

return runInstall({}, 'install-should-dedupe-avoiding-conflicts-7', async (config) => {
assert.equal(await getPackageVersion(config, 'dep-a'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-b'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-c'), '2.0.0');
assert.equal(await getPackageVersion(config, 'dep-d'), '2.0.0');
assert.equal(await getPackageVersion(config, 'dep-e'), '2.0.0');

assert.equal(await getPackageVersion(config, 'dep-a/dep-c'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-a/dep-d'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-a/dep-e'), '1.0.0');

assert.equal(await getPackageVersion(config, 'dep-b/dep-c'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-b/dep-d'), '1.0.0');
assert.equal(await getPackageVersion(config, 'dep-b/dep-e'), '1.0.0');
expect(await getPackageVersion(config, 'dep-a')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-b')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-c')).toEqual('2.0.0');
expect(await getPackageVersion(config, 'dep-d')).toEqual('2.0.0');
expect(await getPackageVersion(config, 'dep-e')).toEqual('2.0.0');

expect(await getPackageVersion(config, 'dep-a/dep-c')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-a/dep-d')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-a/dep-e')).toEqual('1.0.0');

expect(await getPackageVersion(config, 'dep-b/dep-c')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-b/dep-d')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-b/dep-e')).toEqual('1.0.0');
});
});

Expand All @@ -181,12 +179,12 @@ if (!process.env.TRAVIS || process.env.TRAVIS_OS_NAME !== 'osx') {
// revealed in https://github.com/yarnpkg/yarn/issues/112
// adapted for https://github.com/yarnpkg/yarn/issues/1158
return runInstall({}, 'install-should-dedupe-avoiding-conflicts-8', async (config) => {
assert.equal(await getPackageVersion(config, 'glob'), '5.0.15');
assert.equal(await getPackageVersion(config, 'findup-sync/glob'), '4.3.5');
assert.equal(await getPackageVersion(config, 'inquirer'), '0.8.5');
assert.equal(await getPackageVersion(config, 'lodash'), '3.10.1');
assert.equal(await getPackageVersion(config, 'ast-query/lodash'), '4.15.0');
assert.equal(await getPackageVersion(config, 'run-async'), '0.1.0');
expect(await getPackageVersion(config, 'glob')).toEqual('5.0.15');
expect(await getPackageVersion(config, 'findup-sync/glob')).toEqual('4.3.5');
expect(await getPackageVersion(config, 'inquirer')).toEqual('0.8.5');
expect(await getPackageVersion(config, 'lodash')).toEqual('3.10.1');
expect(await getPackageVersion(config, 'ast-query/lodash')).toEqual('4.15.0');
expect(await getPackageVersion(config, 'run-async')).toEqual('0.1.0');
});
});
}
Expand All @@ -195,12 +193,12 @@ test.concurrent('install should dedupe dependencies avoiding conflicts 9', (): P
// revealed in https://github.com/yarnpkg/yarn/issues/112
// adapted for https://github.com/yarnpkg/yarn/issues/1158
return runInstall({}, 'install-should-dedupe-avoiding-conflicts-9', async (config) => {
assert.equal(await getPackageVersion(config, 'glob'), '5.0.15');
assert.equal(await getPackageVersion(config, 'findup-sync/glob'), '4.3.5');
assert.equal(await getPackageVersion(config, 'inquirer'), '0.8.5');
assert.equal(await getPackageVersion(config, 'lodash'), '3.10.1');
assert.equal(await getPackageVersion(config, 'ast-query/lodash'), '4.15.0');
assert.equal(await getPackageVersion(config, 'run-async'), '0.1.0');
expect(await getPackageVersion(config, 'glob')).toEqual('5.0.15');
expect(await getPackageVersion(config, 'findup-sync/glob')).toEqual('4.3.5');
expect(await getPackageVersion(config, 'inquirer')).toEqual('0.8.5');
expect(await getPackageVersion(config, 'lodash')).toEqual('3.10.1');
expect(await getPackageVersion(config, 'ast-query/lodash')).toEqual('4.15.0');
expect(await getPackageVersion(config, 'run-async')).toEqual('0.1.0');
});
});

Expand All @@ -217,7 +215,7 @@ test.concurrent('install should hardlink repeated dependencies', (): Promise<voi
config.cwd,
'node_modules/c/node_modules/a/package.json',
));
assert.equal(b_a.ino, c_a.ino);
expect(b_a.ino).toEqual(c_a.ino);
});
});

Expand All @@ -234,6 +232,6 @@ test.concurrent('install should not hardlink repeated dependencies if linkDuplic
config.cwd,
'node_modules/c/node_modules/a/package.json',
));
assert(b_a.ino != c_a.ino);
expect(b_a.ino).not.toEqual(c_a.ino);
});
});
5 changes: 2 additions & 3 deletions __tests__/commands/install/integration-hoisting.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* @flow */

import assert from 'assert';
import {getPackageVersion, runInstall} from '../_helpers.js';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;
Expand All @@ -10,7 +9,7 @@ test.concurrent('install hoister should prioritise popular transitive dependenci
// -> c
// -> b-2
return runInstall({}, 'install-should-prioritise-popular-transitive', async (config) => {
assert.equal(await getPackageVersion(config, 'b'), '2.0.0');
assert.equal(await getPackageVersion(config, 'a/b'), '0.0.0');
expect(await getPackageVersion(config, 'b')).toEqual('2.0.0');
expect(await getPackageVersion(config, 'a/b')).toEqual('0.0.0');
});
});
Loading

0 comments on commit 76c9fc1

Please sign in to comment.