-
-
Notifications
You must be signed in to change notification settings - Fork 534
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
Test coverage: moduleType overrides during ts-node loader usage #1376
Test coverage: moduleType overrides during ts-node loader usage #1376
Conversation
… applied for ts-node in loader mode
Thanks, what needs to happen next? Does
Is this necessary to get code coverage? |
Codecov Report
|
I don't think so - that (just in case, I did try adding an explicit
Not for code coverage, no, but to get the test module to run without raising that error it does seem to be required. |
Oh, I see the confusion. The logic shares elements of both TS Globs match the behavior of TS Patterns are matched from top to bottom, and anything at the bottom overrides anything at the top. Same as ts-node/tests/module-types/tsconfig.json Lines 6 to 8 in c9c443c
What about importing the files by name instead of importing the directory? |
Thank you - I've applied some rearrangements here, and am now able to run That said I'll want to reconfirm that the test coverage is really proving what it claims to, and also ensure that it works when run as part of the standard test suite. |
(to try to explain what I meant about proving the test coverage: we should get confidence that the overrides are really being used, to make sure that passing test results aren't simply a result of default behaviour) |
Agreed. Does it make sense to copy-paste Can we remove |
Sounds good; I've been messing around a bit further here as you'll see, but the tests do not pass yet.
(I now understand that this should be addressed by the direct filename imports you mentioned previously; I'll try that out soon) |
Test are failing on 14.13.0 and 12.15, but I think I know why. I believe we test on these versions specifically because they are old enough that they do not throw an error when attempting to |
Thanks @cspotcode - I guess that kind of require of ESM-as-CJS-by-default might only work by chance, if at all? Looking at some of the code comments (particularly this one), would it be fair to say that (in this case currently, that's to throw an |
...I've since guessed that that's probably not a sensible error to reproduce, because that was encountered when running the |
The goal is to match node's behavior. The behavior matching is as follows:
We must behave the same way that node would, which means:
In order to correctly match node's behavior with the |
I just realized your comment was about The goal regarding |
No problem at all; we're on the same page, I think - and it's better to overcommunicate in these kinds of conversation. If I understand correctly then we'll end up with a test matrix of six possible outcomes when
It's possible these collapse down to four outcomes, but it'll be a little while before I have time to confirm behaviour across both Node 12.15 and Node 14.13. I also get the feeling that the test coverage here might end up being a base level of coverage rather than exhaustive; in other words, it's not going to reliably test all the differences that could occur for varying CJS and EJS file content. Still, making sure that each line of code is exercised seems like a worthwhile improvement. Feel free to continue on further with the branch if you will have more time and/or want to progress this soon. I should have some time outside work hours next week to look at this again. |
I've added 'expected failure' cases for the moduleType override test under Node 12.15, 14.13 - but also have to admit I haven't yet gone upstream to Node to figure out if those are really the ranges affected (i.e. why the failures on those versions as of 7b6daa3 occurred for those unit test runs). |
That's fine, I feel confident those node versions are in the test matrix
for this reason. There may be some comments in the GH actions workflow
file; I'm not sure. FWIW `n` and `volta` make it fast and easy to switch
node versions. I use Volta for all this testing.
Is there anything else required here? Tests don't need to be perfect as
long as we think they are proving that the feature works.
…On Sun, Jul 4, 2021, 3:09 PM James Addison ***@***.***> wrote:
I've added 'expected failure' cases for the moduleType override test under
Node 12.15, 14.13 - but also have to admit I haven't yet gone upstream to
Node to figure out if those are really the ranges affected (i.e. why the
failures on those versions as of 7b6daa3
<7b6daa3>
occurred for those unit test runs).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1376 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35OB6WPIA7K52LJYJ2L3TWCWVRANCNFSM47ALMQTQ>
.
|
I don't think so? Although I do feel a bit out of my depth here. |
@jayaddison ok, thanks, I'll give this a proper review as soon as I have time, and hopefully get this merged. |
Thanks in advance @cspotcode, and take your time; glad to make any further adjustments to make sure the code's acceptable. |
* Add moduleType option to override module type on certain files. Also refactor resolverFunctions into their own file; should break this into 2x PRs later. * lint fix * add test * remove unnecessary exports from ts-internals; mark exports as @internal * add docs * strip optionBasePaths from showConfig output * proper path normalization to support windows * lint-fix * use es2015 instead of es2020 in test tsconfig to support ts2.7 * add missing path normalization when calling classifyModule * Test coverage: moduleType overrides during ts-node loader usage (#1376) * Test coverage: add test case to confirm that moduleType overrides are applied for ts-node in loader mode * Ensure that a default export exists for the esm-exception module * Re-order tsconfig.json glob rules, and use implicit globbing * lint fixup: apply prettier * Add 'experimental-specifier-resolution' flag to NPM options in ESM module override test * Ensure that a default export exists for the cjs-subdir module * Revert "Ensure that a default export exists for the cjs-subdir module" This reverts commit c64cf92. * Revert "Add 'experimental-specifier-resolution' flag to NPM options in ESM module override test" This reverts commit 1093df8. * Specify tsconfig project using TS_NODE_PROJECT environment variable * Use full file paths in preference to directory-default module imports This avoids ERR_UNSUPPORTED_DIR_IMPORT, without having to provide the 'experimental-specifier-resolution' flag to ts-node * Update index.ts * Update index.ts * Update tsconfig.json * Extract execModuleTypeOverride function * Add expected failure cases for Node 12.15, 14.13 Co-authored-by: Andrew Bradley <cspotcode@gmail.com> * Update tests * fix * fix * fix for TS2.7 * fix * fix * reword * update docs * address todos * fix Co-authored-by: James Addison <jay@jp-hosting.net>
Extends #1371.
This isn't working as expected currently: when running the
test.esm.js
module directly (from the base directory:TS_NODE_PROJECT=tests/module-types/tsconfig.json node --trace-warnings --experimental-specifier-resolution=node --loader ts-node/esm tests/module-types/test.esm.js
), one of the assertions fails because bothimport
ed modules have a value offunction
forrequireType
.Without the
--experimental-specifier-resolution=node
flag, aERR_UNSUPPORTED_DIR_IMPORT
error is raised by the attempts to import modules from directory paths.