Files
yarn/__tests__/commands/upgrade-interactive.js
Jeff Valore f80cbb580c fix(upgrade): No longer warn when upgrading a devDependency (#5606)
* fix(upgrade): No longer warn when upgrading a devDependency

fixes #4840

**Summary**

Previously the upgrade command would call add with the list of packages
to upgrade to. No "--dev"
flag would be carried over and this list would contain all dependencies.
As a result, Add would
report a warning `{package} is already in "devDependencies". Please
remove existing entry first
before adding it to "dependencies".`

I am using the existing `config.commandName` to decide whether or not to
display the warning.

I also updated the jest snapshots, because I was tired of the warning
about 40-some obsolete snapshots, so the snapshot changes here aren't
relevant to the functionality, just cleaning up.

**Test plan**

Added regression test in `__tests__/commands/upgrade.js`.

Upgrade tests now set `config.commandName` which is an existing
property, but is not normally set by tests. I wanted to set it for all
tests in `_helpers.js` but we don't actually specify the command we are
going to test when we build a test runner.

* refactor code based on PR feedback
2018-04-05 10:42:45 +01:00

37 lines
1.3 KiB
JavaScript

/* @flow */
import {ConsoleReporter} from '../../src/reporters/index.js';
import {run as buildRun} from './_helpers.js';
import {run as upgradeInteractive} from '../../src/cli/commands/upgrade-interactive.js';
import * as reporters from '../../src/reporters/index.js';
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
const path = require('path');
const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'upgrade-interactive');
const runUpgrade = buildRun.bind(null, ConsoleReporter, fixturesLoc, (args, flags, config, reporter): Promise<void> => {
config.commandName = 'upgrade-interactive';
return upgradeInteractive(config, reporter, flags, args);
});
test.concurrent('throws if lockfile is out of date', (): Promise<void> => {
const reporter = new reporters.ConsoleReporter({});
return new Promise(async resolve => {
try {
await runUpgrade([], {}, 'lockfile-outdated');
} catch (err) {
expect(err.message).toContain(reporter.lang('lockfileOutdated'));
} finally {
resolve();
}
});
});
test.concurrent('exits with success if no upgrades', (): Promise<void> => {
const reporter = new reporters.ConsoleReporter({});
return runUpgrade([], {}, 'up-to-date', (config, rep, install, output): ?Promise<void> => {
expect(output()).toContain(reporter.lang('allDependenciesUpToDate'));
});
});