Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions __tests__/commands/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ test.concurrent('--verify-tree should report wrong version', async (): Promise<v
expect(thrown).toEqual(true);
});

test.concurrent('--verify-tree should work from a workspace cwd', async (): Promise<void> => {
Copy link
Contributor Author

@bdwain bdwain Apr 24, 2018

Choose a reason for hiding this comment

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

i made the change in check.js so that this test would pass. I needed it to work correctly for the new focus tests to work (or I could have avoided the check at the end of the install and be different from other install tests, but that felt wrong)

let thrown = false;
try {
await runCheck([], {verifyTree: true}, {source: 'verify-tree-workspace-cwd', cwd: '/packages/workspace-1'});
} catch (e) {
thrown = true;
}
expect(thrown).toEqual(false);
});

test.concurrent('--verify-tree should report missing dependency', async (): Promise<void> => {
let thrown = false;
try {
Expand Down
17 changes: 17 additions & 0 deletions __tests__/commands/install/bin-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,20 @@ describe('with nohoist', () => {
});
});
});

describe('with focus', () => {
test('focus points bin links to the shallowly installed packages', (): Promise<void> => {
return runInstall(
{binLinks: true, focus: true},
{source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-1'},
async (config): Promise<void> => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', '.bin', 'example-yarn-workspace-2'))).toEqual(
true,
);
expect(await linkAt(config, 'node_modules', '.bin', 'example-yarn-workspace-2')).toEqual(
'../example-yarn-workspace-2/index.js',
);
},
);
});
});
261 changes: 261 additions & 0 deletions __tests__/commands/install/focus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
/* @flow */

import * as reporters from '../../../src/reporters/index.js';
import * as fs from '../../../src/util/fs.js';
import {runInstall} from '../_helpers.js';
import {Install} from '../../../src/cli/commands/install.js';
import Lockfile from '../../../src/lockfile';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;

const path = require('path');

test.concurrent('focus does not work from a non-workspaces project', async (): Promise<void> => {
let error = '';
const reporter = new reporters.ConsoleReporter({});
try {
await runInstall({focus: true}, 'install-production');
} catch (e) {
error = e.message;
}
expect(error).toContain(reporter.lang('workspacesFocusRootCheck'));
});

test.concurrent('focus does not work from the root of a workspaces project', async (): Promise<void> => {
let error = '';
const reporter = new reporters.ConsoleReporter({});
try {
await runInstall({focus: true}, 'published-monorepo');
} catch (e) {
error = e.message;
}
expect(error).toContain(reporter.lang('workspacesFocusRootCheck'));
});

test.concurrent('focus does a normal workspace installation', (): Promise<void> => {
return runInstall(
{focus: true},
{source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-1'},
async (config): Promise<void> => {
const packageFile = await fs.readFile(
path.join(config.cwd, '..', '..', 'node_modules', 'example-yarn-workspace-2', 'package.json'),
);
expect(JSON.parse(packageFile).version).toEqual('1.1.1');
const readme = await fs.readFile(
path.join(config.cwd, '..', '..', 'node_modules', 'example-yarn-workspace-2', 'README.md'),
);
expect(readme.split('\n')[0]).toEqual('WORKSPACES ROCK2!');
},
);
});

test.concurrent('focus shallowly installs sibling workspaces under target', (): Promise<void> => {
return runInstall(
{focus: true},
{source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-1'},
async (config): Promise<void> => {
const packageFile = await fs.readFile(
path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2', 'package.json'),
);
expect(JSON.parse(packageFile).version).toEqual('1.1.1');
const readme = await fs.readFile(path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2', 'README.md'));
expect(readme.split('\n')[0]).toEqual('WORKSPACES ROCK2!');
},
);
});

test.concurrent('focus should not bail out early after an un-focused install', (): Promise<void> => {
return runInstall({}, 'published-monorepo', async (config, reporter) => {
const oldCwd = config.cwd;

await fs.writeFile(path.join(oldCwd, 'node_modules', 'yarn.test'), 'YARN TEST');

config.cwd += '/packages/example-yarn-workspace-1';

const reinstall = new Install({focus: true}, config, reporter, await Lockfile.fromDirectory(oldCwd));
await reinstall.init();

expect(await fs.exists(path.join(oldCwd, 'node_modules', 'yarn.test'))).toBeFalsy();
});
});

test.concurrent('repeated focused installs should bail out early', (): Promise<void> => {
return runInstall(
{focus: true},
{source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-1'},
async (config, reporter) => {
await fs.writeFile(path.join(config.cwd, 'node_modules', 'yarn.test'), 'YARN TEST');

const lockfileDir = path.join(config.cwd, '..', '..');

const reinstall = new Install({focus: true}, config, reporter, await Lockfile.fromDirectory(lockfileDir));
await reinstall.init();

expect(await fs.exists(path.join(config.cwd, 'node_modules', 'yarn.test'))).toBeTruthy();

await fs.unlink(path.join(config.cwd, 'node_modules', 'yarn.test'));
},
);
});

test.concurrent('switching directories for focused installs should fail integrity checks and reinstall', (): Promise<
void,
> => {
return runInstall(
{focus: true},
{source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-1'},
async (config, reporter) => {
const rootDir = path.join(config.cwd, '..', '..');

await fs.writeFile(path.join(rootDir, 'node_modules', 'yarn.test'), 'YARN TEST');

config.cwd = path.join(rootDir, 'packages', 'example-yarn-workspace-2');

const reinstall = new Install({focus: true}, config, reporter, await Lockfile.fromDirectory(rootDir));
await reinstall.init();

expect(await fs.exists(path.join(rootDir, 'node_modules', 'yarn.test'))).toBeFalsy();
},
);
});

test.concurrent(
'focus shallowly installs anything that a sibling needed to shallowly install underneath that sibling',
(): Promise<void> => {
return runInstall(
{focus: true},
{source: 'focus-conflicts', cwd: '/packages/example-yarn-workspace-1'},
async (config, reporter) => {
const packageFile = await fs.readFile(
path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2', 'node_modules', 'left-pad', 'package.json'),
);
expect(JSON.parse(packageFile).version).toEqual('1.1.2');
},
);
},
);

test.concurrent("focus does not shallowly install a sibling's dev dependencies", (): Promise<void> => {
return runInstall(
{focus: true},
{source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-4'},
async (config, reporter) => {
expect(
await fs.exists(path.join(config.cwd, 'node_modules', 'example-yarn-workspace-3', 'node_modules', 'left-pad')),
).toBeFalsy();
},
);
});

test.concurrent("focus runs shallow dependencies' postinstall scripts", (): Promise<void> => {
return runInstall(
{focus: true},
{source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-4'},
async (config, reporter) => {
expect(
await fs.exists(path.join(config.cwd, 'node_modules', 'example-yarn-workspace-3', 'temp.out')),
).toBeTruthy();
},
);
});

test.concurrent('focus installs transitive dependencies shallowly', (): Promise<void> => {
return runInstall(
{focus: true},
{source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-4'},
async (config, reporter) => {
expect(
await fs.exists(path.join(config.cwd, 'node_modules', 'example-yarn-workspace-1', 'package.json')),
).toBeTruthy();
},
);
});

test.concurrent(
'focus does not install transitive devdependencies shallowly (but does install non-transitive devdeps)',
(): Promise<void> => {
return runInstall(
{focus: true},
{source: 'published-monorepo', cwd: '/packages/example-yarn-workspace-6'},
async (config, reporter) => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'example-yarn-workspace-5'))).toBeTruthy();
expect(
await fs.exists(
path.join(
config.cwd,
'node_modules',
'example-yarn-workspace-5',
'node_modules',
'example-yarn-workspace-2',
),
),
).toBeFalsy();
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2'))).toBeFalsy();
},
);
},
);

test.concurrent(
'focus does not shallowly install current version of sibling if another version is specified in package.json',
(): Promise<void> => {
return runInstall(
{focus: true},
{source: 'focus-different-versions', cwd: '/packages/example-yarn-workspace-1'},
async (config, reporter) => {
const packageFile = await fs.readFile(
path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2', 'package.json'),
);
expect(JSON.parse(packageFile).version).toEqual('1.0.1');
},
);
},
);

describe('nohoist', () => {
test.concurrent('focus installs nohoist dependencies shallowly', (): Promise<void> => {
return runInstall(
{focus: true},
{source: 'focus-nohoist', cwd: '/packages/example-yarn-workspace-1'},
async (config, reporter) => {
const moduleDir = path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2');
expect(await fs.exists(path.join(moduleDir, 'package.json'))).toBeTruthy();
const stat = await fs.lstat(moduleDir);
expect(stat.isSymbolicLink()).toEqual(false);
},
);
});

test.concurrent('focus does not do nested shallow installs of transitive nohoist packages', (): Promise<void> => {
return runInstall(
{focus: true},
{source: 'focus-nohoist', cwd: '/packages/example-yarn-workspace-3'},
async (config, reporter) => {
const moduleDir = path.join(
config.cwd,
'node_modules',
'example-yarn-workspace-1',
'node_modules',
'example-yarn-workspace-2',
);
expect(await fs.exists(path.join(moduleDir, 'package.json'))).toBeFalsy();
},
);
});

test.concurrent(
'focus installs the correct version when a package is nohoist but differs from the workspace version',
(): Promise<void> => {
return runInstall(
{focus: true},
{source: 'focus-nohoist-different-versions', cwd: '/packages/example-yarn-workspace-6'},
async (config, reporter) => {
const packageFile = await fs.readFile(
path.join(config.cwd, 'node_modules', 'example-yarn-workspace-2', 'package.json'),
);
expect(JSON.parse(packageFile).version).toEqual('1.0.0');
},
);
},
);
});
2 changes: 1 addition & 1 deletion __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ test('changes the cache directory when bumping the cache version', async () => {
await resolver.init([{pattern: 'is-array', registry: 'npm'}]);

const ref = resolver.getManifests()[0]._reference;
const cachePath = config.generateHardModulePath(ref, true);
const cachePath = config.generateModuleCachePath(ref);

await fs.writeFile(path.join(cachePath, 'yarn.test'), 'YARN TEST');
await fs.unlink(path.join(config.cwd, 'node_modules'));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "my-project",
"private": true,
"workspaces": [
"packages/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "left-pad",
"version": "1.1.2",
"description": "String left pad",
"main": "index.js",
"scripts": {
"test": "node test",
"bench": "node perf/perf.js"
},
"keywords": [
"leftpad",
"left",
"pad",
"padding",
"string",
"repeat"
],
"repository": {
"url": "git@github.com:stevemao/left-pad.git",
"type": "git"
},
"author": "azer",
"maintainers": [
{
"name": "Cameron Westland",
"email": "camwest@gmail.com"
}
],
"license": "WTFPL"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "workspace-1",
"version": "1.0.0",
"dependencies": {
"left-pad": "1.1.2"
}
}
7 changes: 7 additions & 0 deletions __tests__/fixtures/install/focus-conflicts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "monorepo",
"private": true,
"workspaces": [
"packages/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WORKSPACES ROCK!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('p1');
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "example-yarn-workspace-1",
"version": "1.0.1",
"dependencies": {
"example-yarn-workspace-2": "^1.0.0",
"left-pad": "1.1.3"
},
"main": "index.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WORKSPACES ROCK2!
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

console.log('hey');
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "example-yarn-workspace-2",
"version": "1.1.1",
"bin": "index.js",
"dependencies": {
"left-pad": "1.1.2"
},
"main": "index.js"
}
Loading