Skip to content

Commit 6653d38

Browse files
committed
fix(unassertify): should not transform JSON file
1 parent 3395666 commit 6653d38

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
'use strict';
1212

13+
var path = require('path');
1314
var through = require('through');
1415
var esprima = require('esprima');
1516
var escodegen = require('escodegen');
@@ -77,6 +78,10 @@ function shouldProduceSourceMap (options) {
7778
}
7879

7980
module.exports = function unassertify (filepath, options) {
81+
if (path.extname(filepath) === '.json') {
82+
return through();
83+
}
84+
8085
var data = '',
8186
stream = through(write, end);
8287

test/fixtures/data.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"foo": "baz",
3+
"hoge": "fuga"
4+
}

test/test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,35 @@ describe('just remove assertions if debug: false', function() {
151151
file.pipe(stream);
152152
});
153153
});
154+
155+
156+
describe('when incoming code is JSON file', function() {
157+
var stream = unassertify(
158+
process.cwd() + '/test/fixtures/data.json',
159+
{
160+
_flags: {
161+
basedir: '/absolute/path/to',
162+
cache: {},
163+
debug: true
164+
}
165+
}
166+
);
167+
168+
it('should return a stream', function() {
169+
assert(stream instanceof Stream);
170+
});
171+
172+
it('should not transform', function(done) {
173+
var output = '', file;
174+
stream.on('data', function(buf) {
175+
output += buf;
176+
});
177+
stream.on('end', function() {
178+
var expected = fs.readFileSync('test/fixtures/data.json', 'utf8');
179+
assert.equal(output, expected);
180+
done();
181+
});
182+
file = fs.createReadStream('test/fixtures/data.json');
183+
file.pipe(stream);
184+
});
185+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy