You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The with-jest starter repo seems to be encountering an issue where tests are not running as expected. Upon executing the test command, the test suite fails to initiate, halting any further progress.
The issue has 2 problems:
1. verbatimModuleSyntax
The first problem is caused by verbatimModuleSyntax rule set to true inside "plasmo/templates/tsconfig.base" which is extending all tsconfigs of with-* repositories. The following error happens:
> with-jest-issue@0.0.1 test /Users/misit/dev-work/with-jest-issue
> jest PASS tests/contents/index.test.ts FAIL tests/contents/hello.test.tsx ● Test suite failed to run tests/contents/hello.test.tsx:1:10 - error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. 1 import { describe, expect, it } from "@jest/globals" ~~~~~~~~ tests/contents/hello.test.tsx:1:20 - error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. 1 import { describe, expect, it } from "@jest/globals" ~~~~~~ tests/contents/hello.test.tsx:1:28 - error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. 1 import { describe, expect, it } from "@jest/globals" ~~ tests/contents/hello.test.tsx:2:10 - error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. 2 import { render } from "@testing-library/react" ~~~~~~ tests/contents/hello.test.tsx:4:8 - error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled. 4 import HelloContent from "~contents/hello" ~~~~~~~~~~~~Test Suites: 1 failed, 1 passed, 2 totalTests: 2 passed, 2 totalSnapshots: 0 totalTime: 1.617 sRan all test suites. ELIFECYCLE Test failed. See above for more details.
this problem is fixable in 2 ways:
set verbatimModuleSyntax to false
set type: "module" inside package.json
Not sure about decisions made behind current setup
2. tsx files SyntaxError: Unexpected token '<'
After fixing the first problem we get different error coming from hello.test.tsx file
> with-jest-issue@0.0.1 test /Users/misit/dev-work/with-jest-issue
> jest PASS tests/contents/index.test.ts FAIL tests/contents/hello.test.tsx ● Test suite failed to run Jest encountered an unexpected token Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax. Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration. By default "node_modules" folder is ignored by transformers. Here's what you can do: • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it. • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config. • If you need a custom transformation specify a "transform" option in your config. • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option. You'll find more details and examples of these config options in the docs: https://jestjs.io/docs/configuration For information about custom transformations, see: https://jestjs.io/docs/code-transformation Details: /Users/misit/dev-work/with-jest-issue/tests/contents/hello.test.tsx:11 (0, globals_1.expect)((0, react_1.render)(<hello_1.default />).getByText("Hello")).toBeTruthy(); ^ SyntaxError: Unexpected token '<' at Runtime.createScriptFromCode (node_modules/.pnpm/jest-runtime@29.7.0/node_modules/jest-runtime/build/index.js:1505:14)Test Suites: 1 failed, 1 passed, 2 totalTests: 2 passed, 2 totalSnapshots: 0 totalTime: 0.489 s, estimated 1 sRan all test suites. ELIFECYCLE Test failed. See above for more details.
It seems jest doesn't see the jsx: "react-jsx" rule set for tsx files inside jest.config.mjs. Setting this rule at the tsconfig file fixes the issue but it's not ideal. After removing ? from regexes it seems to work correctly.
What happened?
Description:
The with-jest starter repo seems to be encountering an issue where tests are not running as expected. Upon executing the test command, the test suite fails to initiate, halting any further progress.
The issue has 2 problems:
1.
verbatimModuleSyntax
The first problem is caused by
verbatimModuleSyntax
rule set totrue
inside"plasmo/templates/tsconfig.base"
which is extending alltsconfigs
ofwith-*
repositories. The following error happens:this problem is fixable in 2 ways:
verbatimModuleSyntax
tofalse
type: "module"
insidepackage.json
Not sure about decisions made behind current setup
2. tsx files
SyntaxError: Unexpected token '<'
After fixing the first problem we get different error coming from
hello.test.tsx
fileIt seems
jest
doesn't see thejsx: "react-jsx"
rule set fortsx
files insidejest.config.mjs
. Setting this rule at thetsconfig
file fixes the issue but it's not ideal. After removing?
from regexes it seems to work correctly.Original
After these changes I was able to run the tests
Steps to Reproduce:
pnpm create plasmo --with-jest with-jest-issue
pnpm test
Expected Behavior:
The test suite should execute without errors.
Actual Behavior:
The test suite fails to start, throwing an error message or terminating prematurely.
Additional Information:
This problem persists across different
Node.js
versions (tested latestv16
,v18
,v20
)Question:
Should I proceed with opening a Pull Request with minimal working example?
NOTE: I'm an expert at testing so please correct me if my solutions are wrong somehow 😄
Feel free to let me know if you need further clarification or if there's anything else I can assist with!
Version
Latest
What OS are you seeing the problem on?
MacOSX
What browsers are you seeing the problem on?
No response
Relevant log output
No response
(OPTIONAL) Contribution
Code of Conduct
The text was updated successfully, but these errors were encountered: