-
Notifications
You must be signed in to change notification settings - Fork 12
/
crafty-preset-typescript-gulp.js
123 lines (90 loc) · 3.64 KB
/
crafty-preset-typescript-gulp.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* global describe, it, expect */
const path = require("path");
const configuration = require("@swissquote/crafty/src/configuration");
const { run, cleanDist, exists, readFile } = require("../utils");
const getCrafty = configuration.getCrafty;
jest.setTimeout(10000);
it("Loads crafty-preset-typescript and does not register gulp tasks", () => {
const crafty = getCrafty(["@swissquote/crafty-preset-typescript"], {});
const loadedPresets = crafty.config.loadedPresets.map(
preset => preset.presetName
);
expect(loadedPresets).toContain("@swissquote/crafty-preset-typescript");
crafty.createTasks();
expect(Object.keys(crafty.undertaker._registry.tasks())).toEqual([]);
});
it("Loads crafty-preset-typescript, crafty-runner-gulp and registers gulp task", () => {
const config = { js: { myBundle: { source: "js/**/*.ts" } } };
const crafty = getCrafty(
["@swissquote/crafty-preset-typescript", "@swissquote/crafty-runner-gulp"],
config
);
const loadedPresets = crafty.config.loadedPresets.map(
preset => preset.presetName
);
expect(loadedPresets).toContain("@swissquote/crafty-preset-typescript");
expect(loadedPresets).toContain("@swissquote/crafty-runner-gulp");
crafty.createTasks();
expect(Object.keys(crafty.undertaker._registry.tasks())).toEqual([
"js_myBundle",
"js",
"default"
]);
});
it("Compiles TypeScript", async () => {
const dir = path.join(
__dirname,
"../fixtures/crafty-preset-typescript-gulp/compiles"
);
await cleanDist(dir);
const result = await run(dir, ["run", "default"]);
expect(result).toMatchSnapshot();
expect(exists(dir, "dist/js/myBundle.min.js")).toBeFalsy();
expect(exists(dir, "dist/js/myBundle.min.js.map")).toBeFalsy();
expect(exists(dir, "dist/js/script.js")).toBeTruthy();
expect(exists(dir, "dist/js/script.js.map")).toBeTruthy();
expect(exists(dir, "dist/js/Component.js")).toBeTruthy();
expect(exists(dir, "dist/js/Component.js.map")).toBeTruthy();
expect(readFile(dir, "dist/js/script.js")).toMatchSnapshot();
expect(readFile(dir, "dist/js/Component.js")).toMatchSnapshot();
});
it("Compiles TypeScript and concatenates", async () => {
const dir = path.join(
__dirname,
"../fixtures/crafty-preset-typescript-gulp/concatenates"
);
await cleanDist(dir);
const result = await run(dir, ["run", "default"]);
expect(result).toMatchSnapshot();
expect(exists(dir, "dist/js/myBundle.min.js")).toBeTruthy();
expect(exists(dir, "dist/js/myBundle.min.js.map")).toBeTruthy();
expect(exists(dir, "dist/js/script.js")).toBeFalsy();
expect(exists(dir, "dist/js/script.js.map")).toBeFalsy();
expect(exists(dir, "dist/js/otherfile.js")).toBeFalsy();
expect(exists(dir, "dist/js/otherfile.js.map")).toBeFalsy();
expect(readFile(dir, "dist/js/myBundle.min.js")).toMatchSnapshot();
});
it("Fails gracefully on broken markup", async () => {
const dir = path.join(
__dirname,
"../fixtures/crafty-preset-typescript-gulp/fails"
);
await cleanDist(dir);
const result = await run(dir, ["run", "default"]);
expect(result).toMatchSnapshot();
// Files aren't generated on failed lint
expect(exists(dir, "dist/js/myBundle.min.js")).toBeFalsy();
expect(exists(dir, "dist/js/myBundle.min.js.map")).toBeFalsy();
});
it("Lints TypeScript", async () => {
const dir = path.join(
__dirname,
"../fixtures/crafty-preset-typescript-gulp/lints"
);
await cleanDist(dir);
const result = await run(dir, ["run", "default"]);
expect(result).toMatchSnapshot();
// Files aren't generated on failed lint
expect(exists(dir, "dist/js/myBundle.min.js")).toBeFalsy();
expect(exists(dir, "dist/js/myBundle.min.js.map")).toBeFalsy();
});