-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add modulesWithSideEffectsInSrcFiles to allow esm in srcFiles #60
base: main
Are you sure you want to change the base?
Conversation
0d568a9
to
84fcd90
Compare
Can you help me understand why this is useful? Needing ES modules loaded that you never import seems quite unusual. A link to a repo with a minimal reproducible example of the problem you're trying to solve might help. I'm not necessarily opposed to this feature, but I do think the name will cause confusion. I think most users would reasonably assume they need |
This is useful when the module code has side effects. But there are more complex scenarios where script and modules code needs even to be interleaved. Complex minimal example// <script src=baseinfrastructure.js defer>
function registerControls(){ }
// <script src=basecontrol.js defer>
class control{ /* much code */}
registerControls(control);
// <script src=interactionControl.mjs type=module> migrated code
class interactionControl extends control{ /* much code */}
registerControls(interactionControl);
window.interactionControl = interactionControl; // compatibility layer
// <script src=button.js defer> old code
class button extends interactionControl{ /* much code */}
registerControls(button); A further problem is that you have to use
Yeah you are right. |
@sgravrock
|
Yes, but not right away. I don't currently have a machine that runs Safari 15, so I'd have to rig something up to run on Saucelabs. Not that big a deal but it'll have to wait for the next time when I have a solid block of time for Jasmine.
Why |
Because it is executed at the exact same timing as modules which are also loaded deferred. <script src="a.js" defer></script>
<script src="b.js" type=module></script>
<script src="c.js" defer></script> Which is crucial for having the side effect effective. |
That would be awesome. |
| Can you estimate if the referenced safari bug is still relevant? Looks like it's still needed. The bug was fixed in Safari 16, but Jasmine still supports Safari 15. I'm considering a change to the browser support policy to deal with the difficulty of testing on multiple versions of Safari. But as of today Safari 15 is a fully supported browser, and I'd want to wait as long as practical after a policy change before actually shipping anything that breaks it. |
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 also needs a jsdoc update and tests. Given the nature of the change, I'd recommend an integration test that actually runs jasmine-browser-runner with a suite that would fail if the feature didn't work. See esmIntegrationSpec.js for an example. Supporting unit tests are also welcome.
Ok. Thank you very much for the test. Will create a unit test for that in the next week. I will try to document the need of this new setting. |
373f51f
to
868b8b3
Compare
868b8b3
to
50ffc5b
Compare
I added the the documentation and a test. I am unsure if it needs more hints that one might need |
Looks reasonable at a glance, I just haven't had time to take a decent look at it yet. Stay tuned. |
@@ -156,8 +156,11 @@ config field to something that's high enough up to include both spec and source | |||
files, and set `srcFiles` to `[]`. You can autogenerate such a configuration by | |||
running `npx jasmine-browser-runner init --esm`. | |||
|
|||
If you want to load ES module source directly on load instead of loading it from | |||
the corresponding spec, set the `modulesWithSideEffectsInSrcFiles` config property to `true`. |
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 am unsure if I need to mention enableTopLevelAwait
(for sequencial source loading) here, too.
It is needed but can be confusing.
Actually the bug affects Safari 16 as well. But as far as I can tell Safari 16 has reached end of life. While I'd rather not drop it entirely, I think it would be ok to start removing workarounds for its ESM bugs. If I fixed #62 by emitting script tags in the HTML rather than using _jasmine_loadEsModule, would that allow you to simplify things? I think I can do that regardless of the outcome of jasmine/jasmine#2050 . |
Yes. I had locally removed I could create a PR (which removes |
479d731
to
3a2b094
Compare
We have some ES modules which needs to be loaded as spec files.