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

Commit

Permalink
Re-enable CLI watcher tests
Browse files Browse the repository at this point in the history
These have been notoriously flakey so they were disabled a long ago.
  • Loading branch information
xzyfer committed Apr 2, 2017
1 parent d03234b commit 3782394
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 106 deletions.
12 changes: 9 additions & 3 deletions bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ function getEmitter() {
emitter.on('warn', function(data) {
if (!options.quiet) {
console.warn(data);
} else if (process.env.NODE_ENV) {
console.warn('TESTING', data);
}
});

Expand Down Expand Up @@ -291,9 +293,13 @@ function watch(options, emitter) {
graph = buildGraph(options);
});

if (!options.quiet) {
emitter.emit('warn', util.format('Watching %s', options.directory || options.src));
}
gaze.on('ready', function() {
if (process.env.NODE_ENV === 'test') {
setTimeout(function() {
console.warn('TESTING');
}, 1000);
}
});
}

/**
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"coverage": "node scripts/coverage.js",
"install": "node scripts/install.js",
"postinstall": "node scripts/build.js",
"lint": "node_modules/.bin/eslint bin/node-sass lib scripts test",
"test": "node_modules/.bin/mocha test/cli.js",
"lint": "eslint bin/node-sass lib scripts test",
"test": "mocha test/{*,**/**}.js",
"build": "node scripts/build.js --force",
"prepublish": "not-in-install && node scripts/prepublish.js || in-install"
},
Expand Down Expand Up @@ -77,7 +77,6 @@
"coveralls": "^2.11.8",
"eslint": "^3.4.0",
"istanbul": "^0.4.2",
"lodash.once": "^4.1.1",
"mocha": "^3.1.2",
"mocha-lcov-reporter": "^1.2.0",
"object-merge": "^2.5.1",
Expand Down
159 changes: 60 additions & 99 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ var assert = require('assert'),
glob = require('glob'),
rimraf = require('rimraf'),
stream = require('stream'),
once = require('lodash.once'),
spawn = require('cross-spawn'),
cli = path.join(__dirname, '..', 'bin', 'node-sass'),
touch = require('touch'),
tmpDir = require('unique-temp-dir'),
fixture = path.join.bind(null, __dirname, 'fixtures');

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

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

describe('node-sass in.scss', function() {
it('should compile a scss file', function(done) {
process.chdir(fixture('simple'));

var src = fixture('simple/index.scss');
var dest = fixture('simple/index.css');
var dest = path.join(tmpDir({ create: true }), 'index.css');
var bin = spawn(cli, [src, dest]);

bin.once('close', function() {
assert(fs.existsSync(dest));
fs.unlinkSync(dest);
process.chdir(__dirname);
done();
});
});

it('should compile a scss file to custom destination', function(done) {
process.chdir(fixture('simple'));

var src = fixture('simple/index.scss');
var dest = fixture('simple/index-custom.css');
var bin = spawn(cli, [src, dest]);

bin.once('close', function() {
assert(fs.existsSync(dest));
fs.unlinkSync(dest);
process.chdir(__dirname);
done();
});
bin.once('close', done);
});

it('should compile with the --include-path option', function(done) {
Expand All @@ -167,45 +142,39 @@ describe.only('cli', function() {
bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function(data) {
assert.equal(data.trim(), expected.replace(/\r\n/g, '\n'));
done();
bin.kill();
});
bin.on('exit', done);
});

it('should compile silently using the --quiet option', function(done) {
process.chdir(fixture('simple'));

var src = fixture('simple/index.scss');
var dest = fixture('simple/index.css');
var dest = path.join(tmpDir({ create: true }), 'index.css');
var bin = spawn(cli, [src, dest, '--quiet']);
var didEmit = false;

bin.stderr.once('data', function() {
didEmit = true;
bin.stderr.on('data', function(data) {
if (!/^TESTING/.test(data.toString())) {
assert.fail('should not emit console output with --quiet flag');
}
});

bin.once('close', function() {
assert.equal(didEmit, false);
fs.unlinkSync(dest);
process.chdir(__dirname);
done();
});
bin.on('close', done);
});

it('should still report errors with the --quiet option', function(done) {
process.chdir(fixture('invalid'));

var src = fixture('invalid/index.scss');
var dest = fixture('invalid/index.css');
var dest = path.join(tmpDir({ create: true }), 'index.css');
var bin = spawn(cli, [src, dest, '--quiet']);
var didEmit = false;

bin.stderr.once('data', function() {
didEmit = true;
bin.stderr.on('data', function(data) {
if (!/^TESTING/.test(data.toString())) {
didEmit = true;
}
});

bin.once('close', function() {
assert.equal(didEmit, true);
process.chdir(__dirname);
done();
});
});
Expand All @@ -219,14 +188,16 @@ describe.only('cli', function() {
exited = true;
});

setTimeout(function() {
if (exited) {
throw new Error('Watch ended too early!');
} else {
bin.kill();
done();
}
}, 100);
bin.stderr.once('data', function () {
setTimeout(function() {
if (exited) {
throw new Error('Watch ended too early!');
} else {
bin.kill();
done();
}
}, 100);
});
});

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

bin.stderr.setEncoding('utf8');
bin.stderr.once('data', function (data) {
touch.sync(src);
bin.stderr.once('data', function () {
touch(src);
});
bin.stderr.on('data', function (data) {
if (data.trim() === '=> changed: ' + src) {
Expand All @@ -248,35 +219,31 @@ describe.only('cli', function() {
done();
});
bin.on('exit', done);
}).timeout(5000);
});

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

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

bin.stderr.setEncoding('utf8');
// bin.stderr.on('data', function(data) { console.log('stderr', data.toString()) })
// bin.stdout.on('data', function(data) { console.log('stdout', data.toString()) })
bin.stderr.once('data', function() {
assert.fail('should not emit console output with --quiet flag');
touch(src);
});
bin.stderr.on('data', function(data) {
if (!/^TESTING/.test(data.toString())) {
assert.fail('should not emit console output with --quiet flag');
}
bin.kill();
});
bin.on('error', function(err) {
assert.fail(err);
done();
});
bin.on('exit', done);

setTimeout(function() {
touch(src, {}, function(err) {
if (err) {
assert.fail(err);
}

setTimeout(function() {
bin.kill();
}, 1000);
});
}, 500);
}).timeout(5000);
});

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

bin.stdout.setEncoding('utf8');
// bin.stderr.on('data', function(data) { console.log('stderr', data.toString()) })
// bin.stdout.on('data', function(data) { console.log('stdout', data.toString()) })
bin.stderr.on('data', function() {
touch(src);
});
bin.stdout.once('data', function(data) {
assert.strictEqual(data.trim(), 'a{color:green}');
bin.kill();
Expand All @@ -298,11 +266,7 @@ describe.only('cli', function() {
done();
});
bin.on('exit', done);

setTimeout(function() {
touch.sync(src);
}, 500);
}).timeout(5000);
});

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

it('should watch the full sass dep tree for a single file (sass)', function(done) {
var src = fixture('watching/index.sass');
Expand Down Expand Up @@ -395,7 +359,7 @@ describe.only('cli', function() {
});
bin.on('error', assert.fail);
bin.on('exit', done);
}).timeout(5000);
});

it('should compile all changed files in watched directory', function(done) {
var destDir = tmpDir({
Expand Down Expand Up @@ -433,7 +397,7 @@ describe.only('cli', function() {
bin.on('error', assert.fail);
bin.on('exit', done);
});
});
}).timeout(5000);

describe('node-sass in.scss --output out.css', function() {
it('should compile a scss file to build.css', function(done) {
Expand Down Expand Up @@ -691,10 +655,20 @@ describe.only('cli', function() {
});

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

beforeEach(function() {
dest = path.join(tmpDir({ create: true }), 'index.css');
});

afterEach(function() {
if (fs.existsSync(dest)) {
fs.unlinkSync(dest);
}
});

it('should override imports and fire callback with file and contents', function(done) {
var bin = spawn(cli, [
src, '--output', path.dirname(dest),
Expand All @@ -703,7 +677,6 @@ describe.only('cli', function() {

bin.once('close', function() {
assert.equal(read(dest, 'utf8').trim(), expected);
fs.unlinkSync(dest);
done();
});
});
Expand All @@ -715,11 +688,7 @@ describe.only('cli', function() {
]);

bin.once('close', function() {
if (fs.existsSync(dest)) {
assert.equal(read(dest, 'utf8').trim(), '');
fs.unlinkSync(dest);
}

assert.equal(read(dest, 'utf8').trim(), '/* foo.scss */\n/* bar.scss */');
done();
});
});
Expand All @@ -732,7 +701,6 @@ describe.only('cli', function() {

bin.once('close', function() {
assert.equal(read(dest, 'utf8').trim(), expected);
fs.unlinkSync(dest);
done();
});
});
Expand All @@ -745,7 +713,6 @@ describe.only('cli', function() {

bin.once('close', function() {
assert.equal(read(dest, 'utf8').trim(), expected);
fs.unlinkSync(dest);
done();
});
});
Expand All @@ -757,11 +724,7 @@ describe.only('cli', function() {
]);

bin.once('close', function() {
if (fs.existsSync(dest)) {
assert.equal(read(dest, 'utf8').trim(), '');
fs.unlinkSync(dest);
}

assert.equal(read(dest, 'utf8').trim(), '/* foo.scss */\n/* bar.scss */');
done();
});
});
Expand All @@ -774,7 +737,6 @@ describe.only('cli', function() {

bin.once('close', function() {
assert.equal(read(dest, 'utf8').trim(), expected);
fs.unlinkSync(dest);
done();
});
});
Expand All @@ -787,7 +749,6 @@ describe.only('cli', function() {

bin.once('close', function() {
assert.equal(read(dest, 'utf8').trim(), expected);
fs.unlinkSync(dest);
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/source-map-embed/expected.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3782394

Please sign in to comment.