Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup and babel in build pipeline #4293

Merged
merged 24 commits into from Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
65a61ed
Make browser specific TTY interop explicit instead of a magic bundlin…
Munter Mar 29, 2020
8175492
Remove unnessessary browserify ignore of cli related files and chokidar
Munter Mar 29, 2020
4ccc4c2
Extract lookupFiles from utils to avoid node dependencies in browser …
Munter Mar 29, 2020
8d689fc
Replace browserify with rollup for main library bundling
Munter Mar 30, 2020
b0ec4b9
Polyfill global to check if IE11 will start working
Munter Mar 30, 2020
606f4dd
Don't include esm-utils in browser build. Modern syntax breaks IE
Munter Mar 31, 2020
d25a7cc
Remove duplicate browserify configuration in karma config file
Munter Apr 1, 2020
5c4b56a
Add custom karma rollup plugin and use it to bundle browser tests
Munter May 17, 2020
5e229d4
add process.listeners impl
boneskull May 26, 2020
fe283dd
Extract browser-only helper functions from shared utils file to their…
Munter Jun 12, 2020
7fcd39a
Add browserslist, babel, babel-preset-env and prepare for modern js
Munter Jun 12, 2020
eedd4e6
Add mocha.js.map to npm distributed files
Munter Jun 20, 2020
822515a
Use util function to check if we're running in a browser
Munter Jun 20, 2020
052acb6
Improve documentation of self-built karma-rollup-plugin
Munter Jun 20, 2020
eaf7220
Renamed lib/cli/lookupFiles.js to lib/cli/lookup-files.js
Munter Jun 20, 2020
1a6176c
Clean up rollup config
Munter Jun 20, 2020
ac4aa46
Kebab case file names
Munter Jun 20, 2020
b8c30ed
Remove last traces of unused browserify
Munter Jun 20, 2020
5b08dec
fix bundle path under win32
boneskull Jun 30, 2020
ea59f88
do not run bundle visualizer in CI
boneskull Jul 1, 2020
6be6606
Remove use of mocha.opts in browser testing
Munter Jul 2, 2020
207ef63
Replace package.json browser field with manual rollup exclusion and a…
Munter Jul 2, 2020
f01aeba
Improved naming of rollup plugin to pick values from package.json
Munter Jul 2, 2020
7739689
Revert "Replace package.json browser field with manual rollup exclusi…
Munter Jul 2, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions .browserslistrc
@@ -0,0 +1,12 @@
node >= 10
last 2 Chrome versions
last 2 Edge versions
last 2 Firefox versions
last 2 Safari versions
last 2 Opera versions
Munter marked this conversation as resolved.
Show resolved Hide resolved
unreleased Chrome versions
unreleased Edge versions
unreleased Firefox versions
unreleased Safari versions
unreleased Opera versions
IE 11
7 changes: 4 additions & 3 deletions .eslintrc.yml
Expand Up @@ -5,8 +5,9 @@ extends:
env:
node: true
browser: true
es6: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed with ecmaVersion below?

parserOptions:
ecmaVersion: 5
ecmaVersion: 2018
ecmaFeatures:
jsx: false
sourceType: script
Expand Down Expand Up @@ -37,8 +38,6 @@ overrides:
- 'test/integration/helpers.js'
- 'test/integration/options/watch.spec.js'
- 'test/node-unit/**/*.js'
parserOptions:
ecmaVersion: 2018
env:
browser: false
rules:
Expand All @@ -48,6 +47,8 @@ overrides:
property: 'assign'
- files:
- esm-utils.js
- rollup.config.js
- scripts/rollup-manifest-filter.js
parserOptions:
ecmaVersion: 2018
sourceType: module
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -3,9 +3,13 @@ docs/_site
docs/_dist
docs/images/supporters
mocha.js
mocha.js.map
Munter marked this conversation as resolved.
Show resolved Hide resolved
.karma/
!lib/mocha.js

# Bundle debugging
stats.html

#########################################
# NON-MOCHA STUFF GOES BELOW THIS THING #
#########################################
Expand Down
13 changes: 11 additions & 2 deletions browser-entry.js
Expand Up @@ -9,6 +9,8 @@

process.stdout = require('browser-stdout')({label: false});

var parseQuery = require('./lib/browser/parse-query');
var highlightTags = require('./lib/browser/highlight-tags');
var Mocha = require('./lib/mocha');

/**
Expand Down Expand Up @@ -77,6 +79,13 @@ process.on = function(e, fn) {
}
};

process.listeners = function(e) {
if (e === 'uncaughtException') {
return uncaughtExceptionHandlers;
}
return [];
};

// The BDD UI is registered by default, but no UI will be functional in the
// browser without an explicit call to the overridden `mocha.ui` (see below).
// Ensure that this default UI does not expose its methods to the global scope.
Expand Down Expand Up @@ -155,7 +164,7 @@ mocha.run = function(fn) {
var options = mocha.options;
mocha.globals('location');

var query = Mocha.utils.parseQuery(global.location.search || '');
var query = parseQuery(global.location.search || '');
if (query.grep) {
mocha.grep(query.grep);
}
Expand All @@ -174,7 +183,7 @@ mocha.run = function(fn) {
document.getElementById('mocha') &&
options.noHighlighting !== true
) {
Mocha.utils.highlightTags('code');
highlightTags('code');
}
if (fn) {
fn(err);
Expand Down
45 changes: 13 additions & 32 deletions karma.conf.js
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,43 +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.ignore('chokidar')
.ignore('fs')
.ignore('glob')
.ignore('path')
.ignore('supports-color')
.ignore('./lib/esm-utils.js')
.ignore('./lib/cli/*.js')
.ignore('./lib/nodejs/serializer.js')
.ignore('./lib/nodejs/worker.js')
.ignore('./lib/nodejs/buffered-worker-pool.js')
.ignore('./lib/nodejs/parallel-buffered-runner.js')
.ignore('./lib/nodejs/reporters/parallel-buffered.js')
.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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

},
reporters: ['mocha'],
colors: true,
Munter marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
39 changes: 39 additions & 0 deletions lib/browser/highlight-tags.js
@@ -0,0 +1,39 @@
'use strict';

/**
* Highlight the given string of `js`.
*
* @private
* @param {string} js
* @return {string}
*/
function highlight(js) {
return js
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
.replace(/('.*?')/gm, '<span class="string">$1</span>')
.replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
.replace(/(\d+)/gm, '<span class="number">$1</span>')
.replace(
/\bnew[ \t]+(\w+)/gm,
'<span class="keyword">new</span> <span class="init">$1</span>'
)
.replace(
/\b(function|new|throw|return|var|if|else)\b/gm,
'<span class="keyword">$1</span>'
);
}

/**
* Highlight the contents of tag `name`.
*
* @private
* @param {string} name
*/
module.exports = function highlightTags(name) {
var code = document.getElementById('mocha').getElementsByTagName(name);
for (var i = 0, len = code.length; i < len; ++i) {
code[i].innerHTML = highlight(code[i].innerHTML);
}
};
24 changes: 24 additions & 0 deletions lib/browser/parse-query.js
@@ -0,0 +1,24 @@
'use strict';

/**
* Parse the given `qs`.
*
* @private
* @param {string} qs
* @return {Object<string, string>}
*/
module.exports = function parseQuery(qs) {
return qs
.replace('?', '')
.split('&')
.reduce(function(obj, pair) {
var i = pair.indexOf('=');
var key = pair.slice(0, i);
var val = pair.slice(++i);

// Due to how the URLSearchParams API treats spaces
obj[key] = decodeURIComponent(val.replace(/\+/g, '%20'));

return obj;
}, {});
};
13 changes: 0 additions & 13 deletions lib/browser/tty.js

This file was deleted.

4 changes: 2 additions & 2 deletions lib/cli/collect-files.js
Expand Up @@ -4,8 +4,8 @@ const path = require('path');
const ansi = require('ansi-colors');
const debug = require('debug')('mocha:cli:run:helpers');
const minimatch = require('minimatch');
const utils = require('../utils');
const {NO_FILES_MATCH_PATTERN} = require('../errors').constants;
const lookupFiles = require('./lookup-files');

/**
* Exports a function that collects test files from CLI parameters.
Expand All @@ -27,7 +27,7 @@ module.exports = ({ignore, extension, file, recursive, sort, spec} = {}) => {
spec.forEach(arg => {
let newFiles;
try {
newFiles = utils.lookupFiles(arg, extension, recursive);
newFiles = lookupFiles(arg, extension, recursive);
} catch (err) {
if (err.code === NO_FILES_MATCH_PATTERN) {
unmatched.push({message: err.message, pattern: err.pattern});
Expand Down