/
git-add.test.js
56 lines (43 loc) · 1.95 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
"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], { 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], { 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 file = path.join(cwd, "packages", "pkg-2", "index.log");
const file2 = path.join(cwd, "packages", "pkg-2", "index.js");
await fs.outputFile(file, "hello");
await fs.outputFile(file2, "hello2");
await gitAdd([file, file2], { cwd });
const list = await execa.stdout("git", ["diff", "--cached", "--name-only"], { cwd });
expect(slash(list)).toBe("packages/pkg-2/index.js");
});
test(".gitignore without naming files", async () => {
const cwd = await initFixture("root-manifest-only");
const file = path.join(cwd, "packages", "pkg-2", "index.log");
const file2 = path.join(cwd, "packages", "pkg-2", "index.js");
await fs.outputFile(file, "hello");
await fs.outputFile(file2, "hello2");
await gitAdd([], { cwd });
const list = await execa.stdout("git", ["diff", "--cached", "--name-only"], { cwd });
expect(slash(list)).toBe("packages/pkg-2/index.js");
});