Skip to content

Commit

Permalink
Adding transformAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
ychi authored and SimenB committed Mar 7, 2021
1 parent 3c679f1 commit 2d2f5e6
Show file tree
Hide file tree
Showing 8 changed files with 1,883 additions and 114 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -21,6 +21,7 @@
- `[jest-reporters]` Add static filepath property to all reporters ([#11015](https://github.com/facebook/jest/pull/11015))
- `[jest-snapshot]` [**BREAKING**] Make prettier optional for inline snapshots - fall back to string replacement ([#7792](https://github.com/facebook/jest/pull/7792))
- `[jest-transform]` Pass config options defined in Jest's config to transformer's `process` and `getCacheKey` functions ([#10926](https://github.com/facebook/jest/pull/10926))
- `[jest-transform]` Async code transformations ([#9889](https://github.com/facebook/jest/pull/9889))
- `[jest-worker]` Add support for custom task queues and adds a `PriorityQueue` implementation. ([#10921](https://github.com/facebook/jest/pull/10921))
- `[jest-worker]` Add in-order scheduling policy to jest worker ([10902](https://github.com/facebook/jest/pull/10902))

Expand Down
6 changes: 3 additions & 3 deletions packages/babel-jest/src/index.ts
Expand Up @@ -17,7 +17,7 @@ import * as fs from 'graceful-fs';
import slash = require('slash');
import type {
TransformOptions as JestTransformOptions,
Transformer,
SyncTransformer,
} from '@jest/transform';
import type {Config} from '@jest/types';
import {loadPartialConfig} from './loadBabelConfig';
Expand All @@ -26,7 +26,7 @@ const THIS_FILE = fs.readFileSync(__filename);
const jestPresetPath = require.resolve('babel-preset-jest');
const babelIstanbulPlugin = require.resolve('babel-plugin-istanbul');

type CreateTransformer = Transformer<TransformOptions>['createTransformer'];
type CreateTransformer = SyncTransformer<TransformOptions>['createTransformer'];

const createTransformer: CreateTransformer = userOptions => {
const inputOptions = userOptions ?? {};
Expand Down Expand Up @@ -160,7 +160,7 @@ const createTransformer: CreateTransformer = userOptions => {
};
};

const transformer: Transformer<TransformOptions> = {
const transformer: SyncTransformer<TransformOptions> = {
...createTransformer(),
// Assigned here so only the exported transformer has `createTransformer`,
// instead of all created transformers by the function
Expand Down
6 changes: 6 additions & 0 deletions packages/jest-repl/src/cli/repl.ts
Expand Up @@ -26,6 +26,12 @@ const evalCommand: repl.REPLEval = (
let result;
try {
if (transformer) {
// TODO: support async as well
if (!transformer.process) {
throw new TypeError(
'Jest: currently only sync transforms are supported; a transform must export a `process function',
);
}
const transformResult = transformer.process(
cmd,
jestGlobalConfig.replname || 'jest.js',
Expand Down

0 comments on commit 2d2f5e6

Please sign in to comment.