Skip to content

Commit

Permalink
update jest and flow
Browse files Browse the repository at this point in the history
  • Loading branch information
voxsim committed Jun 15, 2017
1 parent 7e52cbb commit fe401db
Show file tree
Hide file tree
Showing 48 changed files with 508 additions and 453 deletions.
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe
unsafe.enable_getters_and_setters=true

[version]
^0.43.0
^0.48.0
16 changes: 5 additions & 11 deletions __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,7 @@ test.concurrent('install should be idempotent', (): Promise<void> => {
async (config, reporter) => {
expect(await getPackageVersion(config, 'dep-a')).toEqual('1.0.0');
},
null,
false,
null
);

return runInstall({}, 'install-should-be-idempotent', async (config, reporter) => {
Expand Down Expand Up @@ -815,15 +814,10 @@ test.concurrent('prunes the offline mirror tarballs after pruning is enabled', (
test.concurrent('scoped packages remain in offline mirror after pruning is enabled', (): Promise<void> => {
return runInstall({}, 'prune-offline-mirror-scoped', async (config): Promise<void> => {
const mirrorPath = 'mirror-for-offline';
// Ensure that scoped packages remain mangled and resolvable
expect(await fs.exists(path.join(config.cwd, `${mirrorPath}/@fakescope-fake-dependency-1.0.1.tgz`))).toEqual(
true,
'scoped package exists',
);
expect(await fs.exists(path.join(config.cwd, `${mirrorPath}/fake-dependency-1.0.1.tgz`))).toEqual(
true,
'unscoped package exists',
);
// scoped package exists
expect(await fs.exists(path.join(config.cwd, `${mirrorPath}/@fakescope-fake-dependency-1.0.1.tgz`))).toEqual(true);
// unscoped package exists
expect(await fs.exists(path.join(config.cwd, `${mirrorPath}/fake-dependency-1.0.1.tgz`))).toEqual(true);
});
});

Expand Down
120 changes: 44 additions & 76 deletions __tests__/commands/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,25 +174,17 @@ test.concurrent('upgrades dependency packages not in registry', (): Promise<void

const lockFileIncludes = sha => lockfile.includes(` resolved "${gitRemote}#${sha}"`);

expect(lockfile.includes(`"yarn-test-git-repo@${gitRemote}#master":`)).toEqual(
true,
'Lockfile should point to the same yarn-test-git-repo branch.',
);

expect(lockFileIncludes('d2027157d0c7188fc9ed6a6654325d1e3bf4db40')).toEqual(
false,
'Lockfile should update yarn-test-git-repo SHA.',
);

expect(lockfile.includes(`"e2e-test-repo@${gitRemote}#greenkeeper/cross-env-3.1.4":`)).toEqual(
true,
'Lockfile should point to the same e2e-test-repo branch.',
);

expect(lockFileIncludes('da5940e1ad2b7451c00edffb6e755bf2411fc705')).toEqual(
true,
'Lockfile should keep latest e2e-test-repo SHA.',
);
// Lockfile should point to the same yarn-test-git-repo branch
expect(lockfile.includes(`"yarn-test-git-repo@${gitRemote}#master":`)).toEqual(true);

// Lockfile should update yarn-test-git-repo SHA
expect(lockFileIncludes('d2027157d0c7188fc9ed6a6654325d1e3bf4db40')).toEqual(false);

// Lockfile should point to the same e2e-test-repo branch
expect(lockfile.includes(`"e2e-test-repo@${gitRemote}#greenkeeper/cross-env-3.1.4":`)).toEqual(true);

// Lockfile should keep latest e2e-test-repo SHA
expect(lockFileIncludes('da5940e1ad2b7451c00edffb6e755bf2411fc705')).toEqual(true);
});
});

Expand All @@ -204,25 +196,17 @@ test.concurrent('upgrades dev dependency packages not in registry', (): Promise<

const lockFileIncludes = sha => lockfile.includes(` resolved "${gitRemote}#${sha}"`);

expect(lockfile.includes(`"yarn-test-git-repo@${gitRemote}#master":`)).toEqual(
true,
'Lockfile should point to the same yarn-test-git-repo branch.',
);

expect(lockFileIncludes('d2027157d0c7188fc9ed6a6654325d1e3bf4db40')).toEqual(
false,
'Lockfile should update yarn-test-git-repo SHA.',
);

expect(lockfile.includes(`"e2e-test-repo@${gitRemote}#greenkeeper/cross-env-3.1.4":`)).toEqual(
true,
'Lockfile should point to the same e2e-test-repo branch.',
);

expect(lockFileIncludes('da5940e1ad2b7451c00edffb6e755bf2411fc705')).toEqual(
true,
'Lockfile should keep latest e2e-test-repo SHA.',
);
// Lockfile should point to the same yarn-test-git-repo branch
expect(lockfile.includes(`"yarn-test-git-repo@${gitRemote}#master":`)).toEqual(true);

// Lockfile should update yarn-test-git-repo SHA
expect(lockFileIncludes('d2027157d0c7188fc9ed6a6654325d1e3bf4db40')).toEqual(false);

// Lockfile should point to the same e2e-test-repo branch
expect(lockfile.includes(`"e2e-test-repo@${gitRemote}#greenkeeper/cross-env-3.1.4":`)).toEqual(true);

// Lockfile should keep latest e2e-test-repo SHA
expect(lockFileIncludes('da5940e1ad2b7451c00edffb6e755bf2411fc705')).toEqual(true);
});
});

Expand All @@ -234,25 +218,17 @@ test.concurrent('upgrades optional dependency packages not in registry', (): Pro

const lockFileIncludes = sha => lockfile.includes(` resolved "${gitRemote}#${sha}"`);

expect(lockfile.includes(`"yarn-test-git-repo@${gitRemote}#master":`)).toEqual(
true,
'Lockfile should point to the same yarn-test-git-repo branch.',
);

expect(lockFileIncludes('d2027157d0c7188fc9ed6a6654325d1e3bf4db40')).toEqual(
false,
'Lockfile should update yarn-test-git-repo SHA.',
);

expect(lockfile.includes(`"e2e-test-repo@${gitRemote}#greenkeeper/cross-env-3.1.4":`)).toEqual(
true,
'Lockfile should point to the same e2e-test-repo branch.',
);

expect(lockFileIncludes('da5940e1ad2b7451c00edffb6e755bf2411fc705')).toEqual(
true,
'Lockfile should keep latest e2e-test-repo SHA.',
);
// Lockfile should point to the same yarn-test-git-repo branch
expect(lockfile.includes(`"yarn-test-git-repo@${gitRemote}#master":`)).toEqual(true);

// Lockfile should update yarn-test-git-repo SHA
expect(lockFileIncludes('d2027157d0c7188fc9ed6a6654325d1e3bf4db40')).toEqual(false);

// Lockfile should point to the same e2e-test-repo branch
expect(lockfile.includes(`"e2e-test-repo@${gitRemote}#greenkeeper/cross-env-3.1.4":`)).toEqual(true);

// Lockfile should keep latest e2e-test-repo SHA
expect(lockFileIncludes('da5940e1ad2b7451c00edffb6e755bf2411fc705')).toEqual(true);
});
});

Expand All @@ -264,25 +240,17 @@ test.concurrent('upgrades peer dependency packages not in registry', (): Promise

const lockFileIncludes = sha => lockfile.includes(` resolved "${gitRemote}#${sha}"`);

expect(lockfile.includes(`"yarn-test-git-repo@${gitRemote}#master":`)).toEqual(
true,
'Lockfile should point to the same yarn-test-git-repo branch.',
);

expect(lockFileIncludes('d2027157d0c7188fc9ed6a6654325d1e3bf4db40')).toEqual(
false,
'Lockfile should update yarn-test-git-repo SHA.',
);

expect(lockfile.includes(`"e2e-test-repo@${gitRemote}#greenkeeper/cross-env-3.1.4":`)).toEqual(
true,
'Lockfile should point to the same e2e-test-repo branch.',
);

expect(lockFileIncludes('da5940e1ad2b7451c00edffb6e755bf2411fc705')).toEqual(
true,
'Lockfile should keep latest e2e-test-repo SHA.',
);
// Lockfile should point to the same yarn-test-git-repo branch
expect(lockfile.includes(`"yarn-test-git-repo@${gitRemote}#master":`)).toEqual(true);

// Lockfile should update yarn-test-git-repo SHA
expect(lockFileIncludes('d2027157d0c7188fc9ed6a6654325d1e3bf4db40')).toEqual(false);

// Lockfile should point to the same e2e-test-repo branch
expect(lockfile.includes(`"e2e-test-repo@${gitRemote}#greenkeeper/cross-env-3.1.4":`)).toEqual(true);

// Lockfile should keep latest e2e-test-repo SHA
expect(lockFileIncludes('da5940e1ad2b7451c00edffb6e755bf2411fc705')).toEqual(true);
});
});

Expand Down
53 changes: 24 additions & 29 deletions __tests__/package-hoister.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function createTestFixture(testModules: any = {}): any {
packageResolver.addPattern(uid, packageManifest);
});

const packageHoister = new PackageHoister(config, packageResolver, false);
const packageHoister = new PackageHoister(config, packageResolver);

const atPath = function(...installPaths): string {
const rootPath = config.modulesFolder || path.join(config.cwd, 'node_modules');
Expand All @@ -70,35 +70,30 @@ function createTestFixture(testModules: any = {}): any {
};
}

beforeEach(function() {
jasmine.addMatchers({
toContainPackage(): any {
return {
compare(received, uid, expectedInstallPath): any {
let pass: boolean = false;
received.forEach(pkg => {
const [location: string, hoistManifest: HoistManifest] = pkg;
if (location === expectedInstallPath && hoistManifest.pkg._reference.uid === uid) {
pass = true;
}
});

if (pass) {
return {
pass: true,
message: () => `expected ${received} to not contain package UID ${uid} at path ${expectedInstallPath}`,
};
} else {
return {
pass: false,
message: () => `expected ${received} to contain package UID ${uid} at path ${expectedInstallPath}`,
};
}
},
};
},
const toContainPackage = function(received: any, ...expected: any): JestMatcherResult {
const [uid, expectedInstallPath] = expected;
let pass: boolean = false;
received.forEach(pkg => {
const [location: string, hoistManifest: HoistManifest] = pkg;
if (location === expectedInstallPath && hoistManifest.pkg._reference.uid === uid) {
pass = true;
}
});
});

if (pass) {
return {
pass: true,
message: () => `expected ${received} to not contain package UID ${uid} at path ${expectedInstallPath}`,
};
} else {
return {
pass: false,
message: () => `expected ${received} to contain package UID ${uid} at path ${expectedInstallPath}`,
};
}
};

expect.extend({toContainPackage});

test('Produces valid destination paths for scoped modules', () => {
const expected = path.join(CWD, 'node_modules', '@scoped', 'dep');
Expand Down
10 changes: 5 additions & 5 deletions __tests__/util/env-replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import envReplace from '../../src/util/env-replace';
describe('environment variable replacement', () => {
it('will replace a token that exists in the environment', () => {
let result = envReplace('test ${a} replacement', {a: 'token'});
expect(result).toEqual('test token replacement', `result: ${result}`);
expect(result).toEqual('test token replacement');

result = envReplace('${a} replacement', {a: 'token'});
expect(result).toEqual('token replacement', `result: ${result}`);
expect(result).toEqual('token replacement');

result = envReplace('${a}', {a: 'token'});
expect(result).toEqual('token', `result: ${result}`);
expect(result).toEqual('token');
});

it('will not replace a token that does not exist in the environment', () => {
Expand All @@ -19,13 +19,13 @@ describe('environment variable replacement', () => {
envReplace('${a} replacement', {b: 'token'});
} catch (err) {
thrown = true;
expect(err.message).toEqual('Failed to replace env in config: ${a}', `error message: ${err.message}`);
expect(err.message).toEqual('Failed to replace env in config: ${a}');
}
expect(thrown).toEqual(true);
});

it('will not replace a token when a the token-replacement mechanism is prefixed a backslash literal', () => {
const result = envReplace('\\${a} replacement', {a: 'token'});
expect(result).toEqual('\\${a} replacement', `result: ${result}`);
expect(result).toEqual('\\${a} replacement');
});
});
26 changes: 0 additions & 26 deletions __tests__/util/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,6 @@ test('promisify', async function(): Promise<void> {
expect(error && error.message).toEqual('yep');
});

test('promisifyObject', async function(): Promise<void> {
const obj = promise.promisifyObject({
foo(callback) {
callback(null, 'foo');
},

bar(data, callback) {
callback(null, data + 'bar');
},

foobar(callback) {
callback(new Error('yep'));
},
});

expect(await obj.foo()).toBe('foo');
expect(await obj.bar('foo')).toBe('foobar');
let error;
try {
await obj.foobar();
} catch (e) {
error = e;
}
expect(error && error.message).toEqual('yep');
});

test('queue', async function(): Promise<void> {
let running = 0;

Expand Down
Loading

0 comments on commit fe401db

Please sign in to comment.