-
Notifications
You must be signed in to change notification settings - Fork 347
/
update.dart
277 lines (218 loc) · 9.65 KB
/
update.dart
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// Copyright 2018 Google Inc. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;
import 'package:test_process/test_process.dart';
import '../../utils.dart';
/// Defines test that are shared between the Dart and Node.js CLI test suites.
void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
Future<TestProcess> update(Iterable<String> arguments) =>
runSass(["--no-source-map", "--update", ...arguments]);
group("updates CSS", () {
test("that doesn't exist yet", () async {
await d.file("test.scss", "a {b: c}").create();
var sass = await update(["test.scss:out.css"]);
expect(sass.stdout, emits('Compiled test.scss to out.css.'));
await sass.shouldExit(0);
await d
.file("out.css", equalsIgnoringWhitespace("a { b: c; }"))
.validate();
});
test("whose source was modified", () async {
await d.file("out.css", "x {y: z}").create();
await tick;
await d.file("test.scss", "a {b: c}").create();
var sass = await update(["test.scss:out.css"]);
expect(sass.stdout, emits('Compiled test.scss to out.css.'));
await sass.shouldExit(0);
await d
.file("out.css", equalsIgnoringWhitespace("a { b: c; }"))
.validate();
});
test("whose source was transitively modified", () async {
await d.file("other.scss", "a {b: c}").create();
await d.file("test.scss", "@import 'other'").create();
var sass = await update(["test.scss:out.css"]);
expect(sass.stdout, emits('Compiled test.scss to out.css.'));
await sass.shouldExit(0);
await tick;
await d.file("other.scss", "x {y: z}").create();
sass = await update(["test.scss:out.css"]);
expect(sass.stdout, emits('Compiled test.scss to out.css.'));
await sass.shouldExit(0);
await d
.file("out.css", equalsIgnoringWhitespace("x { y: z; }"))
.validate();
});
test("files that share a modified import", () async {
await d.file("other.scss", r"a {b: $var}").create();
await d.file("test1.scss", r"$var: 1; @import 'other'").create();
await d.file("test2.scss", r"$var: 2; @import 'other'").create();
var sass = await update(["test1.scss:out1.css", "test2.scss:out2.css"]);
expect(sass.stdout, emits('Compiled test1.scss to out1.css.'));
expect(sass.stdout, emits('Compiled test2.scss to out2.css.'));
await sass.shouldExit(0);
await tick;
await d.file("other.scss", r"x {y: $var}").create();
sass = await update(["test1.scss:out1.css", "test2.scss:out2.css"]);
expect(sass.stdout, emits('Compiled test1.scss to out1.css.'));
expect(sass.stdout, emits('Compiled test2.scss to out2.css.'));
await sass.shouldExit(0);
await d
.file("out1.css", equalsIgnoringWhitespace("x { y: 1; }"))
.validate();
await d
.file("out2.css", equalsIgnoringWhitespace("x { y: 2; }"))
.validate();
});
test("from stdin", () async {
var sass = await update(["-:out.css"]);
sass.stdin.writeln("a {b: c}");
sass.stdin.close();
expect(sass.stdout, emits('Compiled stdin to out.css.'));
await sass.shouldExit(0);
await d
.file("out.css", equalsIgnoringWhitespace("a { b: c; }"))
.validate();
sass = await update(["-:out.css"]);
sass.stdin.writeln("x {y: z}");
sass.stdin.close();
expect(sass.stdout, emits('Compiled stdin to out.css.'));
await sass.shouldExit(0);
await d
.file("out.css", equalsIgnoringWhitespace("x { y: z; }"))
.validate();
});
test("without printing anything if --quiet is passed", () async {
await d.file("test.scss", "a {b: c}").create();
var sass = await update(["--quiet", "test.scss:out.css"]);
expect(sass.stdout, emitsDone);
await sass.shouldExit(0);
await d
.file("out.css", equalsIgnoringWhitespace("a { b: c; }"))
.validate();
});
});
group("doesn't update a CSS file", () {
test("whose sources weren't modified", () async {
await d.file("test.scss", "a {b: c}").create();
await d.file("out.css", "x {y: z}").create();
var sass = await update(["test.scss:out.css"]);
expect(sass.stdout, emitsDone);
await sass.shouldExit(0);
await d.file("out.css", "x {y: z}").validate();
});
test("whose sibling was modified", () async {
await d.file("test1.scss", "a {b: c}").create();
await d.file("out1.css", "x {y: z}").create();
await d.file("out2.css", "q {r: s}").create();
await tick;
await d.file("test2.scss", "d {e: f}").create();
var sass = await update(["test1.scss:out1.css", "test2.scss:out2.css"]);
expect(sass.stdout, emits('Compiled test2.scss to out2.css.'));
await sass.shouldExit(0);
await d.file("out1.css", "x {y: z}").validate();
});
test("with a missing import", () async {
await d.file("test.scss", "@import 'other'").create();
var message = "Error: Can't find stylesheet to import.";
var sass = await update(["test.scss:out.css"]);
expect(sass.stderr, emits(message));
expect(sass.stderr, emitsThrough(contains("test.scss 1:9")));
await sass.shouldExit(65);
await d.file("out.css", contains(message)).validate();
});
test("with a conflicting import", () async {
await d.file("test.scss", "@import 'other'").create();
await d.file("other.scss", "a {b: c}").create();
await d.file("_other.scss", "x {y: z}").create();
var message = "Error: It's not clear which file to import. Found:";
var sass = await update(["test.scss:out.css"]);
expect(sass.stderr, emits(message));
expect(sass.stderr, emitsThrough(contains("test.scss 1:9")));
await sass.shouldExit(65);
await d.file("out.css", contains(message)).validate();
});
test("from itself", () async {
await d.dir("dir", [d.file("test.css", "a {b: c}")]).create();
var sass = await update(["dir:dir"]);
expect(sass.stdout, emitsDone);
await sass.shouldExit(0);
await d.file("dir/test.css", "a {b: c}").validate();
});
test("that uses a built-in module", () async {
await d.file("test.scss", "@use 'sass:math'; a {b: c}").create();
await d.file("out.css", "x {y: z}").create();
var sass = await update(["test.scss:out.css"]);
expect(sass.stdout, emitsDone);
await sass.shouldExit(0);
await d.file("out.css", "x {y: z}").validate();
});
});
group("updates a CSS file", () {
test("when a file has an error", () async {
await d.file("test.scss", "a {b: c}").create();
await (await update(["test.scss:out.css"])).shouldExit(0);
await d.file("out.css", anything).validate();
var message = "Error: Expected expression.";
await d.file("test.scss", "a {b: }").create();
var sass = await update(["test.scss:out.css"]);
expect(sass.stderr, emits(message));
expect(sass.stderr, emitsThrough(contains("test.scss 1:7")));
await sass.shouldExit(65);
await d.file("out.css", contains(message)).validate();
});
test("when a file has an error even with another stdout output", () async {
await d.file("test.scss", "a {b: c}").create();
await (await update(["test.scss:out.css"])).shouldExit(0);
await d.file("out.css", anything).validate();
var message = "Error: Expected expression.";
await d.file("test.scss", "a {b: }").create();
await d.file("other.scss", "x {y: z}").create();
var sass = await update(["test.scss:out.css", "other.scss:-"]);
expect(sass.stderr, emits(message));
expect(sass.stderr, emitsThrough(contains("test.scss 1:7")));
await sass.shouldExit(65);
await d.file("out.css", contains(message)).validate();
});
test("when an import is removed", () async {
await d.file("test.scss", "@import 'other'").create();
await d.file("_other.scss", "a {b: c}").create();
await (await update(["test.scss:out.css"])).shouldExit(0);
await d.file("out.css", anything).validate();
var message = "Error: Can't find stylesheet to import.";
d.file("_other.scss").io.deleteSync();
var sass = await update(["test.scss:out.css"]);
expect(sass.stderr, emits(message));
expect(sass.stderr, emitsThrough(contains("test.scss 1:9")));
await sass.shouldExit(65);
await d.file("out.css", contains(message)).validate();
});
});
test("deletes a CSS file when a file has an error with --no-error-css",
() async {
await d.file("test.scss", "a {b: c}").create();
await (await update(["test.scss:out.css"])).shouldExit(0);
await d.file("out.css", anything).validate();
await d.file("test.scss", "a {b: }").create();
var sass = await update(["--no-error-css", "test.scss:out.css"]);
expect(sass.stderr, emits("Error: Expected expression."));
expect(sass.stderr, emitsThrough(contains("test.scss 1:7")));
await sass.shouldExit(65);
await d.nothing("out.css").validate();
});
group("doesn't allow", () {
test("--stdin", () async {
var sass = await update(["--stdin", "test.scss"]);
expect(sass.stdout, emits('--update is not allowed with --stdin.'));
await sass.shouldExit(64);
});
test("printing to stderr", () async {
var sass = await update(["test.scss"]);
expect(sass.stdout,
emits('--update is not allowed when printing to stdout.'));
await sass.shouldExit(64);
});
});
}