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

fix bundling; closes #3091 #3145

Closed
wants to merge 2 commits into from
Closed

fix bundling; closes #3091 #3145

wants to merge 2 commits into from

Conversation

boneskull
Copy link
Contributor

@boneskull boneskull commented Dec 12, 2017

This became too difficult to manage on the command-line.

What we're trying to do here is ship a version of the Buffer shim
which plays well with IE9/IE10. Browserify ships with a version which
does NOT play well, meaning we have to force it to use the version
we choose ([email protected]).

The fix is in two parts:

  1. insertGlobalVars option replaces usages of global Buffer with
    require('/path/to/mocha/node_modules/buffer').Buffer
  2. Any other module which explicitly requires buffer or, yes,
    buffer/, must also use /path/to/mocha/node_modules/buffer

If both of these are not in place, Browserify will use its own
version of the buffer shim.

@boneskull boneskull added the semver-patch implementation requires increase of "patch" version number; "bug fixes" label Dec 12, 2017
@boneskull
Copy link
Contributor Author

WIP pending some way of testing this so it doesn't happen again.

@boneskull
Copy link
Contributor Author

oh also this is necessary because —require in browserify doesn’t just “alias” stuff like the “browser” field of package.json which doesn’t work for any modules outside of your own sources anyway...

@boneskull
Copy link
Contributor Author

I started to wonder if this would be easier with Webpack then realized the build script I just wrote is likely smaller than even the most basic Webpack config 😬

@coveralls
Copy link

Coverage Status

Coverage remained the same at 89.95% when pulling c05db7b on issue/3091 into 4c0df70 on master.

@Bamieh
Copy link
Contributor

Bamieh commented Dec 12, 2017

@boneskull I am afraid of using webpack in mocha, mainly because it overrides the native module implementation of node, which might lead to really odd bugs for some end users. It also limits some possible features of mocha, such as using node VMs for isolating the runner from the user code.

@boneskull
Copy link
Contributor Author

@Bamieh We don't bundle for Node.js, only for the browser. So we don't need to worry about native modules getting blasted

@Bamieh
Copy link
Contributor

Bamieh commented Dec 12, 2017

@boneskull okay, i will test this at my work tomorrow because we have the appropriate testing environment for this issue.

This became too difficult to manage on the command-line.

What we're trying to do here is ship a version of the `Buffer` shim
which plays well with IE9/IE10.  Browserify ships with a version which
does NOT play well, meaning we have to force it to use the version
we choose (`[email protected]`).

The fix is in two parts:

1.  `insertGlobalVars` option replaces usages of global `Buffer` with
`require('/path/to/mocha/node_modules/buffer').Buffer`
2.  Any *other* module which explicitly requires `buffer` or, yes,
`buffer/`, must *also* use `/path/to/mocha/node_modules/buffer`

If *both* of these are not in place, Browserify will use its *own*
version of the `buffer` shim.
- this will assert that using `import` with `mocha.js` does not break
- fix: remove missing `Makefile` target; add `test-browser-esm` target
- fix: update invalid comments regarding running SauceLabs locally in
  `karma.conf`
- fix: break if attempting to run Karma on AppVeyor
- refactor Karma test flags to all use `MOCHA_TEST` env var
- a few reformats

Signed-off-by: Christopher Hiller <[email protected]>
@boneskull
Copy link
Contributor Author

@Bamieh I've automated it.. please review

KARMA := "node_modules/.bin/karma"
MOCHA := "bin/mocha"
NYC := "node_modules/.bin/nyc"

ifdef COVERAGE
define test_node
$(NYC) --no-clean --report-dir coverage/reports/$(1) $(MOCHA)
$(NYC) --no-clean --report-dir coverage/reports/$(1) $(MOCHA)
Copy link
Contributor Author

@boneskull boneskull Dec 12, 2017

Choose a reason for hiding this comment

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

from what I can tell the leading tab here is unnecessary

endef
else
test_node := $(MOCHA)
test_node := $(MOCHA)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

and here

@@ -4,6 +4,9 @@ var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var baseBundleDirpath = path.join(__dirname, '.karma');
var builder = require('./scripts/build');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this allows us to reuse the config in karma

.on('bundled', function (err, content) {
if (!err && bundleDirpath) {
if (err) {
throw err;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

apparently we were eating errors before... oops.

// write bundle to directory for debugging
fs.writeFileSync(path.join(bundleDirpath,
'bundle.' + Date.now() + '.js'), content);
fs.writeFileSync(path.join(bundleDirpath, 'mocha.' + Date.now() +
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this filename

if (cfg.sauceLabs) {
cfg.sauceLabs.testName = 'ESM Integration Tests';
cfg.browsers = ['chrome@latest'];
var launcher = cfg.customLaunchers['chrome@latest'];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry this is awkward; we need to update the dev scripts to ES2015+.

'chrome@latest': launcher
};
} else if (!env.TRAVIS) {
cfg.browsers = ['Chrome'];
Copy link
Contributor Author

@boneskull boneskull Dec 12, 2017

Choose a reason for hiding this comment

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

what other browsers currently support ES modules? @mochajs/core

Copy link
Contributor

Choose a reason for hiding this comment

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

in accordance to MDN

This feature is only just beginning to be implemented in browsers natively at this time. It is implemented in many transpilers, such as TypeScript and Babel, and bundlers such as Rollup and Webpack.

image

process.exit(0);
}
cfg.files = [
'test/browser-fixtures/esm.fixture.html',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can we force Karma to load a .js file as a module instead of script? I have no idea.

@@ -0,0 +1,7 @@
<script>
delete window.require;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this ensures that breakage will occur if the suffix on the distfile is bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see #3139 for what I mean

@coveralls
Copy link

Coverage Status

Coverage remained the same at 89.968% when pulling add3281 on issue/3091 into 575d83d on master.

@boneskull
Copy link
Contributor Author

You know, it might be a better idea to just land #3148 instead.

@Bamieh
Copy link
Contributor

Bamieh commented Dec 13, 2017

@boneskull i am totally in favor of #3148 instead of these hacks. But we should keep the tests you wrote if we agree on dropping support for IE9, IE10.

@boneskull boneskull closed this Dec 31, 2017
@boneskull
Copy link
Contributor Author

need to pull my tests out of here

@boneskull boneskull deleted the issue/3091 branch January 9, 2018 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch implementation requires increase of "patch" version number; "bug fixes"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants