-
Notifications
You must be signed in to change notification settings - Fork 12
/
crafty-preset-postcss-gulp.js
140 lines (105 loc) · 4.18 KB
/
crafty-preset-postcss-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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* global describe, it, expect */
const path = require("path");
const rmfr = require("rmfr");
const configuration = require("@swissquote/crafty/src/configuration");
const getCommands = require("@swissquote/crafty/src/commands/index");
const testUtils = require("../utils");
// Add a high timeout because of https://github.com/facebook/jest/issues/8942
// Tests would be unreliable if they timeout >_<
jest.setTimeout(30000);
const getCrafty = configuration.getCrafty;
it("Loads crafty-preset-postcss, crafty-runner-gulp and registers gulp task", () => {
const config = { myBundle: { source: "css/style.scss" } };
const crafty = getCrafty(
["@swissquote/crafty-preset-postcss", "@swissquote/crafty-runner-gulp"],
config
);
const loadedPresets = crafty.config.loadedPresets.map(
preset => preset.presetName
);
expect(loadedPresets).toContain("@swissquote/crafty-preset-postcss");
expect(loadedPresets).toContain("@swissquote/crafty-runner-gulp");
const commands = getCommands(crafty);
expect(Object.keys(commands)).toContain("cssLint");
crafty.createTasks();
expect(Object.keys(crafty.undertaker._registry.tasks())).toEqual([
"css__lint",
"default"
]);
});
it("Doesn't compile without a task, but lints", async () => {
const cwd = path.join(
__dirname,
"../fixtures/crafty-preset-postcss-gulp/no-bundle"
);
await rmfr(path.join(cwd, "dist"));
const result = await testUtils.run(["run", "default"], cwd);
expect(result).toMatchSnapshot();
expect(testUtils.exists(cwd, "dist")).toBeFalsy();
});
it("Doesn't compile without a task, but lints (doesn't throw in development)", async () => {
const cwd = path.join(
__dirname,
"../fixtures/crafty-preset-postcss-gulp/no-bundle-dev"
);
await rmfr(path.join(cwd, "dist"));
const result = await testUtils.run(["run", "default"], cwd);
expect(result).toMatchSnapshot();
expect(testUtils.exists(cwd, "dist")).toBeFalsy();
});
it("Fails gracefully on broken markup", async () => {
const cwd = path.join(
__dirname,
"../fixtures/crafty-preset-postcss-gulp/fails"
);
await rmfr(path.join(cwd, "dist"));
const result = await testUtils.run(["run", "default"], cwd);
expect(result).toMatchSnapshot();
expect(testUtils.exists(cwd, "dist")).toBeFalsy();
});
it("Experiment with all CSS", async () => {
const cwd = path.join(
__dirname,
"../fixtures/crafty-preset-postcss-gulp/experiment"
);
await rmfr(path.join(cwd, "dist"));
const result = await testUtils.run(["run", "default"], cwd);
expect(result).toMatchSnapshot();
expect(testUtils.exists(cwd, "dist/css/myBundle.min.css")).toBeTruthy();
expect(testUtils.exists(cwd, "dist/css/myBundle.min.css.map")).toBeTruthy();
expect(
testUtils.snapshotizeCSS(
testUtils.readFile(cwd, "dist/css/myBundle.min.css")
)
).toMatchSnapshot();
});
it("Compiles CSS", async () => {
const cwd = path.join(
__dirname,
"../fixtures/crafty-preset-postcss-gulp/compiles"
);
await rmfr(path.join(cwd, "dist"));
const result = await testUtils.run(["run", "default"], cwd);
expect(result).toMatchSnapshot();
expect(testUtils.exists(cwd, "dist/css/myBundle.min.css")).toBeTruthy();
expect(testUtils.exists(cwd, "dist/css/myBundle.min.css.map")).toBeTruthy();
expect(testUtils.exists(cwd, "dist/css/imported.scss")).toBeFalsy();
expect(testUtils.readFile(cwd, "dist/css/myBundle.min.css")).toEqual(
".Link{color:#00f}.BodyComponent{margin:0}\n/*# sourceMappingURL=myBundle.min.css.map */\n"
);
});
it("Compiles CSS, configuration has overrides", async () => {
const cwd = path.join(
__dirname,
"../fixtures/crafty-preset-postcss-gulp/compiles-with-overrides"
);
await rmfr(path.join(cwd, "dist"));
const result = await testUtils.run(["run", "default"], cwd);
expect(result).toMatchSnapshot();
expect(testUtils.exists(cwd, "dist/css/myBundle.min.css")).toBeTruthy();
expect(testUtils.exists(cwd, "dist/css/myBundle.min.css.map")).toBeTruthy();
expect(testUtils.exists(cwd, "dist/css/imported.scss")).toBeFalsy();
expect(testUtils.readFile(cwd, "dist/css/myBundle.min.css")).toEqual(
".Link{color:#fa5b35}.BodyComponent{margin:0}\n/*# sourceMappingURL=myBundle.min.css.map */\n"
);
});