Skip to content

Commit

Permalink
feat(transformer): async code transformation (#9889)
Browse files Browse the repository at this point in the history
  • Loading branch information
ychi authored Mar 13, 2021
1 parent 344b31a commit 858c50b
Show file tree
Hide file tree
Showing 8 changed files with 1,859 additions and 125 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- `[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]` Add support for transformers written in ESM ([#11163](https://github.com/facebook/jest/pull/11163))
- `[jest-transform]` [**BREAKING**] Do not export `ScriptTransformer` class, instead export the async function `createScriptTransformer` ([#11163](https://github.com/facebook/jest/pull/11163))
- `[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
Original file line number Diff line number Diff line change
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
5 changes: 3 additions & 2 deletions packages/jest-repl/src/cli/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ declare const jestProjectConfig: Config.ProjectConfig;
import * as path from 'path';
import * as repl from 'repl';
import {runInThisContext} from 'vm';
import type {Transformer} from '@jest/transform';
import type {SyncTransformer} from '@jest/transform';
import type {Config} from '@jest/types';

let transformer: Transformer;
// TODO: support async as well
let transformer: SyncTransformer;
let transformerConfig: unknown;

const evalCommand: repl.REPLEval = (
Expand Down
Loading

1 comment on commit 858c50b

@akshayjai1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this link is helpful, I also got the same error
https://githubmemory.com/repo/facebook/fbjs/issues/441

Got error "Cannot destructure property 'instrument' of 'options' as it is undefined" when using with jest:27.0.4 #441

Please sign in to comment.