Browse Source

Adding rudimentary testing

v5.0.0-beta
Eli Perelman 8 years ago
parent
commit
47e9b520be
  1. 9
      .travis.yml
  2. 4
      package.json
  3. 3
      packages/neutrino/package.json
  4. 6
      packages/neutrino/src/neutrino.js
  5. 117
      packages/neutrino/test/api_test.js
  6. 1534
      packages/neutrino/yarn.lock
  7. 1945
      yarn.lock

9
.travis.yml

@ -0,0 +1,9 @@
cache:
yarn: true
directories:
- node_modules
install:
- yarn
- yarn bootstrap
script:
- yarn test

4
package.json

@ -18,9 +18,11 @@
"docs:deploy": "yarn docs:build && gh-pages --dist _book --remote upstream",
"docs:serve": "gitbook serve",
"release": "yarn release:pre && oao publish",
"release:pre": "oao prepublish"
"release:pre": "oao prepublish",
"test": "ava packages/*/test"
},
"devDependencies": {
"ava": "^0.18.2",
"changelog": "^1.0.7",
"gh-pages": "^0.12.0",
"gitbook-cli": "^2.3.0",

3
packages/neutrino/package.json

@ -27,8 +27,5 @@
"webpack-chain": "^1.4.2",
"webpack-dev-server": "^2.4.1",
"yargs": "^6.6.0"
},
"devDependencies": {
"ava": "^0.18.2"
}
}

6
packages/neutrino/src/neutrino.js

@ -38,11 +38,7 @@ class Neutrino extends EventEmitter {
}
getWebpackOptions() {
if (this.__configCache) {
return this.__configCache;
}
return this.__configCache = this.config.toConfig();
return this.config.toConfig();
}
emitForAll(eventName, payload) {

117
packages/neutrino/test/api_test.js

@ -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' }
}
]
}
]
}
});
});

1534
packages/neutrino/yarn.lock

File diff suppressed because it is too large

1945
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save