-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
WIP pending some way of testing this so it doesn't happen again. |
oh also this is necessary because |
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 😬 |
@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. |
@Bamieh We don't bundle for Node.js, only for the browser. So we don't need to worry about native modules getting blasted |
@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 (`buffer@4.9.x`). 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 <boneskull@boneskull.com>
c05db7b
to
add3281
Compare
@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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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() + |
There was a problem hiding this comment.
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']; |
There was a problem hiding this comment.
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']; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process.exit(0); | ||
} | ||
cfg.files = [ | ||
'test/browser-fixtures/esm.fixture.html', |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
You know, it might be a better idea to just land #3148 instead. |
@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. |
need to pull my tests out of here |
This became too difficult to manage on the command-line.
What we're trying to do here is ship a version of the
Buffer
shimwhich 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 (
buffer@4.9.x
).The fix is in two parts:
insertGlobalVars
option replaces usages of globalBuffer
withrequire('/path/to/mocha/node_modules/buffer').Buffer
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.