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

Commit d1d9547

Browse files
xzyfernschonni
authored andcommitted
Fix tests that have always been broke
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.
1 parent e3ed10b commit d1d9547

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

test/cli.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,31 +122,25 @@ describe('cli', function() {
122122

123123
describe('node-sass in.scss', function() {
124124
it('should compile a scss file', function(done) {
125-
process.chdir(fixture('simple'));
126-
127125
var src = fixture('simple/index.scss');
128126
var dest = fixture('simple/index.css');
129127
var bin = spawn(cli, [src, dest]);
130128

131129
bin.once('close', function() {
132130
assert(fs.existsSync(dest));
133131
fs.unlinkSync(dest);
134-
process.chdir(__dirname);
135132
done();
136133
});
137134
});
138135

139136
it('should compile a scss file to custom destination', function(done) {
140-
process.chdir(fixture('simple'));
141-
142137
var src = fixture('simple/index.scss');
143138
var dest = fixture('simple/index-custom.css');
144139
var bin = spawn(cli, [src, dest]);
145140

146141
bin.once('close', function() {
147142
assert(fs.existsSync(dest));
148143
fs.unlinkSync(dest);
149-
process.chdir(__dirname);
150144
done();
151145
});
152146
});
@@ -169,8 +163,6 @@ describe('cli', function() {
169163
});
170164

171165
it('should compile silently using the --quiet option', function(done) {
172-
process.chdir(fixture('simple'));
173-
174166
var src = fixture('simple/index.scss');
175167
var dest = fixture('simple/index.css');
176168
var bin = spawn(cli, [src, dest, '--quiet']);
@@ -183,14 +175,11 @@ describe('cli', function() {
183175
bin.once('close', function() {
184176
assert.equal(didEmit, false);
185177
fs.unlinkSync(dest);
186-
process.chdir(__dirname);
187178
done();
188179
});
189180
});
190181

191182
it('should still report errors with the --quiet option', function(done) {
192-
process.chdir(fixture('invalid'));
193-
194183
var src = fixture('invalid/index.scss');
195184
var dest = fixture('invalid/index.css');
196185
var bin = spawn(cli, [src, dest, '--quiet']);
@@ -202,7 +191,6 @@ describe('cli', function() {
202191

203192
bin.once('close', function() {
204193
assert.equal(didEmit, true);
205-
process.chdir(__dirname);
206194
done();
207195
});
208196
});
@@ -644,7 +632,8 @@ describe('cli', function() {
644632
describe('importer', function() {
645633
var dest = fixture('include-files/index.css');
646634
var src = fixture('include-files/index.scss');
647-
var expected = read(fixture('include-files/expected-importer.css'), 'utf8').trim().replace(/\r\n/g, '\n');
635+
var expectedData = read(fixture('include-files/expected-data-importer.css'), 'utf8').trim().replace(/\r\n/g, '\n');
636+
var expectedFile = read(fixture('include-files/expected-file-importer.css'), 'utf8').trim().replace(/\r\n/g, '\n');
648637

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

655644
bin.once('close', function() {
656-
assert.equal(read(dest, 'utf8').trim(), expected);
645+
assert.equal(read(dest, 'utf8').trim(), expectedData);
657646
fs.unlinkSync(dest);
658647
done();
659648
});
@@ -667,7 +656,7 @@ describe('cli', function() {
667656

668657
bin.once('close', function() {
669658
if (fs.existsSync(dest)) {
670-
assert.equal(read(dest, 'utf8').trim(), '');
659+
assert.equal(read(dest, 'utf8').trim(), expectedFile);
671660
fs.unlinkSync(dest);
672661
}
673662

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

684673
bin.once('close', function() {
685-
assert.equal(read(dest, 'utf8').trim(), expected);
674+
assert.equal(read(dest, 'utf8').trim(), expectedData);
686675
fs.unlinkSync(dest);
687676
done();
688677
});
@@ -695,7 +684,7 @@ describe('cli', function() {
695684
]);
696685

697686
bin.once('close', function() {
698-
assert.equal(read(dest, 'utf8').trim(), expected);
687+
assert.equal(read(dest, 'utf8').trim(), expectedData);
699688
fs.unlinkSync(dest);
700689
done();
701690
});
@@ -709,7 +698,7 @@ describe('cli', function() {
709698

710699
bin.once('close', function() {
711700
if (fs.existsSync(dest)) {
712-
assert.equal(read(dest, 'utf8').trim(), '');
701+
assert.equal(read(dest, 'utf8').trim(), expectedFile);
713702
fs.unlinkSync(dest);
714703
}
715704

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

726715
bin.once('close', function() {
727-
assert.equal(read(dest, 'utf8').trim(), expected);
716+
assert.equal(read(dest, 'utf8').trim(), expectedData);
728717
fs.unlinkSync(dest);
729718
done();
730719
});
@@ -737,7 +726,7 @@ describe('cli', function() {
737726
]);
738727

739728
bin.once('close', function() {
740-
assert.equal(read(dest, 'utf8').trim(), expected);
729+
assert.equal(read(dest, 'utf8').trim(), expectedData);
741730
fs.unlinkSync(dest);
742731
done();
743732
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
div {
2+
color: yellow; }
3+
4+
div {
5+
color: yellow; }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* foo.scss */
2+
/* bar.scss */

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)