This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
100 lines (77 loc) · 2.26 KB
/
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { assertEquals } from 'https://deno.land/[email protected]/assert/mod.ts';
import {
DenoConfiguration,
getDenoConfiguration,
getImportMap,
ImportMap,
} from './mod.ts';
const realFilepath = 'deno.json';
const temporaryFilepath = 'temporay-deno.json';
const configFilepath = 'deno.json';
const importMapFilepath = 'import-map.json';
Deno.test('getDenoConfiguration', async () => {
const configuration: DenoConfiguration = {
tasks: { greet: 'echo \'Hello world!\'' },
} as const;
await Deno.rename(realFilepath, temporaryFilepath);
await Deno.writeTextFile(configFilepath, JSON.stringify(configuration));
assertEquals(await getDenoConfiguration(), configuration);
await Deno.remove(configFilepath);
await Deno.rename(temporaryFilepath, realFilepath);
});
Deno.test('getImportMap (field)', async () => {
const configuration: DenoConfiguration = {
imports: { hello: 'world' },
} as const;
const importMapWritePromise = Deno.writeTextFile(
importMapFilepath,
JSON.stringify({}),
);
await Deno.rename(realFilepath, temporaryFilepath);
await Promise.all([
importMapWritePromise,
Deno.writeTextFile(
configFilepath,
JSON.stringify(configuration),
),
]);
assertEquals(
await getImportMap(),
// NOTE Comparing directly because it only contains fields also in `ImportMap`.
configuration,
);
const importMapRemovePromise = Deno.remove(importMapFilepath);
await Deno.remove(configFilepath);
await Promise.all([
importMapRemovePromise,
Deno.rename(temporaryFilepath, realFilepath),
]);
});
Deno.test('getImportMap (file)', async () => {
const configuration: DenoConfiguration = {
importMap: 'import-map.json',
} as const;
const importMap: ImportMap = { imports: { hello: 'world' } } as const;
const importMapWritePromise = Deno.writeTextFile(
importMapFilepath,
JSON.stringify(importMap),
);
await Deno.rename(realFilepath, temporaryFilepath);
await Promise.all([
importMapWritePromise,
Deno.writeTextFile(
configFilepath,
JSON.stringify(configuration),
),
]);
assertEquals(
await getImportMap(),
importMap,
);
const importMapRemovePromise = Deno.remove(importMapFilepath);
await Deno.remove(configFilepath);
await Promise.all([
importMapRemovePromise,
Deno.rename(temporaryFilepath, realFilepath),
]);
});