使用 jest 和 remix 运行测试时出现错误 我正在尝试使用 remix 设置一个项目,并以我在文档中看到的测试作为示例在项目中进行测试,然后我得到了一个 e...
使用 jest 和 remix 运行测试时出现错误
我正在尝试使用 remix 建立一个项目,并以我在文档中看到的测试作为示例在项目中进行测试,但出现了错误。
这是我使用 10 年后第一次在 上提问,我甚至不知道该搜索什么了。我按照建议的配置做了所有配置,但一无所获。
存储库链接: https://github.com/carvalhothiago/teste-jest 测试文件是文档中的文件: https://remix.run/docs/en/main/other-api/testing
要运行它,请使用 npm i
然后 npm test
` FAIL app/teste.test.tsx 测试套件运行失败
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:
C:\Users\thiago\documentos\workspace\pessoal\teste-jest\node_modules\@web3-storage\multipart-parser\esm\src\index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import {
^^^^^^
SyntaxError: Cannot use import statement outside a module
> 1 | import { json } from "@remix-run/node";
| ^
2 | import { useLoaderData } from "@remix-run/react";
3 | import { createRemixStub } from "@remix-run/testing";
4 | import { render, screen, waitFor } from "@testing-library/react";
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
at Object.<anonymous> (app/teste.test.tsx:1:1)
测试套件:1 个失败,1 个总测试数:0 个总快照数:0 个总时间:3.084 秒运行所有测试套件。`
我尝试创建一个测试项目,只是为了使用 remix 文档中的示例中的 jest 运行测试