cloudscape-design / jest-preset

Jest presets for Cloudscape Design System
https://cloudscape.design/
Apache License 2.0
5 stars 1 forks source link

[Bug]: #30

Closed no2cturne closed 7 months ago

no2cturne commented 8 months ago

Package version

2.0.22

Jest version

29.5.0

node-versions

18.13.0

npm-versions

9.8.1

Description

When using @cloudscape-design/jest-preset on a NodeJS/Typescript web project with ts-jest and babel-jest, I am still getting the SyntaxError: Unexpected token 'export' error. Below is a copy of my jest.config.ts file where I attempt to merge @cloudscape-design/jest-preset with my settings for ts-jest and babel-jest.

jest.config.ts

import type {JestConfigWithTsJest} from 'ts-jest'
import {defaults as tsjPreset} from 'ts-jest/presets'
import merge from 'merge'

const config: JestConfigWithTsJest = merge.recursive(tsjPreset, {
    // Map @SRC to the src/ folder
    modulePaths: ['<rootDir>/src'],
    moduleNameMapper: {
      '^@SRC/(.*)$': '<rootDir>/src/$1',
    },

    // Enable ts-jest and have it reference test/tsconfig.json
    transform: {
      ...tsjPreset.transform,
      '^.+\\.tsx?$': [
        'ts-jest',
        {
          tsconfig: '<rootDir>/test/tsconfig.json',
        },
      ],
      '^.+\\.jsx?$': 'babel-jest',
    },
    transformIgnorePatterns: [
      '<rootDir>/node_modules/@cloudscape-design/*'
    ],
  }
)

export default config

Source code

No response

Code of Conduct

connorlanigan commented 7 months ago

Hi, in the code you shared, you are not importing the Cloudscape preset. You'll need to add the Cloudscape preset in order to support the syntax used in Cloudscape's code. You can find more details in the "Advanced usage" section of the package readme.