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

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyfer committed Mar 30, 2017
1 parent bdde742 commit 1943d93
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 93 deletions.
19 changes: 13 additions & 6 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 @@ -290,12 +292,17 @@ function watch(options, emitter) {
gaze.on('deleted', function() {
graph = buildGraph(options);
});

emitter.emit('warn', process.env.NODE_ENV);

if (process.env.NODE_ENV === 'test') {
emitter.emit('warn', 'TESTING');
}
// gaze.on('all', function(event, file) {
// console.log(event, file);
// });

gaze.on('ready', function() {
if (process.env.NODE_ENV === 'test') {
setTimeout(function() {
console.warn('TESTING');
}, 1000);
}
});
}

/**
Expand Down
140 changes: 53 additions & 87 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe.only('cli', function() {
// due to spawn hanging/failing silently. See #1692.
// this.retries(4);

describe.skip('node-sass < in.scss', function() {
describe('node-sass < in.scss', function() {
it('should read data from stdin', function(done) {
var src = fs.createReadStream(fixture('simple/index.scss'));
var expected = read(fixture('simple/expected.css'), 'utf8').trim();
Expand Down Expand Up @@ -126,33 +126,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 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 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();
});
bin.once('close', done);
});

it('should compile with the --include-path option', function(done) {
Expand All @@ -168,45 +146,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 @@ -220,14 +192,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 @@ -236,8 +210,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 @@ -249,35 +223,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 @@ -288,8 +258,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 @@ -299,11 +270,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 @@ -328,7 +295,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 @@ -358,7 +325,7 @@ describe.only('cli', function() {
touch.sync(child);
}, 500);
});
}).timeout(5000);
});

describe('node-sass --output directory', function() {
it('should watch whole directory', function(done) {
Expand Down Expand Up @@ -392,12 +359,11 @@ describe.only('cli', function() {
assert.fail('should not emit console output when watching a directory');
});
bin.stderr.once('data', function (data) {
console.log('stderr', data.toString());
touch(srcFile);
});
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 @@ -437,7 +403,7 @@ describe.only('cli', function() {
});
});

describe.skip('node-sass in.scss --output out.css', function() {
describe('node-sass in.scss --output out.css', function() {
it('should compile a scss file to build.css', function(done) {
var src = fixture('simple/index.scss');
var dest = fixture('simple/index.css');
Expand Down Expand Up @@ -530,7 +496,7 @@ describe.only('cli', function() {
});
});

describe.skip('node-sass sass/ --output css/', function() {
describe('node-sass sass/ --output css/', function() {
it('should create the output directory', function(done) {
var src = fixture('input-directory/sass');
var dest = fixture('input-directory/css');
Expand Down Expand Up @@ -646,7 +612,7 @@ describe.only('cli', function() {
});
});

describe.skip('node-sass in.scss --output path/to/file/out.css', function() {
describe('node-sass in.scss --output path/to/file/out.css', function() {
it('should create the output directory', function(done) {
var src = fixture('output-directory/index.scss');
var dest = fixture('output-directory/path/to/file/index.css');
Expand All @@ -666,7 +632,7 @@ describe.only('cli', function() {

});

describe.skip('node-sass --follow --output output-dir input-dir', function() {
describe('node-sass --follow --output output-dir input-dir', function() {
it('should compile with the --follow option', function(done) {
var src = fixture('follow/input-dir');
var dest = fixture('follow/output-dir');
Expand All @@ -692,7 +658,7 @@ describe.only('cli', function() {
});
});

describe.skip('importer', function() {
describe('importer', function() {
var dest = fixture('include-files/index.css');
var src = fixture('include-files/index.scss');
var expected = read(fixture('include-files/expected-importer.css'), 'utf8').trim().replace(/\r\n/g, '\n');
Expand Down Expand Up @@ -819,7 +785,7 @@ describe.only('cli', function() {
});
});

describe.skip('functions', function() {
describe('functions', function() {
it('should let custom functions call setter methods on wrapped sass values (number)', function(done) {
var dest = fixture('custom-functions/setter.css');
var src = fixture('custom-functions/setter.scss');
Expand Down Expand Up @@ -852,4 +818,4 @@ describe.only('cli', function() {
});
});
});
});
}).timeout(5000);

0 comments on commit 1943d93

Please sign in to comment.