Unverified Commit 4940fa30 authored by Renée Kooi's avatar Renée Kooi Committed by GitHub
Browse files

Add tests for a full `bankai build` (#497)

* 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 b1a1eeb96495d175cf88bd5d2ad956fba429f963.
parent 6ddc8d18
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')
}
......@@ -8,3 +8,6 @@ require('./http')
require('./manifest')
require('./script')
require('./style')
// CLI tests
require('./build')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment