Skip to content

Commit b98ae6c

Browse files
committed
Add overlay-database-utils tests
1 parent 9825184 commit b98ae6c

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed

lib/overlay-database-utils.test.js

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/overlay-database-utils.test.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/overlay-database-utils.test.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
4+
import test from "ava";
5+
import * as sinon from "sinon";
6+
7+
import * as actionsUtil from "./actions-util";
8+
import * as gitUtils from "./git-utils";
9+
import { getRunnerLogger } from "./logging";
10+
import {
11+
writeBaseDatabaseOidsFile,
12+
writeOverlayChangesFile,
13+
} from "./overlay-database-utils";
14+
import { createTestConfig, setupTests } from "./testing-utils";
15+
import { withTmpDir } from "./util";
16+
17+
setupTests(test);
18+
19+
test("writeOverlayChangesFile generates correct changes file", async (t) => {
20+
await withTmpDir(async (tmpDir) => {
21+
const dbLocation = path.join(tmpDir, "db");
22+
await fs.promises.mkdir(dbLocation, { recursive: true });
23+
const sourceRoot = path.join(tmpDir, "src");
24+
await fs.promises.mkdir(sourceRoot, { recursive: true });
25+
const tempDir = path.join(tmpDir, "temp");
26+
await fs.promises.mkdir(tempDir, { recursive: true });
27+
28+
const logger = getRunnerLogger(true);
29+
const config = createTestConfig({ dbLocation });
30+
31+
// Mock the getFileOidsUnderPath function to return base OIDs
32+
const baseOids = {
33+
"unchanged.js": "aaa111",
34+
"modified.js": "bbb222",
35+
"deleted.js": "ccc333",
36+
};
37+
const getFileOidsStubForBase = sinon
38+
.stub(gitUtils, "getFileOidsUnderPath")
39+
.resolves(baseOids);
40+
41+
// Write the base database OIDs file
42+
await writeBaseDatabaseOidsFile(config, sourceRoot);
43+
getFileOidsStubForBase.restore();
44+
45+
// Mock the getFileOidsUnderPath function to return overlay OIDs
46+
const currentOids = {
47+
"unchanged.js": "aaa111",
48+
"modified.js": "ddd444", // Changed OID
49+
"added.js": "eee555", // New file
50+
};
51+
const getFileOidsStubForOverlay = sinon
52+
.stub(gitUtils, "getFileOidsUnderPath")
53+
.resolves(currentOids);
54+
55+
// Write the overlay changes file, which uses the mocked overlay OIDs
56+
// and the base database OIDs file
57+
const getTempDirStub = sinon
58+
.stub(actionsUtil, "getTemporaryDirectory")
59+
.returns(tempDir);
60+
const changesFilePath = await writeOverlayChangesFile(
61+
config,
62+
sourceRoot,
63+
logger,
64+
);
65+
getFileOidsStubForOverlay.restore();
66+
getTempDirStub.restore();
67+
68+
const fileContent = await fs.promises.readFile(changesFilePath, "utf-8");
69+
const parsedContent = JSON.parse(fileContent) as { changes: string[] };
70+
71+
t.deepEqual(
72+
parsedContent.changes.sort(),
73+
["added.js", "deleted.js", "modified.js"],
74+
"Should identify added, deleted, and modified files",
75+
);
76+
});
77+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy