forked from jestjs/jest
/
my-transform.cjs
35 lines (27 loc) 路 917 Bytes
/
my-transform.cjs
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
27
28
29
30
31
32
33
34
35
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const {promisify} = require('util');
const wait = promisify(setTimeout);
const fileToTransform = require.resolve('./module-under-test');
const fileToTransform2 = require.resolve('./some-symbol');
module.exports = {
async processAsync(src, filepath) {
if (filepath !== fileToTransform && filepath !== fileToTransform2) {
throw new Error(`Unsupported filepath ${filepath}`);
}
if (filepath === fileToTransform2) {
// we want to wait to ensure the module cache is populated with the correct module
await wait(100);
return src;
}
return src.replace(
"export default 'It was not transformed!!'",
'export default 42',
);
},
};