-
-
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
Stop using all global vars in browser entry #4746
Conversation
c2290f0
to
552c208
Compare
@PaperStrike thanks. I had a look, but havent understood everything, yet. It seems to be quite messy, and I don't want to turn it even worse. In our Node code (for npm), these functions are static on the Not all these variables have to be set, only a subset depending on which interface (eg. |
I have no idea. It's not written by me. By the comment, it's for import like in node. However, I can't get this running in real-browsers (bundled with That's all I know. If this is actually broken, delete / skip the required token test case for browser, export mocha without reading these globals, then everyone would be happy. Or if I understand the situation correctly, we need a brave warrior to do a deep refactor, to better fix this. |
It's in |
@juergba Thanks. I know this and the problem is acturally when mocha invokes the |
@PaperStrike There is this special test test\unit\required-tokens.spec.js already mentioned in browser-entry.js. Without this test, some other browser tests will fail running on @mantoni can I ask you a question, please? |
@juergba Mocha cannot be browserified anymore since v8. I don't know why this exists, but if it explicitly mentions browserify, I guess it's legacy. |
I made a aggresive commit that removes the
Forget about it. My fault. |
@mantoni thank you |
It will be better to have And we can (just tested) achieve this by copying the values from Object.keys(Mocha)
.filter(function(key) {
return !(key in mocha);
})
.forEach(function(key) {
mocha[key] = Mocha[key];
});
module.exports = mocha; The problem is the test cases (tests in this repo, I mean). It's hard to pass them. I tried to put a |
@PaperStrike thank you so far, you are a big help on this issue. I feel a little better, but still this bundling story is so fuzzy. Why do we need
So at first sight I like the idea to removing the
I haven't understood, why browser-entry.js in the setup makes the test pass. Is your last proposition as an addition to the current PR? Or standalone? |
To find the cause, I shortened
Yeah. Earlier this day I found mocha in Node exports
"The problem" means we will have tests failed, if we use the code right above that sentence, without doing other stuff like removing Sorry I didn't made it clear.
Modules (without side effects) are the future. I like writting tests like: import { describe, it } from 'mocha';
describe(...); which is not possible in browsers. And I wish one day mocha exports functions to global only when the user requires (with an option, maybe). It's not possible for now, and the first step to modularize would be the users being able to write like using modules.
The "deep refactor" may be to export |
Ok, we are quite close now.
Why do you prefer having it on Edit: re deep refactor: no, I don't know anybody. I hate browsers. |
I can use it, if the code in #4746 (comment) were applied. If it's applied I can write tests like: <script src="link/to/mocha/bundle"></script>
<script>
mocha.setup('bdd');
window.addEventListener('load', () => {
mocha.run();
});
</script>
<!-- Can also link to external script files -->
<script type="module" id="my-real-tests">
import { describe, it } from 'link/to/mocha/bundle';
describe('group', () => {
it('pass', () => {});
});
</script> Sorry again for my expressions. The "not possible in browsers" I mean it's not possible to use mocha in this way in browsers as of now. |
Anyway, it seems a bit off topic now. If you prefer to delete the required-tokens test case and agree to put a |
Ok then, add #4746 (comment) to this PR. |
The |
Yeah, that's why I mentioned "The problem is the test cases", "tried to put a I'm in UTC+8 and sorry I am out for some hours. |
@juergba After running some own tests in real browsers without bundling beforehead, now I agreed to keep this PR as is.. Been using these TypeScript, bundlers for sometime, damn me forget the browsers don't support such syntax at all. I can get it work, but I need bundlers. Users using bundlers to run tests are the minority, I believe. Sorry for wasting your time. |
PR description updated. |
Regarding removed test case required-tokens.spec.js: we still have integration tests covering this |
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.
@PaperStrike thank you for this PR!
Description of the Change
mocha/browser-entry.js
Line 219 in 4860738
is causing chrome to show a
'window.webkitStorageInfo' is deprecated
warning.Using these properties may affect mocha's own functionalities, too. (See #4740)
This PR makes mocha export without using these globals.
Alternate Designs
Why should this be in core?
This bug exists in mocha.
Benefits
No
'window.webkitStorageInfo' is deprecated
warning when initializing.No risk of breaking mocha's functionalities.
Possible Drawbacks
Applicable issues
Fixes #4745.
Fixes #4740.
Is this a breaking change (major release)? no
Is it an enhancement (minor release)? no
Is it a bug fix, or does it not impact production code (patch release)? yes