Created
April 16, 2016 18:14
-
-
Save shawninder/a45923a48fb54a87c3c68f55efe872cd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'use strict' | |
var Stream = require('stream') | |
var test = require('tape') | |
var browserify = require('browserify') | |
var through = require('through2') | |
/** | |
* This plugin waits until browserify is done going through the require tree, | |
* then adds "SUCCESS!" to the array passed in as `results` in the options object | |
*/ | |
var myPlugin = function (brow, options) { | |
var wrap = brow.pipeline.get('wrap') | |
wrap.push(through(function (buf, enc, next) { | |
this.push(buf) | |
next() | |
}, function (next) { | |
// Mock some async work | |
setTimeout(function () { | |
options.results.push('SUCCESS!') | |
next() | |
}, 1000) | |
})) | |
} | |
test('plugin', function (t) { | |
console.log('test') | |
t.plan(1) | |
var brow = browserify() | |
var js = "console.log('hello world')" | |
var fileStub = new Stream.Readable() | |
fileStub.push(js, 'utf8') | |
fileStub.push(null) | |
var pluginResults = [] | |
brow.plugin(myPlugin, { | |
results: pluginResults | |
}) | |
brow.add(fileStub) | |
brow.bundle(function (err) { | |
if (err) { | |
t.fail('browserify errored: ' + err) | |
} else { | |
t.equal(pluginResults.length, 1, "plugin is done doing it's thing") | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment