Skip to content

Commit

Permalink
Add tests for a full bankai build (#497)
Browse files Browse the repository at this point in the history
* Add tests for a full `bankai build`

* Fix lint

* add some logs to check appveyor output

* abababababababb

* angery

* Update split-require to fix Windows build

* read that dir?

* Revert "read that dir?"

This reverts commit b1a1eeb.
  • Loading branch information
goto-bus-stop authored Jun 1, 2018
1 parent 6ddc8d1 commit 4940fa3
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"send": "^0.16.1",
"server-router": "^6.0.0",
"sheetify": "^7.1.0",
"split-require": "^3.0.1",
"split-require": "^3.1.1",
"split2": "^2.2.0",
"strip-ansi": "^4.0.0",
"tfilter": "^1.0.1",
Expand All @@ -90,9 +90,11 @@
"choo": "^6.8.0",
"choo-devtools": "^2.3.3",
"choo-service-worker": "^2.4.0",
"read-file-tree": "^1.1.0",
"standard": "^11.0",
"tachyons": "^4.9.1",
"tape": "^4.8.0",
"tmp": "github:raszi/node-tmp#310c60f"
"tmp": "github:raszi/node-tmp#310c60f",
"write-file-tree": "^1.0.0"
}
}
94 changes: 94 additions & 0 deletions test/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
var writeFileTree = require('write-file-tree')
var spawn = require('child_process').spawn
var dedent = require('dedent')
var tape = require('tape')
var path = require('path')
var tmp = require('tmp')
var fs = require('fs')

var BIN_PATH = require.resolve('../bin')
function build (entry, output, cb) {
var args = [BIN_PATH, 'build', entry]
if (output) args.push(output)
var proc = spawn(process.execPath, args)
proc.on('error', cb)
proc.on('exit', function (code) {
if (code === 0) cb(null)
else cb(new Error(code))
})
return proc
}

tape('default output directory', function (assert) {
assert.plan(4)

var tmpDir = tmp.dirSync({ dir: path.join(__dirname, '../tmp'), unsafeCleanup: true })
assert.on('end', tmpDir.removeCallback)

writeFileTree.sync(tmpDir.name, {
'index.js': dedent`
var choo = require('choo')
var raw = require('choo/html/raw')
var app = choo()
app.route('/', function () {
return raw('<body>hello world</body>')
})
module.exports = app.mount('body')
`
})

build(path.join(tmpDir.name, '/index.js'), null, function (err) {
assert.ifError(err)
try {
assert.ok(fs.statSync(path.join(tmpDir.name, 'dist')).isDirectory())
} catch (err) {
assert.error(err, 'should have placed output in ./dist')
}
})
build(tmpDir.name, null, function (err) {
assert.ifError(err)
try {
assert.ok(fs.statSync(path.join(tmpDir.name, 'dist')).isDirectory())
} catch (err) {
assert.error(err, 'should have placed output in ./dist')
}
})
})

tape('outputs split bundles', function (assert) {
assert.plan(4)

var tmpDir = tmp.dirSync({ dir: path.join(__dirname, '../tmp'), unsafeCleanup: true })
assert.on('end', tmpDir.removeCallback)

writeFileTree.sync(tmpDir.name, {
'index.js': dedent`
var sr = require('split-require')
sr('./a')
sr('./b')
`,
'a.js': dedent`
module.exports = 'THIS IS A'
`,
'b.js': dedent`
module.exports = 'THIS IS B'
`
})

var output = path.join(tmpDir.name, 'dist')
build(tmpDir.name, output, function (err) {
assert.ifError(err)

// maybe these should use globs instead of hardcoded hashes
// eg glob.sync('dist/*/bundle.js')
assert.ok(fs.existsSync(path.join(output, '3372223d6e7a953f', 'bundle.js')))
assert.notEqual(read(path.join(output, '98abfdc06765c024', 'bundle-2.js')).indexOf('THIS IS A'), -1)
assert.notEqual(read(path.join(output, 'd045ba5484611349', 'bundle-3.js')).indexOf('THIS IS B'), -1)
})
})

function read (p) {
return fs.readFileSync(p, 'utf8')
}
3 changes: 3 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ require('./http')
require('./manifest')
require('./script')
require('./style')

// CLI tests
require('./build')

0 comments on commit 4940fa3

Please sign in to comment.