For some reason, my tests are running fine locally, but failed during concourse CI pipeline test. I compared npx jest --showConfg
with local setup, I don't see the difference that will cause the issue. It is strange that the other .tsx
tests are running fine, only the tests that have import
below statements failed. I did research on jest.config.js
, tsconfig.json
, setupTests.js
, babel.config.js
, Dockerfile
, package.json
, and package-lock.json
files... but still haven't figured out what is missing. Any ideas? Thanks!
Below is the import statement that I used in those failed tests files.
import { render } from "@testing-library/react";
I am getting the error below in concourse pipeline:
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• 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/en/configuration.html
jest configure output:
{
"configs": [
{
"automock": false,
"browser": false,
"cache": true,
"cacheDirectory": "/tmp/jest_0",
"clearMocks": false,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"cwd": "/tmp/build/f541ec31/source-code",
"dependencyExtractor": null,
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"filter": null,
"forceCoverageMatch": [],
"globalSetup": null,
"globalTeardown": null,
"globals": {},
"haste": {
"computeSha1": false,
"providesModuleNodeModules": [],
"throwOnModuleCollision": false
},
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"moduleNameMapper": [
[
"MsalAuthService",
"/tmp/build/f541ec31/source-code/test/MsalAuthServiceMock.js"
],
[
"AuthService",
"/tmp/build/f541ec31/source-code/test/authServiceMock.js"
],
[
"GraphService",
"/tmp/build/f541ec31/source-code/test/authServiceMock.js"
],
[
"ErrorReportingService",
"/tmp/build/f541ec31/source-code/test/ErrorReportingServiceMock.js"
],
[
"\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$",
"/tmp/build/f541ec31/source-code/test/fileMock.js"
],
[
"\\.(css|less|scss)$",
"/tmp/build/f541ec31/source-code/test/styleMock.js"
]
],
"modulePathIgnorePatterns": [],
"name": "cbdb51e30f6e73bcd3a3c5be677e9e95",
"prettierPath": "prettier",
"resetMocks": false,
"resetModules": false,
"resolver": null,
"restoreMocks": false,
"rootDir": "/tmp/build/f541ec31/source-code",
"roots": [
"/tmp/build/f541ec31/source-code"
],
"runner": "jest-runner",
"setupFiles": [],
"setupFilesAfterEnv": [
"/tmp/build/f541ec31/source-code/src/setupTests.ts"
],
"skipFilter": false,
"snapshotSerializers": [],
"testEnvironment": "/tmp/build/f541ec31/source-code/node_modules/jest-environment-jsdom/build/index.js",
"testEnvironmentOptions": {},
"testLocationInResults": false,
"testMatch": [],
"testPathIgnorePatterns": [
"/node_modules/"
],
"testRegex": [
"/test/.*.(test|spec).(tsx|ts)$"
],
"testRunner": "/tmp/build/f541ec31/source-code/node_modules/jest-jasmine2/build/index.js",
"testURL": "http://localhost",
"timers": "real",
"transform": [
[
"^.+\\.tsx?$",
"/tmp/build/f541ec31/source-code/node_modules/jest-config/node_modules/babel-jest/build/index.js"
]
],
"transformIgnorePatterns": [
"/node_modules/"
],
"watchPathIgnorePatterns": []
}
],
"globalConfig": {
"bail": 0,
"changedFilesWithAncestor": false,
"collectCoverage": false,
"collectCoverageFrom": null,
"coverageDirectory": "/tmp/build/f541ec31/source-code/coverage",
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"coverageThreshold": null,
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"expand": false,
"filter": null,
"globalSetup": null,
"globalTeardown": null,
"json": false,
"listTests": false,
"maxConcurrency": 5,
"maxWorkers": 15,
"noStackTrace": false,
"nonFlagArgs": [],
"notify": false,
"notifyMode": "failure-change",
"passWithNoTests": false,
"projects": null,
"rootDir": "/tmp/build/f541ec31/source-code",
"runTestsByPath": false,
"skipFilter": false,
"testFailureExitCode": 1,
"testPathPattern": "",
"testResultsProcessor": null,
"testSequencer": "/tmp/build/f541ec31/source-code/node_modules/@jest/test-sequencer/build/index.js",
"updateSnapshot": "new",
"useStderr": false,
"verbose": null,
"watch": false,
"watchman": true
},
"version": "24.9.0"
}