Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit db9689f

Browse files
committed
Re-enable CLI watcher tests
These have been notoriously flakey so they were disabled a long ago.
1 parent d03234b commit db9689f

File tree

4 files changed

+72
-106
lines changed

4 files changed

+72
-106
lines changed

bin/node-sass

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ function getEmitter() {
158158
emitter.on('warn', function(data) {
159159
if (!options.quiet) {
160160
console.warn(data);
161+
} else if (process.env.NODE_ENV) {
162+
console.warn('TESTING', data);
161163
}
162164
});
163165

@@ -291,9 +293,13 @@ function watch(options, emitter) {
291293
graph = buildGraph(options);
292294
});
293295

294-
if (!options.quiet) {
295-
emitter.emit('warn', util.format('Watching %s', options.directory || options.src));
296-
}
296+
gaze.on('ready', function() {
297+
if (process.env.NODE_ENV === 'test') {
298+
setTimeout(function() {
299+
console.warn('TESTING');
300+
}, 1000);
301+
}
302+
});
297303
}
298304

299305
/**

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"coverage": "node scripts/coverage.js",
3232
"install": "node scripts/install.js",
3333
"postinstall": "node scripts/build.js",
34-
"lint": "node_modules/.bin/eslint bin/node-sass lib scripts test",
35-
"test": "node_modules/.bin/mocha test/cli.js",
34+
"lint": "eslint bin/node-sass lib scripts test",
35+
"test": "mocha test/{*,**/**}.js",
3636
"build": "node scripts/build.js --force",
3737
"prepublish": "not-in-install && node scripts/prepublish.js || in-install"
3838
},
@@ -77,7 +77,6 @@
7777
"coveralls": "^2.11.8",
7878
"eslint": "^3.4.0",
7979
"istanbul": "^0.4.2",
80-
"lodash.once": "^4.1.1",
8180
"mocha": "^3.1.2",
8281
"mocha-lcov-reporter": "^1.2.0",
8382
"object-merge": "^2.5.1",

test/cli.js

Lines changed: 60 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@ var assert = require('assert'),
55
glob = require('glob'),
66
rimraf = require('rimraf'),
77
stream = require('stream'),
8-
once = require('lodash.once'),
98
spawn = require('cross-spawn'),
109
cli = path.join(__dirname, '..', 'bin', 'node-sass'),
1110
touch = require('touch'),
1211
tmpDir = require('unique-temp-dir'),
1312
fixture = path.join.bind(null, __dirname, 'fixtures');
1413

15-
describe.only('cli', function() {
16-
// For some reason we experience random timeout failures in CI
17-
// due to spawn hanging/failing silently. See #1692.
18-
// this.retries(4);
14+
process.env.NODE_ENV = 'test';
1915

16+
describe('cli', function() {
2017
describe('node-sass < in.scss', function() {
2118
it('should read data from stdin', function(done) {
2219
var src = fs.createReadStream(fixture('simple/index.scss'));
@@ -125,33 +122,11 @@ describe.only('cli', function() {
125122

126123
describe('node-sass in.scss', function() {
127124
it('should compile a scss file', function(done) {
128-
process.chdir(fixture('simple'));
129-
130125
var src = fixture('simple/index.scss');
131-
var dest = fixture('simple/index.css');
126+
var dest = path.join(tmpDir({ create: true }), 'index.css');
132127
var bin = spawn(cli, [src, dest]);
133128

134-
bin.once('close', function() {
135-
assert(fs.existsSync(dest));
136-
fs.unlinkSync(dest);
137-
process.chdir(__dirname);
138-
done();
139-
});
140-
});
141-
142-
it('should compile a scss file to custom destination', function(done) {
143-
process.chdir(fixture('simple'));
144-
145-
var src = fixture('simple/index.scss');
146-
var dest = fixture('simple/index-custom.css');
147-
var bin = spawn(cli, [src, dest]);
148-
149-
bin.once('close', function() {
150-
assert(fs.existsSync(dest));
151-
fs.unlinkSync(dest);
152-
process.chdir(__dirname);
153-
done();
154-
});
129+
bin.once('close', done);
155130
});
156131

157132
it('should compile with the --include-path option', function(done) {
@@ -167,45 +142,39 @@ describe.only('cli', function() {
167142
bin.stdout.setEncoding('utf8');
168143
bin.stdout.once('data', function(data) {
169144
assert.equal(data.trim(), expected.replace(/\r\n/g, '\n'));
170-
done();
145+
bin.kill();
171146
});
147+
bin.on('exit', done);
172148
});
173149

174150
it('should compile silently using the --quiet option', function(done) {
175-
process.chdir(fixture('simple'));
176-
177151
var src = fixture('simple/index.scss');
178-
var dest = fixture('simple/index.css');
152+
var dest = path.join(tmpDir({ create: true }), 'index.css');
179153
var bin = spawn(cli, [src, dest, '--quiet']);
180-
var didEmit = false;
181154

182-
bin.stderr.once('data', function() {
183-
didEmit = true;
155+
bin.stderr.on('data', function(data) {
156+
if (!/^TESTING/.test(data.toString())) {
157+
assert.fail('should not emit console output with --quiet flag');
158+
}
184159
});
185160

186-
bin.once('close', function() {
187-
assert.equal(didEmit, false);
188-
fs.unlinkSync(dest);
189-
process.chdir(__dirname);
190-
done();
191-
});
161+
bin.on('close', done);
192162
});
193163

194164
it('should still report errors with the --quiet option', function(done) {
195-
process.chdir(fixture('invalid'));
196-
197165
var src = fixture('invalid/index.scss');
198-
var dest = fixture('invalid/index.css');
166+
var dest = path.join(tmpDir({ create: true }), 'index.css');
199167
var bin = spawn(cli, [src, dest, '--quiet']);
200168
var didEmit = false;
201169

202-
bin.stderr.once('data', function() {
203-
didEmit = true;
170+
bin.stderr.on('data', function(data) {
171+
if (!/^TESTING/.test(data.toString())) {
172+
didEmit = true;
173+
}
204174
});
205175

206176
bin.once('close', function() {
207177
assert.equal(didEmit, true);
208-
process.chdir(__dirname);
209178
done();
210179
});
211180
});
@@ -219,14 +188,16 @@ describe.only('cli', function() {
219188
exited = true;
220189
});
221190

222-
setTimeout(function() {
223-
if (exited) {
224-
throw new Error('Watch ended too early!');
225-
} else {
226-
bin.kill();
227-
done();
228-
}
229-
}, 100);
191+
bin.stderr.once('data', function () {
192+
setTimeout(function() {
193+
if (exited) {
194+
throw new Error('Watch ended too early!');
195+
} else {
196+
bin.kill();
197+
done();
198+
}
199+
}, 100);
200+
});
230201
});
231202

232203
it('should emit `warn` on file change when using --watch option', function(done) {
@@ -235,8 +206,8 @@ describe.only('cli', function() {
235206
var bin = spawn(cli, ['--watch', src]);
236207

237208
bin.stderr.setEncoding('utf8');
238-
bin.stderr.once('data', function (data) {
239-
touch.sync(src);
209+
bin.stderr.once('data', function () {
210+
touch(src);
240211
});
241212
bin.stderr.on('data', function (data) {
242213
if (data.trim() === '=> changed: ' + src) {
@@ -248,35 +219,31 @@ describe.only('cli', function() {
248219
done();
249220
});
250221
bin.on('exit', done);
251-
}).timeout(5000);
222+
});
252223

253224
it('should emit nothing on file change when using --watch and --quiet options', function(done) {
254225
var src = fixture('watching-dir-01/index.scss');
255226

256227
var bin = spawn(cli, ['--watch', '--quiet', src]);
257228

258229
bin.stderr.setEncoding('utf8');
230+
// bin.stderr.on('data', function(data) { console.log('stderr', data.toString()) })
231+
// bin.stdout.on('data', function(data) { console.log('stdout', data.toString()) })
259232
bin.stderr.once('data', function() {
260-
assert.fail('should not emit console output with --quiet flag');
233+
touch(src);
234+
});
235+
bin.stderr.on('data', function(data) {
236+
if (!/^TESTING/.test(data.toString())) {
237+
assert.fail('should not emit console output with --quiet flag');
238+
}
239+
bin.kill();
261240
});
262241
bin.on('error', function(err) {
263242
assert.fail(err);
264243
done();
265244
});
266245
bin.on('exit', done);
267-
268-
setTimeout(function() {
269-
touch(src, {}, function(err) {
270-
if (err) {
271-
assert.fail(err);
272-
}
273-
274-
setTimeout(function() {
275-
bin.kill();
276-
}, 1000);
277-
});
278-
}, 500);
279-
}).timeout(5000);
246+
});
280247

281248
it('should render all watched files', function(done) {
282249
var src = fixture('watching-dir-01/index.scss');
@@ -287,8 +254,9 @@ describe.only('cli', function() {
287254
]);
288255

289256
bin.stdout.setEncoding('utf8');
290-
// bin.stderr.on('data', function(data) { console.log('stderr', data.toString()) })
291-
// bin.stdout.on('data', function(data) { console.log('stdout', data.toString()) })
257+
bin.stderr.on('data', function() {
258+
touch(src);
259+
});
292260
bin.stdout.once('data', function(data) {
293261
assert.strictEqual(data.trim(), 'a{color:green}');
294262
bin.kill();
@@ -298,11 +266,7 @@ describe.only('cli', function() {
298266
done();
299267
});
300268
bin.on('exit', done);
301-
302-
setTimeout(function() {
303-
touch.sync(src);
304-
}, 500);
305-
}).timeout(5000);
269+
});
306270

307271
it('should watch the full scss dep tree for a single file (scss)', function(done) {
308272
var src = fixture('watching/index.scss');
@@ -327,7 +291,7 @@ describe.only('cli', function() {
327291
done();
328292
});
329293
bin.on('exit', done);
330-
}).timeout(5000);
294+
});
331295

332296
it('should watch the full sass dep tree for a single file (sass)', function(done) {
333297
var src = fixture('watching/index.sass');
@@ -357,7 +321,7 @@ describe.only('cli', function() {
357321
touch.sync(child);
358322
}, 500);
359323
});
360-
}).timeout(5000);
324+
});
361325

362326
describe('node-sass --output directory', function() {
363327
it('should watch whole directory', function(done) {
@@ -395,7 +359,7 @@ describe.only('cli', function() {
395359
});
396360
bin.on('error', assert.fail);
397361
bin.on('exit', done);
398-
}).timeout(5000);
362+
});
399363

400364
it('should compile all changed files in watched directory', function(done) {
401365
var destDir = tmpDir({
@@ -691,10 +655,20 @@ describe.only('cli', function() {
691655
});
692656

693657
describe('importer', function() {
694-
var dest = fixture('include-files/index.css');
658+
var dest;
695659
var src = fixture('include-files/index.scss');
696660
var expected = read(fixture('include-files/expected-importer.css'), 'utf8').trim().replace(/\r\n/g, '\n');
697661

662+
beforeEach(function() {
663+
dest = path.join(tmpDir({ create: true }), 'index.css');
664+
});
665+
666+
afterEach(function() {
667+
if (fs.existsSync(dest)) {
668+
fs.unlinkSync(dest);
669+
}
670+
});
671+
698672
it('should override imports and fire callback with file and contents', function(done) {
699673
var bin = spawn(cli, [
700674
src, '--output', path.dirname(dest),
@@ -703,7 +677,6 @@ describe.only('cli', function() {
703677

704678
bin.once('close', function() {
705679
assert.equal(read(dest, 'utf8').trim(), expected);
706-
fs.unlinkSync(dest);
707680
done();
708681
});
709682
});
@@ -715,11 +688,7 @@ describe.only('cli', function() {
715688
]);
716689

717690
bin.once('close', function() {
718-
if (fs.existsSync(dest)) {
719-
assert.equal(read(dest, 'utf8').trim(), '');
720-
fs.unlinkSync(dest);
721-
}
722-
691+
assert.equal(read(dest, 'utf8').trim(), '/* foo.scss */\n/* bar.scss */');
723692
done();
724693
});
725694
});
@@ -732,7 +701,6 @@ describe.only('cli', function() {
732701

733702
bin.once('close', function() {
734703
assert.equal(read(dest, 'utf8').trim(), expected);
735-
fs.unlinkSync(dest);
736704
done();
737705
});
738706
});
@@ -745,7 +713,6 @@ describe.only('cli', function() {
745713

746714
bin.once('close', function() {
747715
assert.equal(read(dest, 'utf8').trim(), expected);
748-
fs.unlinkSync(dest);
749716
done();
750717
});
751718
});
@@ -757,11 +724,7 @@ describe.only('cli', function() {
757724
]);
758725

759726
bin.once('close', function() {
760-
if (fs.existsSync(dest)) {
761-
assert.equal(read(dest, 'utf8').trim(), '');
762-
fs.unlinkSync(dest);
763-
}
764-
727+
assert.equal(read(dest, 'utf8').trim(), '/* foo.scss */\n/* bar.scss */');
765728
done();
766729
});
767730
});
@@ -774,7 +737,6 @@ describe.only('cli', function() {
774737

775738
bin.once('close', function() {
776739
assert.equal(read(dest, 'utf8').trim(), expected);
777-
fs.unlinkSync(dest);
778740
done();
779741
});
780742
});
@@ -787,7 +749,6 @@ describe.only('cli', function() {
787749

788750
bin.once('close', function() {
789751
assert.equal(read(dest, 'utf8').trim(), expected);
790-
fs.unlinkSync(dest);
791752
done();
792753
});
793754
});

test/fixtures/source-map-embed/expected.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)