Skip to content

Commit

Permalink
test: Fix flaky tests after #4811 due to bad assumptions
Browse files Browse the repository at this point in the history
**Summary**

Tests started failing on Travis after #4811, somewhat randomly, due to the mexpecting 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.
  • Loading branch information
BYK committed Nov 3, 2017
1 parent 002ce4a commit 714171b
Show file tree
Hide file tree
Showing 47 changed files with 556 additions and 73 deletions.
548 changes: 548 additions & 0 deletions __tests__/__snapshots__/normalize-manifest.js.snap

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion __tests__/commands/install/bin-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion __tests__/fixtures/normalize-manifest/name/warnings.json

This file was deleted.

1 change: 0 additions & 1 deletion __tests__/fixtures/normalize-manifest/readme/warnings.json

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions __tests__/fixtures/normalize-manifest/warn typo/warnings.json

This file was deleted.

3 changes: 2 additions & 1 deletion __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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');
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lifecycle-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 3 additions & 12 deletions __tests__/normalize-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -16,15 +16,7 @@ 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 reporter = new BufferReporter();
const config = await Config.create({cwd: loc, globalFolder: options.globalFolder}, reporter);

let actual = await fs.readJson(path.join(loc, 'actual.json'));
Expand Down Expand Up @@ -57,7 +49,7 @@ 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')).toMatchSnapshot(loc + options.globalFolder);
}

for (const name of nativeFs.readdirSync(fixturesLoc)) {
Expand All @@ -75,7 +67,6 @@ const globalfixturesLoc = path.join(__dirname, 'fixtures', 'normalize-manifest',
test(
'license warnings should not be thrown with global commands',
_compareManifests.bind(null, globalfixturesLoc, {
expectedWarnings: [],
globalFolder: globalfixturesLoc,
}),
);
Expand Down
2 changes: 1 addition & 1 deletion src/reporters/buffer-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Buffer = Array<{
}>;

export default class BufferReporter extends JSONReporter {
constructor(opts: Object) {
constructor(opts?: Object) {
super(opts);
this._buffer = [];
}
Expand Down

0 comments on commit 714171b

Please sign in to comment.