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 3 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,9 +143,12 @@ 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');
});
});
7 changes: 6 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 body = deps.map((info): Array<string> => {
Expand All @@ -44,6 +44,11 @@ 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('legendColorsForOutdated', red, yellow, green));

reporter.table(['Package', 'Current', 'Wanted', 'Latest', 'Package Type', 'URL'], body);
return 1;
}
Expand Down
2 changes: 2 additions & 0 deletions src/reporters/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ const messages = {
allDependenciesUpToDate: 'All of your dependencies are up to date.',
legendColorsForUpgradeInteractive:
'Color legend : \n $0 : Major Update backward-incompatible updates \n $1 : Minor Update backward-compatible features \n $2 : Patch Update backward-compatible bug fixes',
legendColorsForOutdated:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as legendColorsForUpgradeInteractive should I merge them? If yes what to name them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I'd prefer merging them. How about legendColorsForVersionUpdates?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay changed :)

'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',
multiplePackagesCantUnpackInSameDestination:
Expand Down