jest icon indicating copy to clipboard operation
jest copied to clipboard

Compile typescript from child_process fork does not work (dynamic import)

Open javeoff opened this issue 1 year ago • 1 comments

I have typescript fork(filename) from node:child_process. When i try to run tests, I have an error Unknown file extension ".ts" for /[...myfullpath]/getSpots.ts. All imports works good but import file via fork for multithreading

jest.config.ts

import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
  extensionsToTreatAsEsm: ['.ts'],
  testEnvironment: 'node',
  transform: {
    '.*\\.(tsx?)$': ['@swc/jest', {
      jsc: {
        target: "es2021",
        parser: {
          "syntax": "typescript",
          "decorators": true,
          "dynamicImport": true
        },
      },
    }],
  },
  testRegex: [
    '/tests/.*\\.(test|spec)\\.(ts)$',
    '/src/.*\\.(test|spec)\\.(ts)$',
  ],
  transformIgnorePatterns: [
    'node_modules',
    './dist',
  ],
  testPathIgnorePatterns: ['./dist'],
  moduleFileExtensions: ['ts', 'js', 'json', 'node'],
  testTimeout: 240 * 1_000,
};

export default config;


javeoff avatar Dec 31 '23 12:12 javeoff

It also doesnt work with node:worker_threads

javeoff avatar Jan 02 '24 10:01 javeoff