Skip to content

Commit

Permalink
latest version of yarn master merged with cyan color of powershell
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Dec 7, 2017
1 parent 63d1d0d commit 40210b6
Show file tree
Hide file tree
Showing 51 changed files with 992 additions and 24 deletions.
63 changes: 63 additions & 0 deletions __tests__/commands/__snapshots__/run.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`returns noBinAvailable with no bins 1`] = `
Array [
Object {
"data": "No command specified.",
"error": true,
"type": "error",
},
Object {
"data": "There are no binary scripts available.",
"error": true,
"type": "error",
},
Object {
"data": "Project commands",
"error": false,
"type": "info",
},
Object {
"data": Object {
"hints": Object {
"build": "echo 'building'",
"prestart": "echo 'prestart'",
"start": "node index.js",
},
"items": Array [
"build",
"prestart",
"start",
],
"type": "possibleCommands",
},
"error": false,
"type": "list",
},
Object {
"data": "No command specified.",
"error": true,
"type": "error",
},
]
`;

exports[`returns noScriptsAvailable with no scripts 1`] = `
Array [
Object {
"data": "No command specified.",
"error": true,
"type": "error",
},
Object {
"data": "Commands available from binary scripts: cat-names",
"error": false,
"type": "info",
},
Object {
"data": "There are no scripts specified inside package.json.",
"error": true,
"type": "error",
},
]
`;
31 changes: 31 additions & 0 deletions __tests__/commands/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ test.concurrent('install with --optional flag', (): Promise<void> => {
});
});

test.concurrent('install with --tilde flag', (): Promise<void> => {
return runAdd(['[email protected]'], {tilde: true}, 'add-with-flag', async config => {
const lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock')));
const pkg = await fs.readJson(path.join(config.cwd, 'package.json'));

expect(lockfile.indexOf('isarray@~2.0.1:')).toEqual(0);
expect(pkg.dependencies).toEqual({isarray: '~2.0.1'});
});
});

// Test if moduleAlreadyInManifest warning is displayed
const moduleAlreadyInManifestChecker = ({expectWarnings}: {expectWarnings: boolean}) => async (
args,
Expand Down Expand Up @@ -609,6 +619,27 @@ test.concurrent('upgrade scenario 2 (with sub dependencies)', (): Promise<void>
});
});

test.concurrent('install another fork of an existing package', (): Promise<void> => {
// When installing a package with the same name as an existing one but from a different repo,
// the old one should be replaced with the new one in the lock file.
const firstSource = 'davidreis97/example-yarn-package#master';
const secondSource = 'yarnpkg/example-yarn-package#master';
const pkgName = 'example-yarn-package';
return runAdd([firstSource], {}, 'install-forked-git', async (config, reporter): Promise<void> => {
let lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock')));
expect(lockfile.indexOf(`${pkgName}@${firstSource}:`)).toEqual(0);
expect(lockfile.indexOf(`${pkgName}@${secondSource}:`)).toEqual(-1);

const add = new Add([secondSource], {}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await add.init();

lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock')));

expect(lockfile.indexOf(`${pkgName}@${firstSource}:`)).toEqual(-1);
expect(lockfile.indexOf(`${pkgName}@${secondSource}:`)).toEqual(0);
});
});

test.concurrent('downgrade scenario', (): Promise<void> => {
// left-pad first installed 1.1.0 then downgraded to 0.0.9
// files in mirror, yarn.lock, package.json and node_modules should reflect that
Expand Down
18 changes: 18 additions & 0 deletions __tests__/commands/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,24 @@ test.concurrent('should ignore bundled dependencies', async (): Promise<void> =>
);
});

test.concurrent('should warn about mismatched dependencies if they match resolutions', async (): Promise<void> => {
let mismatchError = false;
let stdout = '';
try {
await runCheck([], {}, 'resolutions', (config, reporter, check, getStdout) => {
stdout = getStdout();
});
} catch (err) {
mismatchError = true;
}
expect(mismatchError).toEqual(false);
expect(
stdout.search(
`warning.*"[email protected]" is incompatible with requested version "pad-left#repeat-string@\\^1.5.4"`,
),
).toBeGreaterThan(-1);
});

test.concurrent('--integrity should throw an error if top level patterns do not match', async (): Promise<void> => {
let integrityError = false;
try {
Expand Down
12 changes: 12 additions & 0 deletions __tests__/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,15 @@ test.skip('pack should include bundled dependencies', (): Promise<void> => {
expect(files.sort()).toEqual(expected.sort());
});
});

test.concurrent('pack should match dotfiles with globs', (): Promise<void> => {
return runPack([], {}, 'glob-dotfile', async (config): Promise<void> => {
const {cwd} = config;
const files = await getFilesFromArchive(
path.join(cwd, 'glob-dotfile-v1.0.0.tgz'),
path.join(cwd, 'glob-dotfile-v1.0.0'),
);
const expected = ['index.js', 'package.json', 'dir', path.join('dir', '.dotfile')];
expect(files.sort()).toEqual(expected.sort());
});
});
34 changes: 34 additions & 0 deletions __tests__/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'run');
const runRun = buildRun.bind(null, BufferReporter, fixturesLoc, (args, flags, config, reporter): Promise<void> => {
return run(config, reporter, flags, args);
});
const runRunInWorkspacePackage = function(cwd, ...args): Promise<void> {
return buildRun.bind(null, BufferReporter, fixturesLoc, (args, flags, config, reporter): Promise<void> => {
const originalCwd = config.cwd;
config.cwd = path.join(originalCwd, cwd);
const retVal = run(config, reporter, flags, args);
retVal.then(() => {
config.cwd = originalCwd;
});
return retVal;
})(...args);
};

test('lists all available commands with no arguments', (): Promise<void> => {
return runRun([], {}, 'no-args', (config, reporter): ?Promise<void> => {
Expand Down Expand Up @@ -133,3 +144,26 @@ test('adds quotes if args have spaces and quotes', (): Promise<void> => {
expect(execCommand).toBeCalledWith(...args);
});
});

test('returns noScriptsAvailable with no scripts', (): Promise<void> => {
return runRun([], {}, 'no-scripts', (config, reporter) => {
expect(reporter.getBuffer()).toMatchSnapshot();
});
});

test('returns noBinAvailable with no bins', (): Promise<void> => {
return runRun([], {}, 'no-bin', (config, reporter) => {
expect(reporter.getBuffer()).toMatchSnapshot();
});
});

test('adds workspace root node_modules/.bin to path when in a workspace', (): Promise<void> => {
return runRunInWorkspacePackage('packages/pkg1', ['env'], {}, 'workspace', (config, reporter): ?Promise<void> => {
const logEntry = reporter.getBuffer().find(entry => entry.type === 'log');
const parsedLogData = JSON.parse(logEntry ? logEntry.data.toString() : '{}');
const envPaths = (parsedLogData.PATH || parsedLogData.Path).split(path.delimiter);

expect(envPaths).toContain(path.join(config.cwd, 'node_modules', '.bin'));
expect(envPaths).toContain(path.join(config.cwd, 'packages', 'pkg1', 'node_modules', '.bin'));
});
});
6 changes: 6 additions & 0 deletions __tests__/fixtures/add/install-forked-git/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "install-forked-git",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
}
18 changes: 18 additions & 0 deletions __tests__/fixtures/check/resolutions/node_modules/.yarn-integrity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions __tests__/fixtures/check/resolutions/node_modules/pad-left/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

134 changes: 134 additions & 0 deletions __tests__/fixtures/check/resolutions/node_modules/pad-left/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 40210b6

Please sign in to comment.