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

Commit

Permalink
Fix tests that have always been broke
Browse files Browse the repository at this point in the history
Four years ago there was a test that mutated `process.cwd` but
didn't correctly reset it. The altered global state resulted in
future tests having incorrect assetions. I only noticed this because
for some reason it manifested in failures in only _some_ Node
versions when N-API was being used.
  • Loading branch information
xzyfer authored and nschonni committed Sep 27, 2020
1 parent e3ed10b commit d1d9547
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
29 changes: 9 additions & 20 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,25 @@ describe('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 bin = spawn(cli, [src, dest]);

bin.once('close', function() {
assert(fs.existsSync(dest));
fs.unlinkSync(dest);
process.chdir(__dirname);
done();
});
});
Expand All @@ -169,8 +163,6 @@ describe('cli', function() {
});

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 bin = spawn(cli, [src, dest, '--quiet']);
Expand All @@ -183,14 +175,11 @@ describe('cli', function() {
bin.once('close', function() {
assert.equal(didEmit, false);
fs.unlinkSync(dest);
process.chdir(__dirname);
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 bin = spawn(cli, [src, dest, '--quiet']);
Expand All @@ -202,7 +191,6 @@ describe('cli', function() {

bin.once('close', function() {
assert.equal(didEmit, true);
process.chdir(__dirname);
done();
});
});
Expand Down Expand Up @@ -644,7 +632,8 @@ describe('cli', 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');
var expectedData = read(fixture('include-files/expected-data-importer.css'), 'utf8').trim().replace(/\r\n/g, '\n');
var expectedFile = read(fixture('include-files/expected-file-importer.css'), 'utf8').trim().replace(/\r\n/g, '\n');

it('should override imports and fire callback with file and contents', function(done) {
var bin = spawn(cli, [
Expand All @@ -653,7 +642,7 @@ describe('cli', function() {
]);

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

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

Expand All @@ -682,7 +671,7 @@ describe('cli', function() {
]);

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

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

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

Expand All @@ -724,7 +713,7 @@ describe('cli', function() {
]);

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

bin.once('close', function() {
assert.equal(read(dest, 'utf8').trim(), expected);
assert.equal(read(dest, 'utf8').trim(), expectedData);
fs.unlinkSync(dest);
done();
});
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/include-files/expected-data-importer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
div {
color: yellow; }

div {
color: yellow; }
2 changes: 2 additions & 0 deletions test/fixtures/include-files/expected-file-importer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* foo.scss */
/* bar.scss */
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 d1d9547

Please sign in to comment.