/
git-add.test.js
64 lines (49 loc) · 2.31 KB
/
git-add.test.js
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
"use strict";
const execa = require("execa");
const fs = require("fs-extra");
const path = require("path");
const slash = require("slash");
const initFixture = require("@lerna-test/init-fixture")(__dirname);
const gitAdd = require("../lib/git-add");
test("relative files", async () => {
const cwd = await initFixture("root-manifest-only");
const file = path.join("packages", "pkg-1", "index.js");
await fs.outputFile(path.join(cwd, file), "hello");
await gitAdd([file], { granularPathspec: true }, { cwd });
const list = await execa.stdout("git", ["diff", "--cached", "--name-only"], { cwd });
expect(slash(list)).toBe("packages/pkg-1/index.js");
});
test("absolute files", async () => {
const cwd = await initFixture("root-manifest-only");
const file = path.join(cwd, "packages", "pkg-2", "index.js");
await fs.outputFile(file, "hello");
await gitAdd([file], { granularPathspec: true }, { cwd });
const list = await execa.stdout("git", ["diff", "--cached", "--name-only"], { cwd });
expect(slash(list)).toBe("packages/pkg-2/index.js");
});
test(".gitignore", async () => {
const cwd = await initFixture("root-manifest-only");
const file3 = path.join(cwd, "packages/version-3/package.json");
const file4 = path.join(cwd, "packages/dynamic-4/package.json");
await Promise.all([
// a "dynamic" package is intentionally unversioned, yet still published
fs.outputJSON(file3, { three: true }),
fs.outputJSON(file4, { four: true }),
]);
await gitAdd([file3, file4], { granularPathspec: false }, { cwd });
const list = await execa.stdout("git", ["diff", "--cached", "--name-only"], { cwd });
expect(slash(list)).toBe("packages/version-3/package.json");
});
test(".gitignore without naming files", async () => {
const cwd = await initFixture("root-manifest-only");
const file5 = path.join(cwd, "packages/version-5/package.json");
const file6 = path.join(cwd, "packages/dynamic-6/package.json");
await Promise.all([
// a "dynamic" package is intentionally unversioned, yet still published
fs.outputJSON(file5, { five: true }),
fs.outputJSON(file6, { six: true }),
]);
await gitAdd([], { granularPathspec: false }, { cwd });
const list = await execa.stdout("git", ["diff", "--cached", "--name-only"], { cwd });
expect(slash(list)).toBe("packages/version-5/package.json");
});