Skip to content

Commit 223fbdf

Browse files
rweinbergerSophie Saskin
authored andcommitted
feat(bson): test bson in browser
Add support for running bson tests in the browser via Karma. Fixes NODE-1504
1 parent 3620ef8 commit 223fbdf

22 files changed

+5621
-1443
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ cache:
88
directories:
99
- node_modules
1010

11+
before_script:
12+
- "sudo chown root /opt/google/chrome/chrome-sandbox"
13+
- "sudo chmod 4755 /opt/google/chrome/chrome-sandbox"
14+
- "npm run build"
15+
1116
node_js:
1217
- 4
1318
- 6

karma.conf.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use strict';
2+
3+
const scenariosPlugin = require('./tools/scenarios-plugin');
4+
const jsonPlugin = require('rollup-plugin-json');
5+
const nodeGlobals = require('rollup-plugin-node-globals');
6+
const nodeBuiltins = require('rollup-plugin-node-builtins');
7+
const commonjs = require('rollup-plugin-commonjs');
8+
const nodeResolve = require('rollup-plugin-node-resolve');
9+
10+
const rollupPlugins = [
11+
scenariosPlugin(),
12+
nodeResolve({
13+
browser: true,
14+
preferBuiltins: false
15+
}),
16+
commonjs({
17+
namedExports: {
18+
'node_modules/buffer/index.js': ['isBuffer']
19+
}
20+
}),
21+
nodeBuiltins(),
22+
nodeGlobals(),
23+
jsonPlugin()
24+
];
25+
26+
const rollupConfig = {
27+
plugins: rollupPlugins,
28+
output: {
29+
format: 'iife',
30+
name: 'BSONtest',
31+
exports: 'named'
32+
}
33+
};
34+
35+
const onwarn = warning => {
36+
if (warning.code === 'CIRCULAR_DEPENDENCY' || warning.code === 'EVAL') return;
37+
console.warn(warning.toString());
38+
};
39+
40+
rollupConfig.onwarn = onwarn;
41+
42+
// Karma configuration
43+
// Generated on Thu Jun 28 2018 14:24:01 GMT-0400 (EDT)
44+
45+
module.exports = function(config) {
46+
config.set({
47+
basePath: '',
48+
frameworks: ['mocha'],
49+
reporters: ['mocha'],
50+
files: [{ pattern: 'test/node/!(bson_node_only_test).js', watched: false }],
51+
preprocessors: {
52+
'test/node/!(bson_node_only_test).js': 'rollup'
53+
},
54+
rollupPreprocessor: rollupConfig,
55+
port: 9876,
56+
colors: true,
57+
logLevel: config.LOG_INFO,
58+
autoWatch: true,
59+
browsers: ['ChromeHeadless'],
60+
singleRun: true,
61+
concurrency: Infinity
62+
});
63+
};

0 commit comments

Comments
 (0)