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

[Bug]: Are import assertions required when importing JSON Modules? #13693

Closed
ayame113 opened this issue Dec 25, 2022 · 3 comments · Fixed by #12755
Closed

[Bug]: Are import assertions required when importing JSON Modules? #13693

ayame113 opened this issue Dec 25, 2022 · 3 comments · Fixed by #12755

Comments

@ayame113
Copy link

ayame113 commented Dec 25, 2022

Version

29.3.1

Steps to reproduce

I'm using Jest's experimental ES Modules support.

First, create a test file that imports the JSON file without the import assertions like this:

// index.test.js
// imports the JSON file without the import assertions
import testdata from "./testdata.json";

import { expect, describe, test } from '@jest/globals';
describe('', () => {
  test('', async () => {
    expect(1 + 1).toBe(2);
  })
});

Then run this:

> node --experimental-vm-modules node_modules/.bin/jest

As a result, an ERR_IMPORT_ASSERTION_TYPE_MISSING error should have occurred, but no error occurs.

Expected behavior

Expect to get ERR_IMPORT_ASSERTION_TYPE_MISSING errors, just like when I run it in Node.js.

Actual behavior

Exit without error.

Additional context

vm.SourceTextModule can receive the value of importAssertions when resolving import statements.

https://nodejs.org/api/vm.html#new-vmsourcetextmodulecode-options

However, it seems that now the value of importAssertions is not respected.

https://github.com/facebook/jest/blob/fb2de8a10f8e808b080af67aa771f67b5ea537ce/packages/jest-runtime/src/index.ts#L628-L631

Environment

System:
    OS: macOS 12.3
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 16.17.1 - ~/.anyenv/envs/nodenv/versions/16.17.1/bin/node
    npm: 9.2.0 - ~/.anyenv/envs/nodenv/versions/16.17.1/bin/npm
  npmPackages:
    jest: ^29.3.1 => 29.3.1

Edit: Sorry if this was intentional behaviour.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Jan 24, 2023
@SimenB
Copy link
Member

SimenB commented Jan 24, 2023

It's not currently enforced, see #12755. As mentioned there, not all node versions we support have support for that API. I guess we could just check if the current version supports it, tho

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants