Skip to content

Commit

Permalink
test(cache): test the cacher
Browse files Browse the repository at this point in the history
  • Loading branch information
blurrah committed Jul 1, 2024
1 parent 649b294 commit 1fe1438
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
82 changes: 79 additions & 3 deletions src/write.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,83 @@
import { describe, expect, test } from "vitest";
import { updateCache } from "./write";

describe("write to file", () => {
test("Hello", () => {
expect(true).toBeTruthy();
describe("cache", () => {
test("writes output to empty cache", () => {
const cache = {};

updateCache({
cache,
data: {
Test: new Set(["hello"]),
"Test.NestedNamespace": new Set(["foobar"]),
},
source: {},
});

expect(cache).toEqual({
Test: {
hello: "Test.hello",
NestedNamespace: {
foobar: "Test.NestedNamespace.foobar",
},
},
});
});

test("writes output to existing cache", () => {
const cache = {
Test: {
hello: "Test.hello",
NestedNamespace: {
foobar: "Test.NestedNamespace.foobar",
},
},
};

updateCache({
cache,
data: {
Test: new Set(["test"]),
"Test.NestedNamespace": new Set(["test"]),
},
source: {},
});

expect(cache).toEqual({
Test: {
hello: "Test.hello",
test: "Test.test",
NestedNamespace: {
foobar: "Test.NestedNamespace.foobar",
test: "Test.NestedNamespace.test",
},
},
});
});

test("updates labels with existing source", () => {
const cache = {};

updateCache({
cache,
data: {
Test: new Set(["hello"]),
"Test.NestedNamespace": new Set(["foobar"]),
},
source: {
Test: {
hello: "Hello",
},
},
});

expect(cache).toEqual({
Test: {
hello: "Hello",
NestedNamespace: {
foobar: "Test.NestedNamespace.foobar",
},
},
});
});
});
2 changes: 1 addition & 1 deletion src/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function processFiles(
/**
* Update existing cache based on given data and source labels
*/
function updateCache({
export function updateCache({
cache,
source,
data,
Expand Down

0 comments on commit 1fe1438

Please sign in to comment.