-
-
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
Tests not run/reported using ES modules in browser #2816
Comments
Side notes:
Question -- if you add logging here: import MyLib from './lib.js';
const expect = chai.expect;
console.log("calling describe");
describe('test', function() {
console.log("inside describe callback"); ...and here: <script type="module" src="./test.js"></script>
<script>console.log("running Mocha");mocha.run()</script> ...What ends up in the console then? |
The Hence "MyLib.hypotenuse 8 15" is output in the console, but not the previous "MyLib.hypotenuse 5 12". I don't currently have access to Edge or Safari, and for some reason cannot manage to install Firefox 54 – I will try again. |
So, in that screenshot of the console logs "running Mocha" comes before the rest. The reason the tests aren't getting run and reported is, quite simply, that the test file is loading after the script tag that calls I don't happen to have a browser handy that supports the new module system (or whatever's specified of it so far, anyway...), but I'd guess from this behavior that modules are implicitly async or something along those lines. There might be something that can be specified to make a given set of scripts load in order even when some of them are modules, although I don't happen to know (I can pull up a lot of information on google; figuring out which information is current and whether it's going to be superseded next year is... harder). A sure-fire alternative would be to put |
Thank you! That got me there. Modules are defer by default. Regular inline scripts ignore defer ... but inline module scripts are deferred. Hence the following works (and also benefits from defer, and also reads cleanly!):
Produces: Hooray! |
Modules are defer by default. Regular inline scripts ignore defer ... but inline module scripts are deferred. mochajs/mocha#2816
I am trying – and failing – to use mocha to test ES modules in the browser.
I am using the following code:
test.html
:test.js
:lib.js
:I am running tests in Chrome 60.0.3100.0 (dev channel, using Experimental Web Platform flag, on Linux).
At first I got no tests run at all; going through issues, I discovered #2760 suggested adding
.run()
, which does invoke the test (per theconsole.log
), but still does not make the test appear in the browser:This test can be run from www.movable-type.co.uk/dev/mocha-es-modules (using Chrome 60 with flag).
The text was updated successfully, but these errors were encountered: