Repository navigation
Expand file tree
/
Copy pathLinkCommand.js
More file actions
67 lines (52 loc) · 1.82 KB
/
Copy pathLinkCommand.js
File metadata and controls
67 lines (52 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import log from "npmlog";
// mocked or stubbed modules
import FileSystemUtilities from "../src/FileSystemUtilities";
// helpers
import callsBack from "./helpers/callsBack";
import initFixture from "./helpers/initFixture";
import normalizeRelativeDir from "./helpers/normalizeRelativeDir";
import yargsRunner from "./helpers/yargsRunner";
// file under test
import * as commandModule from "../src/commands/LinkCommand";
const run = yargsRunner(commandModule);
// silence logs
log.level = "silent";
// stub symlink in certain tests to reduce redundancy
const fsSymlink = FileSystemUtilities.symlink;
const resetSymlink = () => {
FileSystemUtilities.symlink = fsSymlink;
};
const stubSymlink = () => {
FileSystemUtilities.symlink = jest.fn(callsBack());
};
// object snapshots have sorted keys
const symlinkedDirectories = testDir =>
FileSystemUtilities.symlink.mock.calls.map(args => ({
_src: normalizeRelativeDir(testDir, args[0]),
dest: normalizeRelativeDir(testDir, args[1]),
type: args[2],
}));
describe("LinkCommand", () => {
beforeEach(() => {});
afterEach(() => jest.resetAllMocks());
describe("with local package dependencies", () => {
beforeEach(stubSymlink);
afterEach(resetSymlink);
it("should symlink all packages", async () => {
const testDir = await initFixture("LinkCommand/basic");
const lernaLink = run(testDir);
await lernaLink();
expect(symlinkedDirectories(testDir)).toMatchSnapshot();
});
});
describe("with --force-local", () => {
beforeEach(stubSymlink);
afterEach(resetSymlink);
it("should force symlink of all packages", async () => {
const testDir = await initFixture("LinkCommand/force-local");
const lernaLink = run(testDir);
await lernaLink();
expect(symlinkedDirectories(testDir)).toMatchSnapshot();
});
});
});