-
-
Notifications
You must be signed in to change notification settings - Fork 970
test: extract cjs require tests to .spec.cts #3436
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
base: next
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for fakerjs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## next #3436 +/- ##
==========================================
- Coverage 99.97% 99.97% -0.01%
==========================================
Files 2836 2836
Lines 218600 218600
Branches 952 952
==========================================
- Hits 218547 218545 -2
- Misses 53 55 +2 🚀 New features to boost your workflow:
|
88640f0
to
0fb1a6a
Compare
0fb1a6a
to
b6c8cb8
Compare
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 if we just move all require(*)-cjs calls into .spec.cts files. That way we can more safely use the require-nodejs keyword and ensure that it really works.
What do you mean by "ensure that it really works"? Why does it not work right now? 🤔
But not only this, when we will remove cjs support in v10, we could ensure this way at least for newer versions of nodejs, that it still works with their new require(esm) nodejs.org/api/modules.html#loading-ecmascript-modules-using-require
I don't see how moving the test in a separate file ensures this behavior. As far as I can tell this would require our code base to use explicit *.m(t|j)s
file extensions, which is not the case right now. Am I missing something? Could you elaborate on this?
Object.keys( | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
allLocales | ||
) |
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 you use our internal keys
function (from 'src/internal/keys.ts'
)? That way we don't need to disable the line from linting.
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'll try 👀
Oh, I think I did it that way, because it does not use imports from src
at all, but is more an integration/e2e-test depending on the build output
That way, the test also fully ensures that nothing gets "optimized" but reads the final bundled sourcecode
Before this PR, we used faker/test/locale-imports.spec.ts Line 9 in 1e551c5
No, we wont need to ship |
36cdb4b
to
7a036ed
Compare
@xDivisionByZerox in the future (v10) we might need to run this And then we need to switch the required calls to depend on v10's esm bundled code - require('../dist/index.cjs')
+ require('../dist/index.js')
- require(`../dist/locale/${locale}.cjs`)
+ require(`../dist/locale/${locale}.js`) |
7a036ed
to
e5a5074
Compare
e5a5074
to
1f87d91
Compare
1f87d91
to
e1ad736
Compare
I just go a great idea over night! 💡
What if we just move all
require(*)
-cjs calls into.spec.cts
files. That way we can more safely use therequire
-nodejs keyword and ensure that it really works.But not only this, when we will remove cjs support in v10, we could ensure this way at least for newer versions of nodejs, that it still works with their new
require(esm)
https://nodejs.org/api/modules.html#loading-ecmascript-modules-using-require