Eli Perelman
8 years ago
7 changed files with 2056 additions and 1562 deletions
@ -0,0 +1,9 @@ |
|||
cache: |
|||
yarn: true |
|||
directories: |
|||
- node_modules |
|||
install: |
|||
- yarn |
|||
- yarn bootstrap |
|||
script: |
|||
- yarn test |
@ -0,0 +1,117 @@ |
|||
import test from 'ava'; |
|||
import Neutrino from '../src/neutrino'; |
|||
|
|||
test('initializes with no arguments', t => { |
|||
t.notThrows(() => new Neutrino()); |
|||
}); |
|||
|
|||
test('initializes with options', t => { |
|||
t.notThrows(() => new Neutrino({ testing: true })); |
|||
}); |
|||
|
|||
test('initialization stores options', t => { |
|||
const options = { alpha: 'a', beta: 'b', gamma: 'c' }; |
|||
const api = new Neutrino(options); |
|||
|
|||
t.deepEqual(options, api.options); |
|||
}); |
|||
|
|||
test('creates an instance of webpack-chain', t => { |
|||
const api = new Neutrino(); |
|||
|
|||
t.is(typeof api.config.toConfig, 'function'); |
|||
}); |
|||
|
|||
test('middleware receives API instance', t => { |
|||
const api = new Neutrino(); |
|||
|
|||
api.use(n => t.is(n, api)); |
|||
}); |
|||
|
|||
test('middleware receives default options', t => { |
|||
const api = new Neutrino(); |
|||
|
|||
api.use((api, options) => { |
|||
t.deepEqual(options, {}); |
|||
}); |
|||
}); |
|||
|
|||
test('middleware receives options parameter', t => { |
|||
const api = new Neutrino(); |
|||
const defaults = { alpha: 'a', beta: 'b', gamma: 'c' }; |
|||
|
|||
api.use((api, options) => { |
|||
t.deepEqual(options, defaults); |
|||
}, defaults); |
|||
}); |
|||
|
|||
test('triggers promisified event handlers', t => { |
|||
const api = new Neutrino(); |
|||
|
|||
api.on('test', () => t.pass('test event triggered')); |
|||
api.emitForAll('test'); |
|||
}); |
|||
|
|||
test('events handle promise resolution', async t => { |
|||
const api = new Neutrino(); |
|||
|
|||
api.on('test', () => Promise.resolve('alpha')); |
|||
|
|||
const [value] = await api.emitForAll('test'); |
|||
|
|||
t.is(value, 'alpha'); |
|||
}); |
|||
|
|||
test('events handle promise rejection', async t => { |
|||
const api = new Neutrino(); |
|||
|
|||
api.on('test', () => Promise.reject(new Error('beta'))); |
|||
|
|||
const err = await t.throws(api.emitForAll('test')); |
|||
|
|||
t.is(err.message, 'beta'); |
|||
}); |
|||
|
|||
test('events handle multiple promise resolutions', async t => { |
|||
const api = new Neutrino(); |
|||
|
|||
api.on('test', () => Promise.resolve('alpha')); |
|||
api.on('test', () => Promise.resolve('beta')); |
|||
api.on('test', () => Promise.resolve('gamma')); |
|||
|
|||
const values = await api.emitForAll('test'); |
|||
|
|||
t.deepEqual(values, ['alpha', 'beta', 'gamma']); |
|||
}); |
|||
|
|||
test('creates a Webpack config', t => { |
|||
const api = new Neutrino(); |
|||
|
|||
api.use(api => { |
|||
api.config.module |
|||
.rule('compile') |
|||
.test(/\.js$/) |
|||
.include('src') |
|||
.loader('babel', 'babel-loader', { alpha: 'a', beta: 'b' }); |
|||
}); |
|||
|
|||
t.deepEqual(api.getWebpackOptions(), { |
|||
resolve: { modules: [], extensions: [] }, |
|||
resolveLoader: { modules: [] }, |
|||
plugins: [], |
|||
module: { |
|||
rules: [ |
|||
{ |
|||
test: /\.js$/, |
|||
include: ['src'], |
|||
use: [ |
|||
{ |
|||
loader: 'babel-loader', |
|||
options: { alpha: 'a', beta: 'b' } |
|||
} |
|||
] |
|||
} |
|||
] |
|||
} |
|||
}); |
|||
}); |
File diff suppressed because it is too large
File diff suppressed because it is too large
Loading…
Reference in new issue