Skip to content

Commit

Permalink
rename package
Browse files Browse the repository at this point in the history
  • Loading branch information
changwoolab committed Feb 13, 2024
1 parent 9536033 commit eedf790
Show file tree
Hide file tree
Showing 4 changed files with 2,883 additions and 200 deletions.
75 changes: 39 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# react-native-fast-jest
# flow-aware-swc-jest

Run testing 3x faster than babel-jest in React Native!

Internally using @swc/jest
Use `@swc/jest` even if you are using flow.

<table>
<tr>
<th>babel-jest (61s)</th>
<th>react-native-fast-jest (23s)</th>
<th>flow-aware-swc-jest (23s)</th>
</tr>
<tr>
<td>
Expand All @@ -23,58 +21,63 @@ Internally using @swc/jest
</tr>
</table>


## Installation

```
npm i --save-dev react-native-fast-jest
npm i --save-dev flow-aware-swc-jest
```

## Configuration

1. You need to configure `.swcrc` like below.

```json
{
"jsc": {
"parser": {
"syntax": "typescript",
"jsx": true,
"tsx": true,
"dynamicImport": false,
"privateMethod": false,
"functionBind": false,
"exportDefaultFrom": false,
"exportNamespaceFrom": false,
"decorators": false,
"decoratorsBeforeExport": false,
"topLevelAwait": false,
"importMeta": false,
"preserveAllComments": false
},
"transform": null,
"target": "es5",
"loose": true,
"externalHelpers": false,
"keepClassNames": false
"jsc": {
"parser": {
"syntax": "typescript",
"jsx": true,
"tsx": true,
"dynamicImport": false,
"privateMethod": false,
"functionBind": false,
"exportDefaultFrom": false,
"exportNamespaceFrom": false,
"decorators": false,
"decoratorsBeforeExport": false,
"topLevelAwait": false,
"importMeta": false,
"preserveAllComments": false
},
"isModule": true
"transform": null,
"target": "es5",
"loose": true,
"externalHelpers": false,
"keepClassNames": false
},
"isModule": true
}
```

2. Configure jest config trasform

```js
transform: {
'^.+\\.(t|j)sx?$': 'react-native-fast-jest',
'^.+\\.(t|j)sx?$': 'flow-aware-swc-jest',
},
```

## I have error when jest.spyOn
## I have error when jest.spyOn

`TypeError: Cannot redefine property` or `TypeError: Cannot read properties of undefined`

You need to do mock as a esModule

```js
jest.mock('./path_to_spy', () => {
return {
__esModule: true, // <- Important!
...jest.requireActual('./path_to_spy'),
};
jest.mock("./path_to_spy", () => {
return {
__esModule: true, // <- Important!
...jest.requireActual("./path_to_spy"),
};
});
```
15 changes: 6 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
const flowRemoveTypes = require("flow-remove-types");
const createTransformer = require("@swc/jest").createTransformer;
const createSwcTransformer = require("@swc/jest").createTransformer;

const swcTransformer = createSwcTransformer();

module.exports = {
process(src, filename, jestOptions) {
const flowRemoved = flowRemoveTypes(src, jestOptions).toString();
const result = createTransformer().process(
flowRemoved,
filename,
jestOptions
);
return result;
return swcTransformer.process(flowRemoved, filename, jestOptions);
},
processAsync(src, filename, jestOptions) {
const flowRemoved = flowRemoveTypes(src).toString();
return createTransformer().processAsync(flowRemoved, filename, jestOptions);
return swcTransformer.processAsync(flowRemoved, filename, jestOptions);
},
getCacheKey(src, filename, jestOptions) {
const flowRemoved = flowRemoveTypes(src).toString();
return createTransformer().getCacheKey(flowRemoved, filename, jestOptions);
return swcTransformer.getCacheKey(flowRemoved, filename, jestOptions);
},
};
Loading

0 comments on commit eedf790

Please sign in to comment.