-
Notifications
You must be signed in to change notification settings - Fork 0
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(jest): support ESM setup files #12
Conversation
tests/setup-files/setup.cjs
Outdated
@@ -0,0 +1,3 @@ | |||
const path = require('path') | |||
|
|||
global.SETUP_CJS = path.basename(__filename) // using some cjs stuff here to make sure it works |
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.
globalThis
is the canonical name for the global object
global
might be not defined in general (e.g. if we support some other env other than Node.js-like)
% jsc
>>> globalThis
[object global]
>>> global
Exception: ReferenceError: Can't find variable: global
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.
replaced with globalThis
tests/setup-files/setup.js
Outdated
@@ -0,0 +1,3 @@ | |||
import path from 'path' | |||
|
|||
global.SETUP_JS_MODULE = path.basename(import.meta.url) |
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.
import.meta.url
is an url, calling basename on it might be not ideal
does just import.meta.filename
work here?
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.
ah, this is actually testing that import path
works, makes sense
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.
yeah, these 3 setup files are just for testing.
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.
Let's land this and if anything needs to be fixed will change it later
Add support for importing ESM files supplied in jest's
setupFiles
orsetupFilesAfterEnv