aboutsummaryrefslogtreecommitdiffstats
path: root/config/jestEsbuildTransform.js
blob: 7c6a57cc1e8d255a0c0c6d0bd09b0fa724f835c8 (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
24
25
26
import { transform } from 'esbuild';

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

export default {
  /**
   * @param {string} source
   * @param {string} filePath
   * @param {import('@jest/types').Config.GlobalConfig} jestConfig
   * @return {Promise<import('@jest/types').TransformTypes.TransformResult>}
   */
  async processAsync(source, filePath) {
    const { code } = await transform(source, {
      loader: filePath.endsWith('tsx') ? 'tsx' : 'ts',
      sourcefile: filePath,
      format: 'esm',
      target: node,
      sourcemap: 'inline',
    });
    return {
      code,
      originalCode: source,
      sourceMapPath: null,
    };
  },
};