Skip to content

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

Closed

Description

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions