Commit 41106f52 authored by Tasso Evangelista's avatar Tasso Evangelista

Fix tests bundling

parent 2e133525
......@@ -25,7 +25,10 @@
"test-main": "electron-mocha --require source-map-support/register app/main.specs.js",
"test-renderer": "electron-mocha --require source-map-support/register --renderer app/renderer.specs.js",
"test": "npm-run-all test-main test-renderer",
"coverage": "npm test -- -R scripts/istanbul-reporter",
"precoverage": "gulp build-coverage-tests --env=test",
"coverage-main": "electron-mocha --require source-map-support/register --reporter scripts/istanbul-reporter app/main.specs.js",
"coverage-renderer": "electron-mocha --require source-map-support/register --reporter scripts/istanbul-reporter app/renderer.specs.js",
"coverage": "npm-run-all coverage-main coverage-renderer",
"pree2e": "gulp build-e2e-tests --env=test",
"e2e": "mocha app/e2e.js.autogenerated --require source-map-support/register"
},
......
const gulp = require('gulp');
const jetpack = require('fs-jetpack');
const bundle = require('./bundle');
const istanbul = require('rollup-plugin-istanbul');
const createEntryFile = async(srcDir, matching, outputDir, entryFileName, rollupOptions) => {
const entryFileContent = srcDir.find('.', { matching })
.map((path) => `import './${ path.replace(/\\/g, '/') }';`)
.join('\n');
srcDir.write(entryFileName, entryFileContent);
await bundle(srcDir.path(entryFileName), outputDir.path(entryFileName), rollupOptions);
srcDir.remove(entryFileName);
};
gulp.task('build-unit-tests', ['environment'], () => {
const rollupOptions = {
rollupPlugins: [
istanbul({
exclude: ['**/*.spec.js', '**/*.specs.js'],
sourcemap: true,
}),
],
};
gulp.task('build-unit-tests', ['build-app'], async() => {
await bundle.many('src', 'background/*.spec.js', 'app/main.specs.js');
await bundle.many('src', ['*.spec.js', '!background/*.spec.js'], 'app/renderer.specs.js');
});
return Promise.all([
createEntryFile(jetpack.cwd('src'), 'background/*.spec.js',
jetpack.cwd('app'), 'main.specs.js', rollupOptions),
createEntryFile(jetpack.cwd('src'), ['*.spec.js', '!background/*.spec.js'],
jetpack.cwd('app'), 'renderer.specs.js', rollupOptions),
]);
gulp.task('build-coverage-tests', ['build-app'], async() => {
await bundle.many('src', 'background/*.spec.js', 'app/main.specs.js', { coverage: true });
await bundle.many('src', ['*.spec.js', '!background/*.spec.js'], 'app/renderer.specs.js', { coverage: true });
});
gulp.task('build-e2e-tests', ['build-app'], () => createEntryFile(
jetpack.cwd('src'), '*.e2e.js',
jetpack.cwd('app'), 'e2e.js.autogenerated'
));
gulp.task('build-e2e-tests', ['build-app'], async() => {
await bundle.many('src', '*.e2e.js', 'app/e2e.js.autogenerated');
});
const path = require('path');
const builtinModules = require('builtin-modules');
const appManifest = require('../package.json');
const jetpack = require('fs-jetpack');
const path = require('path');
const { rollup } = require('rollup');
const commonjs = require('rollup-plugin-commonjs');
const istanbul = require('rollup-plugin-istanbul');
const json = require('rollup-plugin-json');
const nodeResolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const appManifest = require('../package.json');
const cached = {};
module.exports = async(src, dest, { rollupPlugins = [] } = {}) => {
const bundle = async(src, dest, { coverage = false, rollupPlugins = [] } = {}) => {
const inputOptions = {
input: src,
external: [
......@@ -20,6 +22,12 @@ module.exports = async(src, dest, { rollupPlugins = [] } = {}) => {
cache: cached[src],
plugins: [
...rollupPlugins,
...(coverage ? [
istanbul({
exclude: ['**/*.spec.js', '**/*.specs.js'],
sourcemap: true,
}),
] : []),
json(),
nodeResolve(),
commonjs(),
......@@ -39,3 +47,19 @@ module.exports = async(src, dest, { rollupPlugins = [] } = {}) => {
cached[src] = bundle;
await bundle.write(outputOptions);
};
const bundleMany = async(srcDirPath, matching, dest, options) => {
const srcDir = jetpack.cwd(srcDirPath);
const src = srcDir.path(path.basename(dest));
const entryFileContent = (await srcDir.findAsync({ matching }))
.map((path) => `import './${ path.replace(/\\/g, '/') }';`)
.join('\n');
await jetpack.writeAsync(src, entryFileContent);
await bundle(src, dest, options);
await jetpack.removeAsync(src);
};
module.exports = bundle;
module.exports.many = bundleMany;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment