mirror of
https://github.com/zhigang1992/yarn.git
synced 2026-04-29 09:45:02 +08:00
**Summary** Tests started failing on Travis after #4811, somewhat randomly, due to them expecting the unwrapped output. This PR fixes those expectations and moves normalize-manifest tests to snapshots since that's easier than updating 40+ JSON files by hand. **Test plan** Tests should pass on all platforms and CI and locally.
This commit is contained in:
211
__tests__/__snapshots__/normalize-manifest.js.snap
Normal file
211
__tests__/__snapshots__/normalize-manifest.js.snap
Normal file
@@ -0,0 +1,211 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`author object normalize 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`author string 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`authors file to contributors 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`bin string 1`] = `
|
||||
Array [
|
||||
"foo: No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`binding.gyp scripts.install 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`bugs string 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`bundledDependencies alias 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`clean version 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`clean version with v 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`contributors array expand 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`dedupe all trivial dependencies 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`dedupe dependencies 1`] = `Array []`;
|
||||
|
||||
exports[`dedupe dependencies root 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
"\\"dependencies\\" has dependency \\"foobar\\" with range \\"2.0.0\\" that collides with a dependency in \\"devDependencies\\" of the same name with version \\"1.0.0\\"",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`dedupe optionalDependencies 1`] = `Array []`;
|
||||
|
||||
exports[`dedupe optionalDependencies root 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
"\\"optionalDependencies\\" has dependency \\"foobar\\" with range \\"1.0.0\\" that collides with a dependency in \\"dependencies\\" of the same name with version \\"2.0.0\\"",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`dedupe single trivial dependency 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`engines array 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`explode directories.bin 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`explode directories.man 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`extract description 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`homepage string 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`hosted git repository url 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`keywords string 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`license warnings should not be thrown with global commands 1`] = `Array []`;
|
||||
|
||||
exports[`maintainers array expand 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`man string 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`name 1`] = `
|
||||
Array [
|
||||
"foobar: No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`readme 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`repository string 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`scoped bin string 1`] = `
|
||||
Array [
|
||||
"@scope/foo: No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`server scripts.start 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`valid license 1`] = `Array []`;
|
||||
|
||||
exports[`version 1`] = `
|
||||
Array [
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`warn builtin module collision 1`] = `
|
||||
Array [
|
||||
"fs: \\"fs\\" is also the name of a node core module",
|
||||
"fs: No license field",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`warn empty string invalid license 1`] = `
|
||||
Array [
|
||||
"License should be a valid SPDX license expression",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`warn invalid license 1`] = `
|
||||
Array [
|
||||
"License should be a valid SPDX license expression",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`warn typo 1`] = `
|
||||
Array [
|
||||
"Potential typo \\"dependancies\\", did you mean \\"dependencies\\"?",
|
||||
"No license field",
|
||||
]
|
||||
`;
|
||||
@@ -31,7 +31,7 @@ function execCommand(cwd: string, binPath: Array<string>, args: Array<string>):
|
||||
cwd,
|
||||
env: {
|
||||
...process.env,
|
||||
YARN_SILENT: 0,
|
||||
YARN_WRAP_OUTPUT: 1,
|
||||
},
|
||||
},
|
||||
(error, stdout) => {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["foo: No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1,3 +0,0 @@
|
||||
[
|
||||
"No license field"
|
||||
]
|
||||
@@ -1,4 +0,0 @@
|
||||
[
|
||||
"No license field",
|
||||
"\"dependencies\" has dependency \"foobar\" with range \"2.0.0\" that collides with a dependency in \"devDependencies\" of the same name with version \"1.0.0\""
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
[]
|
||||
@@ -1,4 +0,0 @@
|
||||
[
|
||||
"No license field",
|
||||
"\"optionalDependencies\" has dependency \"foobar\" with range \"1.0.0\" that collides with a dependency in \"dependencies\" of the same name with version \"2.0.0\""
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
[]
|
||||
@@ -1,3 +0,0 @@
|
||||
[
|
||||
"No license field"
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["foobar: No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["@scope/foo: No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["foo%bar: No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
[]
|
||||
@@ -1 +0,0 @@
|
||||
[".foobar: No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
["foo$bar: No license field"]
|
||||
@@ -1 +0,0 @@
|
||||
[]
|
||||
@@ -1 +0,0 @@
|
||||
["No license field"]
|
||||
@@ -1,4 +0,0 @@
|
||||
[
|
||||
"fs: \"fs\" is also the name of a node core module",
|
||||
"fs: No license field"
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
["License should be a valid SPDX license expression"]
|
||||
@@ -1 +0,0 @@
|
||||
["License should be a valid SPDX license expression"]
|
||||
@@ -1,4 +0,0 @@
|
||||
[
|
||||
"Potential typo \"dependancies\", did you mean \"dependencies\"?",
|
||||
"No license field"
|
||||
]
|
||||
@@ -34,6 +34,7 @@ async function execCommand(
|
||||
return new Promise((resolve, reject) => {
|
||||
const cleanedEnv = {...process.env};
|
||||
cleanedEnv['YARN_SILENT'] = 0;
|
||||
cleanedEnv['YARN_WRAP_OUTPUT'] = 1;
|
||||
delete cleanedEnv['FORCE_COLOR'];
|
||||
|
||||
exec(
|
||||
@@ -121,7 +122,7 @@ test.concurrent('should add package with no-lockfile option', async () => {
|
||||
expectAddSuccessfullOutputWithNoLockFile(stdout, 'repeating');
|
||||
});
|
||||
|
||||
test.concurrent('should add package with frozzen-lockfile option', async () => {
|
||||
test.concurrent('should add package with frozen-lockfile option', async () => {
|
||||
const stdout = await execCommand('add', ['repeating', '--frozen-lockfile'], 'run-add-option', true);
|
||||
expectAddSuccessfullOutputWithNoLockFile(stdout, 'repeating');
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ async function execCommand(cmd: string, packageName: string, env = process.env):
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const cleanedEnv = {...env};
|
||||
cleanedEnv['YARN_SILENT'] = 0;
|
||||
cleanedEnv['YARN_WRAP_OUTPUT'] = 1;
|
||||
delete cleanedEnv['FORCE_COLOR'];
|
||||
|
||||
exec(
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import normalizeManifest from '../src/util/normalize-manifest/index.js';
|
||||
import NoopReporter from '../src/reporters/base-reporter.js';
|
||||
import {BufferReporter} from '../src/reporters/index.js';
|
||||
import Config from '../src/config.js';
|
||||
import map from '../src/util/map.js';
|
||||
import * as util from '../src/util/normalize-manifest/util.js';
|
||||
@@ -15,17 +15,9 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
|
||||
|
||||
const fixturesLoc = path.join(__dirname, 'fixtures', 'normalize-manifest');
|
||||
|
||||
async function _compareManifests(loc, options = {}): Promise<void> {
|
||||
const actualWarnings = [];
|
||||
const expectedWarnings = options.expectedWarnings || (await fs.readJson(path.join(loc, 'warnings.json')));
|
||||
const reporter = new NoopReporter();
|
||||
|
||||
// $FlowFixMe: Investigate
|
||||
reporter.warn = function(msg) {
|
||||
actualWarnings.push(msg);
|
||||
};
|
||||
|
||||
const config = await Config.create({cwd: loc, globalFolder: options.globalFolder}, reporter);
|
||||
async function _compareManifests(name, loc, {globalFolder} = {}): Promise<void> {
|
||||
const reporter = new BufferReporter();
|
||||
const config = await Config.create({cwd: loc, globalFolder}, reporter);
|
||||
|
||||
let actual = await fs.readJson(path.join(loc, 'actual.json'));
|
||||
const expected = await fs.readJson(path.join(loc, 'expected.json'));
|
||||
@@ -57,7 +49,9 @@ async function _compareManifests(loc, options = {}): Promise<void> {
|
||||
}
|
||||
|
||||
expect(map(actual)).toEqual(expand(expected));
|
||||
expect(actualWarnings).toEqual(expectedWarnings);
|
||||
expect(
|
||||
reporter.getBuffer().filter(d => d.type === 'warning').map(d => String(d.data).replace(/\\/g, '/')),
|
||||
).toMatchSnapshot(name);
|
||||
}
|
||||
|
||||
for (const name of nativeFs.readdirSync(fixturesLoc)) {
|
||||
@@ -67,18 +61,13 @@ for (const name of nativeFs.readdirSync(fixturesLoc)) {
|
||||
|
||||
const loc = path.join(fixturesLoc, name);
|
||||
|
||||
test(name, _compareManifests.bind(null, loc));
|
||||
test(name, () => _compareManifests(name, loc));
|
||||
}
|
||||
|
||||
const globalfixturesLoc = path.join(__dirname, 'fixtures', 'normalize-manifest', 'name');
|
||||
const globalFolder = path.join(__dirname, 'fixtures', 'normalize-manifest', 'name');
|
||||
|
||||
test(
|
||||
'license warnings should not be thrown with global commands',
|
||||
_compareManifests.bind(null, globalfixturesLoc, {
|
||||
expectedWarnings: [],
|
||||
globalFolder: globalfixturesLoc,
|
||||
}),
|
||||
);
|
||||
test('license warnings should not be thrown with global commands', () =>
|
||||
_compareManifests('license warnings should not be thrown with global commands', globalFolder, {globalFolder}));
|
||||
|
||||
test('util.stringifyPerson', () => {
|
||||
expect(util.stringifyPerson({name: 'Sebastian McKenzie'})).toEqual('Sebastian McKenzie');
|
||||
|
||||
@@ -9,7 +9,7 @@ type Buffer = Array<{
|
||||
}>;
|
||||
|
||||
export default class BufferReporter extends JSONReporter {
|
||||
constructor(opts: Object) {
|
||||
constructor(opts?: Object) {
|
||||
super(opts);
|
||||
this._buffer = [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user