sapling/addons/isl/jest-transformer-import-meta.cjs
Evan Krause 8bcc1366b4 Update jest to 29
Summary: Update jest now that we've updated typescript. Only minor changes required to make it work as expected.

Reviewed By: quark-zju

Differential Revision: D56205373

fbshipit-source-id: 9f89d901c76f1d3671545a8a089dad9aaa7ddf82
2024-04-16 15:18:34 -07:00

27 lines
895 B
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const {default: tsJest} = require('ts-jest');
const transformer = tsJest.createTransformer({diagnostics: false});
/**
* Replace 'import.meta.hot' with 'undefined' to make Jest happy.
* Replace 'import.meta.url' with a require filename to enable WebWorkers.
* Then delegates to the ts-jest transformer.
*
* For simplicity, we just do a naive string replace without complex parsing.
*/
function process(sourceText, path, options) {
const newSourceText = sourceText
.replace(/import\.meta\.hot/g, 'undefined')
.replace(/import\.meta\.url/g, `require('url').pathToFileURL(__filename).toString()`);
return transformer.process(newSourceText, path, options);
}
module.exports = {process};