Skip to content

Commit

Permalink
Add custom karma rollup plugin and use it to bundle browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Munter authored and boneskull committed May 27, 2020
1 parent ba2b880 commit 579bf5a
Show file tree
Hide file tree
Showing 4 changed files with 317 additions and 86 deletions.
33 changes: 13 additions & 20 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const fs = require('fs');
const path = require('path');
const os = require('os');
const rollupPlugin = require('./scripts/karma-rollup-plugin');
const baseBundleDirpath = path.join(__dirname, '.karma');

const hostname = os.hostname();
Expand All @@ -18,31 +19,23 @@ const browserPlatformPairs = {
module.exports = config => {
let bundleDirpath;
const cfg = {
frameworks: ['browserify', 'mocha'],
frameworks: ['rollup', 'mocha'],
files: [
// we use the BDD interface for all of the tests that
// aren't interface-specific.
'test/unit/*.spec.js'
],
preprocessors: {
'test/**/*.js': ['browserify']
},
browserify: {
debug: true,
configure: function configure(b) {
b.on('bundled', (err, content) => {
if (err) {
throw err;
}
if (bundleDirpath) {
// write bundle to directory for debugging
fs.writeFileSync(
path.join(bundleDirpath, `mocha.${Date.now()}.js`),
content
);
}
});
}
plugins: [
'karma-mocha',
'karma-mocha-reporter',
'karma-sauce-launcher',
'karma-chrome-launcher',
rollupPlugin
],
rollup: {
configFile: 'rollup.config.js',
include: ['test/**'],
bundlePath: bundleDirpath
},
reporters: ['mocha'],
colors: true,
Expand Down

0 comments on commit 579bf5a

Please sign in to comment.