Skip to content

Commit 504b073

Browse files
authored
chore: Separate buffered contents suites from basic tests (#38)
1 parent 8531275 commit 504b073

File tree

3 files changed

+85
-63
lines changed

3 files changed

+85
-63
lines changed

lib/helpers.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,7 @@ function writeSourceMaps(file, destPath, callback) {
232232
}
233233

234234
// Append source map comment
235-
if (comment) {
236-
file.contents = appendBuffer(file.contents, Buffer.from(comment));
237-
}
235+
file.contents = appendBuffer(file.contents, Buffer.from(comment));
238236

239237
callback(null, file, sourceMapFile);
240238
}

test/add.js

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ var sourceContent = fs.readFileSync(
1515
'utf-8'
1616
);
1717

18-
function makeFile() {
19-
return new File({
20-
cwd: __dirname,
21-
base: path.join(__dirname, 'assets'),
22-
path: path.join(__dirname, 'assets', 'helloworld.js'),
23-
contents: Buffer.from(sourceContent),
24-
});
25-
}
26-
2718
function makeSourcemap() {
2819
return {
2920
file: 'all.js',
@@ -40,20 +31,16 @@ function makeSourcemap() {
4031
};
4132
}
4233

43-
function makeFileWithInlineSourceMap() {
44-
var inline = convert.fromObject(makeSourcemap()).toComment();
45-
return new File({
46-
cwd: __dirname,
47-
base: path.join(__dirname, 'assets'),
48-
path: path.join(__dirname, 'assets', 'all.js'),
49-
contents: Buffer.from(
50-
'console.log("line 1.1"),console.log("line 1.2"),console.log("line 2.1"),console.log("line 2.2");\n' +
51-
inline
52-
),
53-
});
54-
}
55-
5634
describe('add', function () {
35+
function makeFile() {
36+
return new File({
37+
cwd: __dirname,
38+
base: path.join(__dirname, 'assets'),
39+
path: path.join(__dirname, 'assets', 'helloworld.js'),
40+
contents: Buffer.from(sourceContent),
41+
});
42+
}
43+
5744
it('errors if file argument is undefined', function (done) {
5845
sourcemaps.add(undefined, function (err) {
5946
expect(
@@ -84,14 +71,6 @@ describe('add', function () {
8471
});
8572
});
8673

87-
it('does not error if file argument is a Vinyl object with Buffer contents', function (done) {
88-
var file = makeFile();
89-
sourcemaps.add(file, function (err) {
90-
expect(err).toBeFalsy();
91-
done();
92-
});
93-
});
94-
9574
it('errors if file argument is a Vinyl object with contents from streamx.Readable', function (done) {
9675
var file = makeFile();
9776
file.contents = streamx.Readable.from([]);
@@ -115,6 +94,38 @@ describe('add', function () {
11594
done();
11695
});
11796
});
97+
});
98+
99+
describe('add (buffered contents)', function () {
100+
function makeFile() {
101+
return new File({
102+
cwd: __dirname,
103+
base: path.join(__dirname, 'assets'),
104+
path: path.join(__dirname, 'assets', 'helloworld.js'),
105+
contents: Buffer.from(sourceContent),
106+
});
107+
}
108+
109+
function makeFileWithInlineSourceMap() {
110+
var inline = convert.fromObject(makeSourcemap()).toComment();
111+
return new File({
112+
cwd: __dirname,
113+
base: path.join(__dirname, 'assets'),
114+
path: path.join(__dirname, 'assets', 'all.js'),
115+
contents: Buffer.from(
116+
'console.log("line 1.1"),console.log("line 1.2"),console.log("line 2.1"),console.log("line 2.2");\n' +
117+
inline
118+
),
119+
});
120+
}
121+
122+
it('does not error if file argument is a Vinyl object with Buffer contents', function (done) {
123+
var file = makeFile();
124+
sourcemaps.add(file, function (err) {
125+
expect(err).toBeFalsy();
126+
done();
127+
});
128+
});
118129

119130
it('calls back with the untouched file if file already has a sourcemap', function (done) {
120131
var sourceMap = {

test/write.js

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,6 @@ function makeSourceMap() {
2525
};
2626
}
2727

28-
function makeFile() {
29-
var file = new File({
30-
cwd: __dirname,
31-
base: path.join(__dirname, 'assets'),
32-
path: path.join(__dirname, 'assets', 'helloworld.js'),
33-
contents: Buffer.from(sourceContent),
34-
sourceMap: makeSourceMap(),
35-
});
36-
return file;
37-
}
38-
39-
function makeNestedFile() {
40-
var file = new File({
41-
cwd: __dirname,
42-
base: path.join(__dirname, 'assets'),
43-
path: path.join(__dirname, 'assets', 'dir1', 'dir2', 'helloworld.js'),
44-
contents: Buffer.from(sourceContent),
45-
});
46-
file.sourceMap = makeSourceMap();
47-
return file;
48-
}
49-
5028
function base64JSON(object) {
5129
return (
5230
'data:application/json;charset=utf-8;base64,' +
@@ -55,6 +33,17 @@ function base64JSON(object) {
5533
}
5634

5735
describe('write', function () {
36+
function makeFile() {
37+
var file = new File({
38+
cwd: __dirname,
39+
base: path.join(__dirname, 'assets'),
40+
path: path.join(__dirname, 'assets', 'helloworld.js'),
41+
contents: Buffer.from(sourceContent),
42+
sourceMap: makeSourceMap(),
43+
});
44+
return file;
45+
}
46+
5847
it('errors if file argument is undefined', function (done) {
5948
sourcemaps.write(undefined, function (err) {
6049
expect(
@@ -85,14 +74,6 @@ describe('write', function () {
8574
});
8675
});
8776

88-
it('does not error if file argument is a Vinyl object with Buffer contents', function (done) {
89-
var file = makeFile();
90-
sourcemaps.write(file, function (err) {
91-
expect(err).toBeFalsy();
92-
done();
93-
});
94-
});
95-
9677
it('errors if file argument is a Vinyl object with contents from streamx.Readable', function (done) {
9778
var file = makeFile();
9879
file.contents = streamx.Readable.from([]);
@@ -170,6 +151,38 @@ describe('write', function () {
170151
done(err);
171152
});
172153
});
154+
});
155+
156+
describe('write (buffered contents)', function () {
157+
function makeFile() {
158+
var file = new File({
159+
cwd: __dirname,
160+
base: path.join(__dirname, 'assets'),
161+
path: path.join(__dirname, 'assets', 'helloworld.js'),
162+
contents: Buffer.from(sourceContent),
163+
sourceMap: makeSourceMap(),
164+
});
165+
return file;
166+
}
167+
168+
function makeNestedFile() {
169+
var file = new File({
170+
cwd: __dirname,
171+
base: path.join(__dirname, 'assets'),
172+
path: path.join(__dirname, 'assets', 'dir1', 'dir2', 'helloworld.js'),
173+
contents: Buffer.from(sourceContent),
174+
sourceMap: makeSourceMap(),
175+
});
176+
return file;
177+
}
178+
179+
it('does not error if file argument is a Vinyl object with Buffer contents', function (done) {
180+
var file = makeFile();
181+
sourcemaps.write(file, function (err) {
182+
expect(err).toBeFalsy();
183+
done();
184+
});
185+
});
173186

174187
it('writes an inline sourcemap when no destPath', function (done) {
175188
var file = makeFile();

0 commit comments

Comments
 (0)