CreateApp › trigger lifecycle
│ 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
│ 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/admin/Documents/workspace/taro-test-utils/tests/react/src/app.scss:1
│ ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){.mr-10 {
│ ^
│ SyntaxError: Unexpected token '.'
│ 1 | import React from 'react'
│ 2 | import { useDidShow, useLaunch } from '@tarojs/taro'
│ > 3 | import './app.scss'
│ | ^
│ 4 |
│ 5 | const App: React.FC<{ children: any }> = ({ children }) => {
│ 6 |
│ at Runtime.createScriptFromCode (../../node_modules/.pnpm/jest-runtime@29.5.0/node_modules/jest-runtime/build/index.js:1495:14)
│ at Object.require (src/app.ts:3:1)
│ at require (../../packages/test-utils-react/dist/index.js:77:25)
│ at call (../../node_modules/.pnpm/@babel+runtime@7.22.5/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:44:17)
│ at Generator.tryCatch (../../node_modules/.pnpm/@babel+runtime@7.22.5/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:125:22)
│ at Generator._invoke [as next] (../../node_modules/.pnpm/@babel+runtime@7.22.5/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:69:21)
│ at next (../../packages/test-utils-react/dist/index.js:31:71)
│ at Object.<anonymous>.__awaiter (../../packages/test-utils-react/dist/index.js:27:12)
│ at ReactTestUtil.__awaiter (../../packages/test-utils-react/dist/index.js:72:16)
│ at createApp (__tests__/createApp.spec.ts:12:21)
│ at call (../../node_modules/.pnpm/@babel+runtime@7.22.5/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:44:17)
│ at Generator.tryCatch (../../node_modules/.pnpm/@babel+runtime@7.22.5/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:125:22)
│ at Generator._invoke [as next] (../../node_modules/.pnpm/@babel+runtime@7.22.5/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:69:21)
│ at asyncGeneratorStep (../../node_modules/.pnpm/@babel+runtime@7.22.5/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
│ at asyncGeneratorStep (../../node_modules/.pnpm/@babel+runtime@7.22.5/node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:9)
│ at _next (../../node_modules/.pnpm/@babel+runtime@7.22.5/node_modules/@babel/runtime/helpers/asyncToGenerator.js:27:7)
│ at Object.<anonymous> (../../node_modules/.pnpm/@babel+runtime@7.22.5/node_modules/@babel/runtime/helpers/asyncToGenerator.js:19:12)
│ Test Suites: 1 failed, 1 of 5 total
│ Tests: 4 failed, 4 total
│ Snapshots: 0 total
│ Time: 2.662 s, estimated 6 s
│ Ran all test suites.
问题描述
官方仓库 taro-test-utils@0.1.0,在
tests/react/src/app.scss
中加上 css 代码,如.mr-10 { margin-right: 10px }
,执行pnpm test
报错。错误信息