| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | const {default: tsJest} = require('ts-jest'); |
| 9 | |
| 10 | const transformer = tsJest.createTransformer({diagnostics: false}); |
| 11 | |
| 12 | /** |
| 13 | * Replace 'import.meta.hot' with 'undefined' to make Jest happy. |
| 14 | * Replace 'import.meta.url' with a require filename to enable WebWorkers. |
| 15 | * Then delegates to the ts-jest transformer. |
| 16 | * |
| 17 | * For simplicity, we just do a naive string replace without complex parsing. |
| 18 | */ |
| 19 | function process(sourceText, path, options) { |
| 20 | const newSourceText = sourceText |
| 21 | .replace(/import\.meta\.hot/g, 'undefined') |
| 22 | .replace(/import\.meta\.url/g, `require('url').pathToFileURL(__filename).toString()`); |
| 23 | return transformer.process(newSourceText, path, options); |
| 24 | } |
| 25 | |
| 26 | module.exports = {process}; |
| 27 | |