Skip to content

Commit

Permalink
test(core): improve branch coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Aug 23, 2020
1 parent 34eceaf commit bfed243
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
23 changes: 22 additions & 1 deletion src/commands/__snapshots__/fix-mismatches.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`fixMismatches ignores non-semver dependencies 1`] = `
Array [
Object {
"contents": Object {
"dependencies": Object {
"foo": "link:vendor/foo-0.1.0",
},
},
"filePath": "/a/package.json",
},
Object {
"contents": Object {
"dependencies": Object {
"foo": "link:vendor/foo-0.2.0",
},
},
"filePath": "/b/package.json",
},
]
`;

exports[`fixMismatches sets all dependencies installed with different versions to the highest version 1`] = `
Array [
Object {
Expand All @@ -12,7 +33,7 @@ Array [
},
Object {
"contents": Object {
"dependencies": Object {
"devDependencies": Object {
"foo": "0.2.0",
},
},
Expand Down
13 changes: 11 additions & 2 deletions src/commands/fix-mismatches.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ describe('fixMismatches', () => {
});

it('sets all dependencies installed with different versions to the highest version', () => {
const wrappers = [mock.wrapper('a', ['foo@0.1.0']), mock.wrapper('b', ['foo@0.2.0'])];
fixMismatches(['dependencies'], /./, wrappers);
const wrappers = [mock.wrapper('a', ['foo@0.1.0']), mock.wrapper('b', [], ['foo@0.2.0'])];
fixMismatches(['dependencies', 'devDependencies', 'peerDependencies'], /./, wrappers);
expect(wrappers).toMatchSnapshot();
});

it('ignores non-semver dependencies', () => {
const wrappers = [
mock.wrapper('a', ['foo@link:vendor/foo-0.1.0']),
mock.wrapper('b', ['foo@link:vendor/foo-0.2.0']),
];
fixMismatches(['dependencies', 'devDependencies', 'peerDependencies'], /./, wrappers);
expect(wrappers).toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion src/commands/format.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DEFAULT_CONFIG } from '../constants';
import { format } from './format';
import { Source, SourceWrapper } from './lib/get-wrappers';
import { DEFAULT_CONFIG } from '../constants';

const createWrapper = (contents: Source): SourceWrapper => ({ contents, filePath: '' });

Expand Down
2 changes: 1 addition & 1 deletion src/commands/lib/get-wrappers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { sync as readYamlFileSync } from 'read-yaml-file';
import { isArrayOfStrings } from 'expect-more';
import { readJsonSync } from 'fs-extra';
import { sync } from 'glob';
import { join, resolve } from 'path';
import { sync as readYamlFileSync } from 'read-yaml-file';
import { ALL_PATTERNS } from '../../constants';

interface Options {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/get-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cosmiconfigSync } from 'cosmiconfig';
import { isArray, isBoolean, isNonEmptyString, isObject, isRegExp, isArrayOfStrings } from 'expect-more';
import { isArray, isArrayOfStrings, isBoolean, isNonEmptyString, isObject, isRegExp } from 'expect-more';
import { isValidSemverRange } from '../commands/lib/is-semver';
import { DEFAULT_CONFIG, SyncpackConfig } from '../constants';

Expand Down
8 changes: 4 additions & 4 deletions test/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ const toObject = (identifiers: string[]): { [key: string]: string } =>
return memo;
}, {});

export const wrapper = (dirName: string, deps: string[], devDeps?: string[], peerDeps?: string[]): SourceWrapper => {
export const wrapper = (dirName: string, deps?: string[], devDeps?: string[], peerDeps?: string[]): SourceWrapper => {
return {
contents: {
...(deps ? { dependencies: toObject(deps) } : {}),
...(devDeps ? { devDependencies: toObject(devDeps) } : {}),
...(peerDeps ? { peerDependencies: toObject(peerDeps) } : {}),
...(deps && deps.length > 0 ? { dependencies: toObject(deps) } : {}),
...(devDeps && devDeps.length > 0 ? { devDependencies: toObject(devDeps) } : {}),
...(peerDeps && peerDeps.length > 0 ? { peerDependencies: toObject(peerDeps) } : {}),
},
filePath: `/${dirName}/package.json`,
};
Expand Down

0 comments on commit bfed243

Please sign in to comment.