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

compare current version against latest and not wanted version in outdated command #4519

Merged
merged 6 commits into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions __tests__/commands/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ const runOutdated = buildRun.bind(
write() {},
}),
});

// mock all formatters so we can assert on all of them
const mockFormat = {};
Object.keys(this.format).forEach(key => {
mockFormat[key] = jest.fn(this.format[key]);
});
// $FlowFixMe
this.format = mockFormat;
}

info(msg: string) {
// Overwrite to not interfere with the table output
}
},
fixturesLoc,
Expand Down Expand Up @@ -56,6 +68,7 @@ test.concurrent('works with no arguments', (): Promise<void> => {
const json: Object = JSON.parse(out);

expect(json.data.body.length).toBe(1);
expect(reporter.format.green).toHaveBeenCalledWith('left-pad');
});
});

Expand All @@ -65,6 +78,7 @@ test.concurrent('works with single argument', (): Promise<void> => {

expect(json.data.body.length).toBe(1);
expect(json.data.body[0][0]).toBe('max-safe-integer');
expect(reporter.format.green).toHaveBeenCalledWith('max-safe-integer');
});
});

Expand All @@ -77,6 +91,8 @@ test.concurrent('works with multiple arguments', (): Promise<void> => {
expect(json.data.body.length).toBe(2);
expect(json.data.body[0][0]).toBe('left-pad');
expect(json.data.body[1][0]).toBe('max-safe-integer');
expect(reporter.format.yellow).toHaveBeenCalledWith('left-pad');
expect(reporter.format.green).toHaveBeenCalledWith('max-safe-integer');
});
});

Expand All @@ -95,7 +111,9 @@ test.concurrent('works with exotic resolvers', (): Promise<void> => {

expect(json.data.body.length).toBe(2);
expect(json.data.body[0]).toEqual(first);
expect(reporter.format.red).toHaveBeenCalledWith('max-safe-integer');
expect(json.data.body[1]).toEqual(second);
expect(reporter.format.red).toHaveBeenCalledWith('yarn');
});
});

Expand All @@ -112,6 +130,7 @@ test.concurrent('shows when wanted > current and current > latest', (): Promise<
expect(json.data.body.length).toBe(1);
expect(json.data.body[0][0]).toBe('webpack');
expect(semver.lt(json.data.body[0][1], json.data.body[0][2])).toBe(true);
expect(reporter.format.yellow).toHaveBeenCalledWith('webpack');
});
});

Expand All @@ -124,10 +143,13 @@ test.concurrent('displays correct dependency types', (): Promise<void> => {
expect(json.data.body.length).toBe(3);
expect(body[0][0]).toBe('is-online');
expect(body[0][4]).toBe('optionalDependencies');
expect(reporter.format.red).toHaveBeenCalledWith('is-online');
expect(body[1][0]).toBe('left-pad');
expect(body[1][4]).toBe('dependencies');
expect(reporter.format.yellow).toHaveBeenCalledWith('left-pad');
expect(body[2][0]).toBe('max-safe-integer');
expect(body[2][4]).toBe('devDependencies');
expect(reporter.format.green).toHaveBeenCalledWith('max-safe-integer');
});
});

Expand Down
8 changes: 7 additions & 1 deletion src/cli/commands/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
}

const getNameFromHint = hint => (hint ? `${hint}Dependencies` : 'dependencies');
const colorizeName = ({current, wanted, name}) => reporter.format[colorForVersions(current, wanted)](name);
const colorizeName = ({current, latest, name}) => reporter.format[colorForVersions(current, latest)](name);

if (deps.length) {
const usesWorkspaces = !!config.workspaceRootFolder;
Expand All @@ -50,11 +50,17 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
return row;
});

const red = reporter.format.red('<red>');
const yellow = reporter.format.yellow('<yellow>');
const green = reporter.format.green('<green>');
reporter.info(reporter.lang('legendColorsForVersionUpdates', red, yellow, green));

const header = ['Package', 'Current', 'Wanted', 'Latest', 'Workspace', 'Package Type', 'URL'];
if (!usesWorkspaces) {
header.splice(4, 1);
}
reporter.table(header, body);

return 1;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/upgrade-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
const red = reporter.format.red('<red>');
const yellow = reporter.format.yellow('<yellow>');
const green = reporter.format.green('<green>');
reporter.info(reporter.lang('legendColorsForUpgradeInteractive', red, yellow, green));
reporter.info(reporter.lang('legendColorsForVersionUpdates', red, yellow, green));

const answers: Array<Dependency> = await reporter.prompt('Choose which packages to update.', choices, {
name: 'packages',
Expand Down
2 changes: 1 addition & 1 deletion src/reporters/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const messages = {
noPermission: 'Cannot create $0 due to insufficient permissions.',
noGlobalFolder: 'Cannot find a suitable global folder. Tried these: $0',
allDependenciesUpToDate: 'All of your dependencies are up to date.',
legendColorsForUpgradeInteractive:
legendColorsForVersionUpdates:
'Color legend : \n $0 : Major Update backward-incompatible updates \n $1 : Minor Update backward-compatible features \n $2 : Patch Update backward-compatible bug fixes',
frozenLockfileError: 'Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`.',
fileWriteError: 'Could not write file $0: $1',
Expand Down