Skip to content

Commit

Permalink
Merge pull request #26 from tmcw/tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
hughsk committed Dec 29, 2014
2 parents 1f2482f + 3c5d1b1 commit 9c946dd
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ function json(bundles, callback) {
})

modules = modules.filter(function(module) {
return !isEmpty(module)
return module && !isEmpty(module)
})

if (!modules.length) return

var browserifyModules = modules.filter(fromBrowserify(true))
var otherModules = modules.filter(function(module) {
if (path.basename(module.id) === '_empty.js') return false
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"prepublish": "mkdir -p build && npm run browserify && npm run rework && npm run bundle-demo",
"browserify": "browserify src/index.js | uglifyjs -c 2> /dev/null > build/bundle.js",
"bundle-demo": "node lib/bundle-demo > index.html",
"build-fixture": "browserify --full-paths ./test/fixture/index.js > ./test/fixture/bundle.js && browserify ./test/fixture/index.js > ./test/fixture/bundle-no-full.js",
"demo": "npm run prepublish && opener index.html",
"rework": "node lib/bundle-css > build/style.css"
},
Expand Down Expand Up @@ -45,6 +46,7 @@
"marked": "^0.3.2",
"prettysize": "0.0.3",
"rework": "^0.20.2",
"tape": "^3.0.3",
"uglify-js": "^2.4.15"
},
"keywords": [
Expand Down
4 changes: 4 additions & 0 deletions test/fixture/bundle-no-full.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/fixture/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixture/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 42
21 changes: 21 additions & 0 deletions test/json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var json = require('../').json
var test = require('tape')
var fs = require('fs')

test('json', function(t) {
json([fs.readFileSync(__dirname + '/fixture/bundle.js', 'utf8')], function(err, res) {
t.notOk(err)
t.ok(res)
t.equal(res.name, 'index.js', 'main file name')
t.equal(res.children.length, 1, '.children.length')
t.end()
})
})

test('json missing --full-paths', function(t) {
json([fs.readFileSync(__dirname + '/fixture/bundle-no-full.js', 'utf8')], function(err, res) {
t.ok(err, 'returns error')
t.notOk(res, 'does not return result')
t.end()
})
})

0 comments on commit 9c946dd

Please sign in to comment.