-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #64
- Loading branch information
Showing
5 changed files
with
206 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
var test = require('tap').test; | ||
var spawn = require('child_process').spawn; | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
|
||
var files = { | ||
main: path.join(__dirname, '/files/main.js'), | ||
foo: path.join(__dirname, '/files/foo.js'), | ||
bar: path.join(__dirname, '/files/bar.js') | ||
}; | ||
var sources = { | ||
main: fs.readFileSync(files.main, 'utf8'), | ||
foo: fs.readFileSync(files.foo, 'utf8'), | ||
bar: fs.readFileSync(files.bar, 'utf8') | ||
}; | ||
|
||
test('bin', function (t) { | ||
t.plan(3); | ||
|
||
var ps = spawn(process.execPath, [ | ||
path.resolve(__dirname, '../bin/cmd.js'), '-', | ||
], { | ||
cwd: __dirname + '/files' | ||
}); | ||
|
||
var input = fs.createReadStream(files.main); | ||
input.pipe(ps.stdin); | ||
|
||
var src = ''; | ||
var err = ''; | ||
ps.stdout.on('data', function (buf) { src += buf }); | ||
ps.stderr.on('data', function (buf) { err += buf }); | ||
|
||
ps.on('exit', function (code) { | ||
t.equal(code, 0); | ||
t.equal(err, ''); | ||
|
||
var rows = JSON.parse(src); | ||
t.same(rows.sort(cmp), [ | ||
{ | ||
id: __dirname + '/files/_stream_1.js', | ||
file: __dirname + '/files/_stream_1.js', | ||
source: sources.main, | ||
entry: true, | ||
deps: { './foo': files.foo } | ||
}, | ||
{ | ||
id: files.foo, | ||
file: files.foo, | ||
source: sources.foo, | ||
deps: { './bar': files.bar } | ||
}, | ||
{ | ||
id: files.bar, | ||
file: files.bar, | ||
source: sources.bar, | ||
deps: {} | ||
} | ||
].sort(cmp)); | ||
}); | ||
}); | ||
|
||
function cmp (a, b) { return a.id < b.id ? -1 : 1 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
var parser = require('../'); | ||
var test = require('tap').test; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var through = require('through2'); | ||
|
||
var files = { | ||
main: path.join(__dirname, '/files/_stream_1.js'), | ||
foo: path.join(__dirname, '/files/foo.js'), | ||
bar: path.join(__dirname, '/files/bar.js'), | ||
extra: path.join(__dirname, '/files/extra.js') | ||
}; | ||
var sources = { | ||
foo: fs.readFileSync(files.foo, 'utf8'), | ||
bar: fs.readFileSync(files.bar, 'utf8'), | ||
extra: fs.readFileSync(files.extra, 'utf8'), | ||
main: "console.log(require('./foo')(5)); require('./extra.js')" | ||
}; | ||
|
||
test('source fake stream', function (t) { | ||
t.plan(1); | ||
var p = parser({ basedir: __dirname + '/files' }); | ||
var s = through(); | ||
p.end(s); | ||
s.end(sources.main); | ||
|
||
var rows = []; | ||
p.on('data', function (row) { rows.push(row) }); | ||
p.on('end', function () { | ||
t.same(rows.sort(cmp), [ | ||
{ | ||
id: files.main, | ||
file: files.main, | ||
source: sources.main, | ||
entry: true, | ||
deps: { './foo': files.foo, './extra.js': files.extra } | ||
}, | ||
{ | ||
id: files.foo, | ||
file: files.foo, | ||
source: sources.foo, | ||
deps: { './bar': files.bar } | ||
}, | ||
{ | ||
id: files.bar, | ||
file: files.bar, | ||
source: sources.bar, | ||
deps: {} | ||
}, | ||
{ | ||
id: files.extra, | ||
file: files.extra, | ||
source: sources.extra, | ||
deps: {} | ||
}, | ||
].sort(cmp)); | ||
}); | ||
}); | ||
|
||
function cmp (a, b) { return a.id < b.id ? -1 : 1 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
var parser = require('../'); | ||
var test = require('tap').test; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var through = require('through2'); | ||
|
||
var files = { | ||
main: path.join(__dirname, '/files/main.js'), | ||
foo: path.join(__dirname, '/files/foo.js'), | ||
bar: path.join(__dirname, '/files/bar.js'), | ||
extra: path.join(__dirname, '/files/extra.js') | ||
}; | ||
var sources = { | ||
foo: fs.readFileSync(files.foo, 'utf8'), | ||
bar: fs.readFileSync(files.bar, 'utf8'), | ||
extra: fs.readFileSync(files.extra, 'utf8'), | ||
main: "console.log(require('./foo')(5)); require('./extra.js')" | ||
}; | ||
|
||
test('source real stream', function (t) { | ||
t.plan(1); | ||
var p = parser(); | ||
var s = through(); | ||
p.end({ | ||
file: files.main, | ||
source: s | ||
}); | ||
s.end(sources.main); | ||
|
||
var rows = []; | ||
p.on('data', function (row) { rows.push(row) }); | ||
p.on('end', function () { | ||
t.same(rows.sort(cmp), [ | ||
{ | ||
id: files.main, | ||
file: files.main, | ||
source: sources.main, | ||
entry: true, | ||
deps: { './foo': files.foo, './extra.js': files.extra } | ||
}, | ||
{ | ||
id: files.foo, | ||
file: files.foo, | ||
source: sources.foo, | ||
deps: { './bar': files.bar } | ||
}, | ||
{ | ||
id: files.bar, | ||
file: files.bar, | ||
source: sources.bar, | ||
deps: {} | ||
}, | ||
{ | ||
id: files.extra, | ||
file: files.extra, | ||
source: sources.extra, | ||
deps: {} | ||
}, | ||
].sort(cmp)); | ||
}); | ||
}); | ||
|
||
function cmp (a, b) { return a.id < b.id ? -1 : 1 } |