Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some tests for link/unlink command #3293

Merged
merged 3 commits into from
May 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/commands/_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export async function run<T, R>(
cwd,
globalFolder: path.join(cwd, '.yarn-global'),
cacheFolder: flags.cacheFolder || path.join(cwd, '.yarn-cache'),
linkFolder: path.join(cwd, '.yarn-link'),
linkFolder: flags.linkFolder || path.join(cwd, '.yarn-link'),
production: flags.production,
}, reporter);

Expand Down
39 changes: 39 additions & 0 deletions __tests__/commands/link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* @flow */

import {run as buildRun} from './_helpers.js';
import {run as link} from '../../src/cli/commands/link.js';
import {ConsoleReporter} from '../../src/reporters/index.js';
import type {CLIFunctionReturn} from '../../src/types.js';
import mkdir from './../_temp.js';
import * as fs from '../../src/util/fs.js';

const path = require('path');

const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'link');
const runLink = buildRun.bind(
null,
ConsoleReporter,
fixturesLoc,
(args, flags, config, reporter): CLIFunctionReturn => {
return link(config, reporter, flags, args);
},
);

test.concurrent('creates folder in linkFolder', async (): Promise<void> => {
const linkFolder = await mkdir('link-folder');
await runLink([], {linkFolder}, 'package-with-name', async (config, reporter): Promise<void> => {
const existed = await fs.exists(path.join(linkFolder, 'a-package'));
expect(existed).toEqual(true);
});
});

test.concurrent('throws error if package.json does not have name', async (): Promise<void> => {
const linkFolder = await mkdir('link-folder');
const reporter = new ConsoleReporter({});

try {
await runLink([], {linkFolder}, 'package-no-name', () => {});
} catch (err) {
expect(err.message).toContain(reporter.lang('unknownPackageName'));
}
});
55 changes: 55 additions & 0 deletions __tests__/commands/unlink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* @flow */

import {run as buildRun} from './_helpers.js';
import {run as link} from '../../src/cli/commands/link.js';
import {run as unlink} from '../../src/cli/commands/unlink.js';
import {ConsoleReporter} from '../../src/reporters/index.js';
import type {CLIFunctionReturn} from '../../src/types.js';
import mkdir from './../_temp.js';
import * as fs from '../../src/util/fs.js';

const path = require('path');

const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'link');
const runLink = buildRun.bind(
null,
ConsoleReporter,
fixturesLoc,
(args, flags, config, reporter): CLIFunctionReturn => {
return link(config, reporter, flags, args);
},
);

const runUnlink = buildRun.bind(
null,
ConsoleReporter,
fixturesLoc,
(args, flags, config, reporter): CLIFunctionReturn => {
return unlink(config, reporter, flags, args);
},
);

test.concurrent('creates folder in linkFolder', async (): Promise<void> => {
const linkFolder = await mkdir('link-folder');

await runLink([], {linkFolder}, 'package-with-name', async (config, reporter): Promise<void> => {
const existed = await fs.exists(path.join(linkFolder, 'a-package'));
expect(existed).toEqual(true);
});

await runUnlink([], {linkFolder}, 'package-with-name', async (config, reporter): Promise<void> => {
const existed = await fs.exists(path.join(linkFolder, 'a-package'));
expect(existed).toEqual(false);
});
});

test.concurrent('throws error if package.json does not have name', async (): Promise<void> => {
const linkFolder = await mkdir('link-folder');
const reporter = new ConsoleReporter({});

try {
await runUnlink([], {linkFolder}, 'package-no-name', () => {});
} catch (err) {
expect(err.message).toContain(reporter.lang('unknownPackageName'));
}
});
3 changes: 3 additions & 0 deletions __tests__/fixtures/link/package-no-name/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dependencies": {}
}
1 change: 1 addition & 0 deletions __tests__/fixtures/link/package-with-name/bar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foobar
5 changes: 5 additions & 0 deletions __tests__/fixtures/link/package-with-name/bar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "bar",
"version": "0.0.0",
"main": "index.js"
}
6 changes: 6 additions & 0 deletions __tests__/fixtures/link/package-with-name/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "a-package",
"dependencies": {
"foo": "file:bar"
}
}
4 changes: 4 additions & 0 deletions __tests__/fixtures/link/package-with-name/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"foo@file:bar":
version "0.0.0"