Browse Source

Add `runCommand` helper method to Neutrino.

v6-dev
Jarid Margolin 8 years ago
parent
commit
339d049956
  1. 27
      packages/neutrino/src/neutrino.js
  2. 11
      packages/neutrino/test/api_test.js

27
packages/neutrino/src/neutrino.js

@ -68,31 +68,22 @@ class Neutrino extends EventEmitter {
}
build(args) {
return this
.emitForAll('prebuild', args)
.then(() => this.builder())
.then(() => this.emitForAll('build', args));
return this.runCommand('build', args, () => this.builder());
}
start(args) {
return this
.emitForAll('prestart', args)
.then(() => {
const config = this.getWebpackOptions();
if (config.devServer) {
return this.devServer();
}
return this.watcher();
})
.then(() => this.emitForAll('start', args));
return this.runCommand('start', args, () => (this.getWebpackOptions().devServer ? this.devServer() : this.watcher()));
}
test(args) {
return this.runCommand('test', args);
}
runCommand(command, args = {}, fn) {
return this
.emitForAll('pretest', args)
.then(() => this.emitForAll('test', args));
.emitForAll(`pre${command}`, args)
.then(fn)
.then(() => this.emitForAll(command, args));
}
devServer() {

11
packages/neutrino/test/api_test.js

@ -94,6 +94,17 @@ test('import middleware for use', t => {
t.notDeepEqual(api.getWebpackOptions(), {});
});
test('command emits events around execution', async (t) => {
const api = new Neutrino();
const events = [];
api.on('prebuild', () => events.push('alpha'));
api.on('build', () => events.push('gamma'));
await api.runCommand('build', {}, () => events.push('beta'));
t.deepEqual(events, ['alpha', 'beta', 'gamma']);
});
test('creates a Webpack config', t => {
const api = new Neutrino();

Loading…
Cancel
Save