-
Notifications
You must be signed in to change notification settings - Fork 2
/
sourceFile.test.ts
74 lines (62 loc) · 2.23 KB
/
sourceFile.test.ts
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { SourceFile } from "../lib/sources/sourceFile.ts";
import { assertEquals, assertRejects, assertSnapshot, join } from "./deps.ts";
import {
ensureRelativePath,
getFixtureDir,
getFixturePath,
} from "./helpers.ts";
const outputDir = await Deno.makeTempDir();
function createSourceFile(path: string) {
return new SourceFile(
getFixturePath("app", path),
getFixtureDir("app"),
);
}
Deno.test("constructor", async () => {
const path = join("src", "app.tsx");
const sourceFile = createSourceFile(path);
assertEquals(sourceFile.isLocked(), true);
assertEquals(sourceFile.root(), getFixtureDir("app"));
assertEquals(
sourceFile.path(),
getFixturePath("app", sourceFile.relativePath()),
);
assertEquals(sourceFile.relativePath(), ensureRelativePath(path));
assertEquals(await sourceFile.contentHash(), "d28e4b24");
});
Deno.test("url", () => {
const file = new SourceFile("./client.tsx", "file:///app");
assertEquals(file.url(), new URL("file:///app/client.tsx"));
});
Deno.test("path", () => {
const file = new SourceFile("./client.tsx", "file:///app");
assertEquals(file.path(), "/app/client.tsx");
});
Deno.test("relativePath", () => {
const file = new SourceFile("./client.tsx", "file:///app");
assertEquals(file.relativePath(), "./client.tsx");
});
Deno.test("copyTo", async () => {
const sourceFile = createSourceFile(join("src", "app.tsx"));
const copied = await sourceFile.copyTo(outputDir);
assertEquals(copied.root(), outputDir);
assertEquals(copied.path(), join(outputDir, copied.relativePath()));
assertEquals(copied.isLocked(), false);
assertEquals(await copied.contentHash(), await sourceFile.contentHash());
/**
* We should be able to remove this file since it was copied
*/
assertEquals(await copied.remove(), true);
});
Deno.test("remove a locked file", () => {
const sourceFile = createSourceFile(join("src", "app.tsx"));
assertRejects(() => sourceFile.remove());
});
Deno.test("read a file", async (t) => {
const sourceFile = createSourceFile(join("src", "app.tsx"));
assertSnapshot(t, await sourceFile.read());
});
Deno.test("read a non existent file", () => {
const sourceFile = createSourceFile(join("src", "app2.tsx"));
assertRejects(() => sourceFile.read());
});