/
git-checkout.test.js
34 lines (26 loc) · 1.37 KB
/
git-checkout.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
"use strict";
const execa = require("execa");
const fs = require("fs-extra");
const path = require("path");
const initFixture = require("@lerna-test/init-fixture")(__dirname);
const gitCheckout = require("../lib/git-checkout");
test("gitCheckout files", async () => {
const cwd = await initFixture("no-interdependencies");
const files = ["package-1", "package-2"].map(name => path.join("packages", name, "package.json"));
await Promise.all(files.map(fp => fs.writeJSON(path.join(cwd, fp), { foo: "bar" })));
await gitCheckout(files, { granularPathspec: true }, { cwd });
const modified = await execa.stdout("git", ["ls-files", "--modified"], { cwd });
expect(modified).toBe("");
});
test("gitCheckout files with .gitignored files", async () => {
const cwd = await initFixture("no-interdependencies");
const files = ["package-1", "package-2", "package-3"].map(name =>
path.join("packages", name, "package.json")
);
// simulate a "dynamic", intentionally unversioned package by gitignoring it
await fs.writeFile(path.join(cwd, ".gitignore"), "packages/package-3/*", "utf8");
await Promise.all(files.map(fp => fs.outputJSON(path.join(cwd, fp), { foo: "bar" })));
await gitCheckout(files, { granularPathspec: false }, { cwd });
const modified = await execa.stdout("git", ["ls-files", "--others"], { cwd });
expect(modified).toBe("packages/package-3/package.json");
});