-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.test.ts
104 lines (94 loc) · 2.8 KB
/
plugin.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
101
102
103
104
import * as apex from "../deps/@apexlang/core/mod.ts";
import { assertEquals } from "../deps/@std/assert/mod.ts";
import { processConfig, processPlugin } from "../src/generate.ts";
import * as path from "../deps/@std/path/mod.ts";
import { asBytes, setupLogger } from "../src/utils.ts";
import { Configuration } from "../src/config.ts";
const __dirname = new URL(".", import.meta.url).pathname;
const spec = path.join(__dirname, "test.axdl");
const plugin = path.join(__dirname, "test-plugin.ts");
const generator = path.join(__dirname, "test-generator.ts");
await setupLogger("DEBUG");
Deno.test(
"plugin",
{ permissions: { read: true, net: true, run: true } },
async () => {
const apexSource = await Deno.readTextFile(spec);
const doc = apex.parse(apexSource);
const config = await processPlugin(doc, {
spec,
plugins: [plugin],
});
assertEquals(config.generates, { "Test.0.file": { module: generator } });
},
);
Deno.test(
"plugins don't override original tasks, generate commands, or config properties",
{ permissions: { read: true, net: true, run: true } },
async () => {
const apexSource = await Deno.readTextFile(spec);
const doc = apex.parse(apexSource);
const config = await processPlugin(doc, {
spec,
config: { name: "", value: "original" },
plugins: [plugin],
tasks: {
"build": {
cmds: [`echo "overridden"`],
deps: [""],
},
},
generates: { "Test.1.file": { module: "overridden.ts" } },
} as Configuration);
assertEquals(config, {
spec,
config: { value: "original", name: "from-plugin" },
plugins: [plugin],
tasks: { "build": { cmds: [`echo "overridden"`], deps: [""] } },
generates: { "Test.1.file": { module: "overridden.ts" } },
});
},
);
Deno.test(
"plugin",
{ permissions: { read: true, net: true, run: true } },
async () => {
const apexSource = await Deno.readTextFile(spec);
const doc = apex.parse(apexSource);
const config = await processPlugin(doc, {
spec,
plugins: [plugin, plugin],
});
assertEquals(config.generates, {
"Test.0.file": { module: generator },
"Test.1.file": { module: generator },
});
assertEquals(config.tasks, {
"build": { cmds: [`echo "from-plugin"`] },
});
},
);
Deno.test(
"generate",
{ permissions: { read: true, net: true, run: true } },
async () => {
const output = await processConfig({
spec,
plugins: [plugin, plugin],
});
assertEquals(output, [
{
path: "Test.0.file",
contents: asBytes("startend"),
executable: false,
runAfter: undefined,
},
{
path: "Test.1.file",
contents: asBytes("startend"),
executable: false,
runAfter: undefined,
},
]);
},
);