Skip to content
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 CI for Node 16.14.x #5404

Merged
merged 4 commits into from
Apr 2, 2022
Merged

Conversation

STRd6
Copy link
Contributor

@STRd6 STRd6 commented Apr 1, 2022

Guarding dynamic import tests based on Node version
These import assertions weren't actually running on older versions of
Node. They failed to parse so failed to run at all. Node 16.14.x added
support to parse the import assertion syntax but instead failed with
Invalid module "data:application/json,..." has an unsupported MIME type "application/json"

Node 17.8.x supports the syntax and supports the application/json mime
as well.

As a cleanup item also updated caniuse-lite.

STRd6 added 2 commits April 1, 2022 12:05
These import assertions weren't actually running on older versions of
Node. They failed to parse so failed to run at all. Node 16.14.x added
support to parse the import assertion syntax but instead failed with
`Invalid module "data:application/json,..." has an unsupported MIME type "application/json"`

Node 17.8.x supports the syntax and supports the `application/json` mime
as well.
@GeoffreyBooth
Copy link
Collaborator

We’ve been using feature detection for this rather than hard-coding Node versions. See

coffeescript/Cakefile

Lines 465 to 479 in 3d39d20

# Run every test in the `test` folder, recording failures, except for files
# we’re skipping because the features to be tested are unsupported in the
# current Node runtime.
testFilesToSkip = []
skipUnless = (featureDetect, filenames) ->
unless (try new Function featureDetect)
testFilesToSkip = testFilesToSkip.concat filenames
skipUnless 'async () => {}', ['async.coffee', 'async_iterators.coffee']
skipUnless 'async function* generator() { yield 42; }', ['async_iterators.coffee']
skipUnless 'var a = 2 ** 2; a **= 3', ['exponentiation.coffee']
skipUnless 'var {...a} = {}', ['object_rest_spread.coffee']
skipUnless '/foo.bar/s.test("foo\tbar")', ['regex_dotall.coffee']
skipUnless '1_2_3', ['numeric_literal_separators.coffee']
skipUnless '1n', ['numbers_bigint.coffee']
skipUnless 'async () => { await import(\'data:application/json,{"foo":"bar"}\', { assert: { type: "json" } }) }', ['import_assertions.coffee']

Do you mind updating the last line there, about import assertions, such that that resolves the issue? So that we don’t need to put guards in the test file itself. Some of the tests don’t parse at all in certain versions of Node because of syntax, and so it’s important not to load the file at all (rather than loading it and skipping most or all of its contents based on a condition).

@STRd6
Copy link
Contributor Author

STRd6 commented Apr 1, 2022

This is the same test referenced in the last skipUnless. The problem is that it now parses in node 16.4.x but fails during the async execution of the test on 16.14.x.

I'll poke around and see if I can extend skipUnless to detect async failures.

@STRd6 STRd6 force-pushed the update-caniuse-lite branch from 92470ce to 0c617e5 Compare April 1, 2022 22:34
@GeoffreyBooth
Copy link
Collaborator

GeoffreyBooth commented Apr 1, 2022

Now that I think about it more, I think skipUnless is meant just for parsing errors, where we need to avoid loading that file at all; but there are sometimes guards within tests based on missing functionality. But those guards I think are still feature detections, not version checks. Maybe you could do a feature detection at the top of the test file somehow that an import of application/json is supported? Not sure how, if that needs to be async.

Though if you get it to work within skipUnless I would be fine with that too, I don’t think skipUnless needs to only involve parsing errors. The advantage of a feature detection within the file is that we could avoid skipping the entire file, potentially, but that might not matter in this case.

@GeoffreyBooth
Copy link
Collaborator

GeoffreyBooth commented Apr 2, 2022

I dug into this a bit: nodejs/node#41736 (comment)

Basically, Node 16.14.0 included support for the import assertions syntax, so that syntax starts parsing as of 16.14.0; but JSON modules still require the --experimental-json-modules flag on 16.x. That flag was removed in 17.5.0, but that change hasn’t been backported to 16 yet; it should land as part of 16.15.0, whenever that comes out. So we’re in a weird transition state where the syntax parses but the module is unrecognized, which will only be the case for the brief life of Node 16.14.x.

So I guess we can land this try/catch for now and just remove it once 16.15.0 is released, in order to unblock your other PRs. I pushed a commit to add more info to the comment.

@GeoffreyBooth GeoffreyBooth merged commit 3ad26de into jashkenas:main Apr 2, 2022
@STRd6 STRd6 deleted the update-caniuse-lite branch April 3, 2022 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants