aboutsummaryrefslogtreecommitdiffstats
path: root/config/jestEsbuildTransform.js
blob: 4bf49e60e1e8c18f40850837eb6317788b381d5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { transform } from 'esbuild';

import { node } from './buildConstants.js';

/** @type {import('@jest/transform').AsyncTransformer<undefined>} */
const transformer = {
  canInstrument: false,
  async processAsync(source, filePath) {
    const { code, map } = await transform(source, {
      loader: filePath.endsWith('tsx') ? 'tsx' : 'ts',
      sourcefile: filePath,
      format: 'esm',
      target: node,
      sourcemap: true,
    });
    return {
      code,
      map,
    };
  },
};

export default transformer;