зеркало из https://github.com/microsoft/backfill.git
add unit tests
This commit is contained in:
Родитель
55ea9eb657
Коммит
5bd2618807
|
@ -23,7 +23,8 @@
|
|||
"globby": "^11.0.0",
|
||||
"find-up": "^4.1.0",
|
||||
"find-yarn-workspace-root": "^1.2.1",
|
||||
"fs-extra": "^8.1.0"
|
||||
"fs-extra": "^8.1.0",
|
||||
"tempy": "^0.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/fs-extra": "^8.0.0",
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
import path from "path";
|
||||
import { EOL } from "os";
|
||||
import fs from "fs-extra";
|
||||
import tempy from "tempy";
|
||||
|
||||
import { getListOfGitFiles } from "../gitFiles";
|
||||
|
||||
function expectAreSame<T>(array1: T[], array2: T[]): void {
|
||||
expect(array1.length).toBe(array2.length);
|
||||
array1.forEach((value, index) => {
|
||||
expect(value).toBe(array2[index]);
|
||||
});
|
||||
}
|
||||
|
||||
describe("getFilesTrackedByGit()", () => {
|
||||
it("when packageRoot is also repo root", async () => {
|
||||
const cwd = tempy.directory();
|
||||
|
||||
// Creating very simple git repo
|
||||
await fs.mkdirp(path.join(cwd, ".git"));
|
||||
await fs.writeFile(path.join(cwd, ".gitignore"), "lib");
|
||||
await fs.writeFile(path.join(cwd, "package.json"), "");
|
||||
await fs.mkdirp(path.join(cwd, "lib"));
|
||||
await fs.mkdirp(path.join(cwd, "src"));
|
||||
await fs.writeFile(path.join(cwd, "src", "index.ts"), "");
|
||||
await fs.writeFile(path.join(cwd, "lib", "index.js"), "");
|
||||
|
||||
const files = await getListOfGitFiles(cwd);
|
||||
|
||||
const expectedFiles = ["package.json", path.join("src", "index.ts")];
|
||||
|
||||
expectAreSame(files, expectedFiles);
|
||||
});
|
||||
it("when packageRoot is not repo root", async () => {
|
||||
const repoRoot = tempy.directory();
|
||||
const packageRoot = path.join(repoRoot, "packages", "foo");
|
||||
|
||||
// Creating git repo
|
||||
await fs.mkdirp(path.join(repoRoot, ".git"));
|
||||
await fs.writeFile(path.join(repoRoot, ".gitignore"), "lib");
|
||||
await fs.writeFile(path.join(repoRoot, "package.json"), "");
|
||||
|
||||
await fs.mkdirp(packageRoot);
|
||||
await fs.writeFile(
|
||||
path.join(packageRoot, ".gitignore"),
|
||||
`!lib${EOL}lib/*${EOL}!lib/index.d.ts`
|
||||
);
|
||||
await fs.writeFile(path.join(packageRoot, "package.json"), "");
|
||||
|
||||
await fs.mkdirp(path.join(packageRoot, "lib"));
|
||||
await fs.mkdirp(path.join(packageRoot, "src"));
|
||||
await fs.writeFile(path.join(packageRoot, "src", "index.ts"), "");
|
||||
await fs.writeFile(path.join(packageRoot, "lib", "index.js"), "");
|
||||
await fs.writeFile(path.join(packageRoot, "lib", "index.d.ts"), "");
|
||||
|
||||
const files = await getListOfGitFiles(packageRoot);
|
||||
|
||||
const expectedFiles = [
|
||||
path.join("lib", "index.d.ts"),
|
||||
"package.json",
|
||||
path.join("src", "index.ts")
|
||||
];
|
||||
|
||||
console.log(files);
|
||||
|
||||
expectAreSame(files, expectedFiles);
|
||||
});
|
||||
});
|
Загрузка…
Ссылка в новой задаче