Jest встречается неожиданный токен «экспорт» в модуле узла «@Kubernetes/Client Node» во время работы тестовJavascript

Форум по Javascript
Ответить Пред. темаСлед. тема
Anonymous
 Jest встречается неожиданный токен «экспорт» в модуле узла «@Kubernetes/Client Node» во время работы тестов

Сообщение Anonymous »

Я запускаю Jest (версия:^29.7.0) Test Suite в среде Node.js V22 с использованием TypeScript. Используется «@kubernetes /client-node».

Код: Выделить всё

FAIL  src/modules/_common/k8s/services/k8s-storage-class.service.test.ts
● 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.

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:

D:\project\node_modules\@kubernetes\client-node\dist\index.js:1
({"Object.":function(module,exports,require,__dirname,__filename,jest){export * from './config.js';
^^^^^^

SyntaxError: Unexpected token 'export'
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
at Object. (src/modules/_common/k8s/k8s.config.ts:2:1)
at Object. (src/modules/_common/k8s/services/k8s-storage-class.service.test.ts:3:1)

< /code>
dtsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"allowJs": true,
"outDir": "dist",
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true
}
}
< /code>
Jest Config < /p>
{
"verbose": true,
"transform": {
"^.+\\.tsx?$": "ts-jest",
"^.+\\.js$": "babel-jest",
"\\.(yaml|yml)$": "jest-yaml-transform",
"node_modules/@kubernetes/client-node/dist/index.js": [
"ts-jest",
{
"isolatedModules": true
}
]
},
"transformIgnorePatterns": [
"/node_modules/(?!@kubernetes/client-node)/",
"/node_modules/(?!.*.js$)",
"/dist/"
],
"testEnvironment": "node",
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(tsx?)$",
"moduleNameMapper": {
"^@root(.*)$": "$1",
"^@configs(.*)$": "/configs$1",
"^@constants(.*)$": "/src/constants$1",
"^@common(.*)$": "/src/common$1",
"^@core(.*)$": "/src/core$1",
"^@middleware(.*)$": "/src/middleware$1",
"^@modules(.*)$": "/src/modules$1",
"^@utils(.*)$": "/src/utils$1"
},
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"setupFiles": [
"./test.config.ts"
]
}
Jest пытается выполнить файл, который использует синтаксис ES Module (Import/Export), но Jest не настроен должным образом для обработки модулей ES, что приводит к неожиданному токену 'Export' Ошибка.

Подробнее здесь: https://stackoverflow.com/questions/794 ... -client-no
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Javascript»