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

Allow jest.config.cts #14064

Closed
wants to merge 1 commit into from
Closed

Allow jest.config.cts #14064

wants to merge 1 commit into from

Conversation

karlhorky
Copy link
Contributor

@karlhorky karlhorky commented Apr 12, 2023

Summary

Allow loading jest.config.cts files for ESM projects

This will avoid the extra package.json configuration below to special-case ts-node for jest.config.ts:

{
  "ts-node": {
    "moduleTypes": {
      "jest.config.ts": "cjs"
    }
  }
}

Mentioned as part of #13118

Test plan

Opening the PR for feedback first

@karlhorky
Copy link
Contributor Author

Ok, tests are failing here

Looks like there are some fixtures that need to be created:

Run yarn test-ci-partial:parallel --max-workers 2 --shard=1/4
.........
Error: Could not find a "package.json" file in /home/runner/work/jest/jest/packages/jest-cli/src/init/__tests__/__fixtures__/has-jest-config-file-cts


Error: Could not find a "package.json" file in /home/runner/work/jest/jest/packages/jest-cli/src/init/__tests__/__fixtures__/has-jest-config-file-cts


Error: expect(received).toBe(expected) // Object.is equality

Expected: "jest.config.ts"
Received: "jest.config.js"

    at Object.toBe (packages/jest-cli/src/init/__tests__/init.test.ts:247:61)

Error: TypeError: Cannot read properties of undefined (reading '1')

    at Object.<anonymous> (packages/jest-cli/src/init/__tests__/init.test.ts:280:73)
.
/home/runner/work/jest/jest/packages/jest-cli/src/init/__tests__/init.test.ts

  ● init › has-jest-config-file-cts › ask the user whether to override config or not › user answered with "Yes"

    Could not find a "package.json" file in /home/runner/work/jest/jest/packages/jest-cli/src/init/__tests__/__fixtures__/has-jest-config-file-cts



  ● init › has-jest-config-file-cts › ask the user whether to override config or not › user answered with "No"

    Could not find a "package.json" file in /home/runner/work/jest/jest/packages/jest-cli/src/init/__tests__/__fixtures__/has-jest-config-file-cts



  ● init › project using jest.config.ts › ask the user whether he wants to use Typescript or not › user answered with "Yes"

    expect(received).toBe(expected) // Object.is equality

    Expected: "jest.config.ts"
    Received: "jest.config.js"

      at Object.toBe (packages/jest-cli/src/init/__tests__/init.test.ts:247:61)

  ● init › has jest config in package.json › should ask the user whether to override config or not

    TypeError: Cannot read properties of undefined (reading '1')

      at Object.<anonymous> (packages/jest-cli/src/init/__tests__/init.test.ts:280:73)

...............................................Unable to get back timeout of Jest, falling back onto Jest for global timeout handling
Unable to get back timeout of Jest, falling back onto Jest for global timeout handling
.Unable to get back timeout of Jest, falling back onto Jest for global timeout handling
Unable to get back timeout of Jest, falling back onto Jest for global timeout handling
.....................[SKIP] Does not work on jest-circus
..[SKIP] Does not work on jest-circus
...[SKIP] Does not work on jest-circus
...........................
Errors thrown in packages/jest-cli/src/init/__tests__/init.test.ts
.


Summary of all failing tests
 FAIL  packages/jest-cli/src/init/__tests__/init.test.ts
  ● init › has-jest-config-file-cts › ask the user whether to override config or not › user answered with "Yes"

    Could not find a "package.json" file in /home/runner/work/jest/jest/packages/jest-cli/src/init/__tests__/__fixtures__/has-jest-config-file-cts



  ● init › has-jest-config-file-cts › ask the user whether to override config or not › user answered with "No"

    Could not find a "package.json" file in /home/runner/work/jest/jest/packages/jest-cli/src/init/__tests__/__fixtures__/has-jest-config-file-cts



  ● init › project using jest.config.ts › ask the user whether he wants to use Typescript or not › user answered with "Yes"

    expect(received).toBe(expected) // Object.is equality

    Expected: "jest.config.ts"
    Received: "jest.config.js"

      at Object.toBe (packages/jest-cli/src/init/__tests__/init.test.ts:247:61)

  ● init › has jest config in package.json › should ask the user whether to override config or not

    TypeError: Cannot read properties of undefined (reading '1')

      at Object.<anonymous> (packages/jest-cli/src/init/__tests__/init.test.ts:280:73)


Test Suites: 1 failed, 111 passed, 112 total
Tests:       4 failed, 3 skipped, 1184 passed, 1191 total
Snapshots:   315 passed, 315 total
Time:        154.952 s
Ran all test suites in 7 projects.
Error: Process completed with exit code 1.

And some snapshots need updating:

Run yarn test-ci-partial:parallel --max-workers 2 --shard=3/4
........................
Error: expect(received).toThrow(expected)

Expected substring: "The --config option requires a JSON string literal, or a file path with one of these extensions: .js, .ts, .mjs, .cjs, .json"
Received message:   "The --config option requires a JSON string literal, or a file path with one of these extensions: .js, .ts, .mjs, .cjs, .cts, .json.
Example usage: jest --config ./jest.config.js"

      at check (packages/jest-cli/src/args.ts:89:11)

    at Object.toThrow (packages/jest-cli/src/__tests__/args.test.ts:91:48)

Error: expect(received).toThrow(expected)

Expected substring: "The --config option requires a JSON string literal, or a file path with one of these extensions: .js, .ts, .mjs, .cjs, .json"
Received message:   "The --config option requires a JSON string literal, or a file path with one of these extensions: .js, .ts, .mjs, .cjs, .cts, .json.
Example usage: jest --config ./jest.config.js"

      at check (packages/jest-cli/src/args.ts:89:11)

    at Object.toThrow (packages/jest-cli/src/__tests__/args.test.ts:100:58)
.
/home/runner/work/jest/jest/packages/jest-cli/src/__tests__/args.test.ts

  ● check › raises an exception if config is not a valid JSON string

    expect(received).toThrow(expected)

    Expected substring: "The --config option requires a JSON string literal, or a file path with one of these extensions: .js, .ts, .mjs, .cjs, .json"
    Received message:   "The --config option requires a JSON string literal, or a file path with one of these extensions: .js, .ts, .mjs, .cjs, .cts, .json.
    Example usage: jest --config ./jest.config.js"

          at check (packages/jest-cli/src/args.ts:89:11)

      at Object.toThrow (packages/jest-cli/src/__tests__/args.test.ts:91:48)

  ● check › raises an exception if config is not a supported file type

    expect(received).toThrow(expected)

    Expected substring: "The --config option requires a JSON string literal, or a file path with one of these extensions: .js, .ts, .mjs, .cjs, .json"
    Received message:   "The --config option requires a JSON string literal, or a file path with one of these extensions: .js, .ts, .mjs, .cjs, .cts, .json.
    Example usage: jest --config ./jest.config.js"

          at check (packages/jest-cli/src/args.ts:89:11)

      at Object.toThrow (packages/jest-cli/src/__tests__/args.test.ts:100:58)

..........................Unable to get back timeout of Jest, falling back onto Jest for global timeout handling
Unable to get back timeout of Jest, falling back onto Jest for global timeout handling
...........................Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot
.................................


Summary of all failing tests
 FAIL  packages/jest-cli/src/__tests__/args.test.ts
  ● check › raises an exception if config is not a valid JSON string

    expect(received).toThrow(expected)

    Expected substring: "The --config option requires a JSON string literal, or a file path with one of these extensions: .js, .ts, .mjs, .cjs, .json"
    Received message:   "The --config option requires a JSON string literal, or a file path with one of these extensions: .js, .ts, .mjs, .cjs, .cts, .json.
    Example usage: jest --config ./jest.config.js"

          at check (packages/jest-cli/src/args.ts:89:11)

      at Object.toThrow (packages/jest-cli/src/__tests__/args.test.ts:91:48)

  ● check › raises an exception if config is not a supported file type

    expect(received).toThrow(expected)

    Expected substring: "The --config option requires a JSON string literal, or a file path with one of these extensions: .js, .ts, .mjs, .cjs, .json"
    Received message:   "The --config option requires a JSON string literal, or a file path with one of these extensions: .js, .ts, .mjs, .cjs, .cts, .json.
    Example usage: jest --config ./jest.config.js"

          at check (packages/jest-cli/src/args.ts:89:11)

      at Object.toThrow (packages/jest-cli/src/__tests__/args.test.ts:100:58)


Test Suites: 1 failed, 1 skipped, 109 passed, 110 of 111 total
Tests:       2 failed, 4 skipped, 1793 passed, 1799 total
Snapshots:   1149 passed, 1149 total
Time:        162.286 s
Ran all test suites in 9 projects.
Error: Process completed with exit code 1.

@DerTimonius
Copy link
Contributor

Hi @karlhorky I opened a separate PR here (#14070) with added fixtures and snapshots! Hope you don't mind 🙂

@github-actions
Copy link

This PR is stale because it has been open 90 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 Jul 12, 2023
@karlhorky
Copy link
Contributor Author

The PR #14070 will be the one to watch, closing this one

@karlhorky karlhorky closed this Jul 12, 2023
@karlhorky karlhorky deleted the patch-1 branch July 12, 2023 11:06
@github-actions
Copy link

This pull request 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 Aug 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants