@stylexswc/jest 0.17.0 → 0.17.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -73
- package/package.json +23 -7
package/README.md
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
# @stylexswc/jest
|
|
2
|
+
|
|
3
|
+
> Jest transformer that compiles StyleX with a Rust compiler (NAPI-RS + SWC).
|
|
4
|
+
> Part of the
|
|
5
|
+
> [StyleX SWC Plugin](https://github.com/Dwlad90/stylex-swc-plugin#readme)
|
|
6
|
+
> workspace.
|
|
7
|
+
|
|
8
|
+
Components that use [StyleX](https://stylexjs.com) cannot run in Jest without a
|
|
9
|
+
transform: `stylex.create` calls must be compiled before the test executes. This
|
|
10
|
+
transformer does that compilation with
|
|
11
|
+
[`@stylexswc/rs-compiler`](https://www.npmjs.com/package/@stylexswc/rs-compiler),
|
|
12
|
+
a Rust implementation of the StyleX transform, so tests see the same compiled
|
|
13
|
+
class names your production build produces — without pulling Babel into your
|
|
14
|
+
test pipeline.
|
|
15
|
+
|
|
16
|
+
This is a community project and is not affiliated with Meta. It tracks the
|
|
17
|
+
official StyleX releases
|
|
18
|
+
<!-- stylex-compatibility:start -->(currently compatible with StyleX v0.19.0)<!-- stylex-compatibility:end -->
|
|
19
|
+
and requires Node.js 20 or newer.
|
|
13
20
|
|
|
14
21
|
## Installation
|
|
15
22
|
|
|
16
|
-
To install the package, run the following command:
|
|
17
|
-
|
|
18
23
|
```bash
|
|
19
24
|
npm install --save-dev @stylexswc/jest
|
|
20
25
|
```
|
|
21
26
|
|
|
22
27
|
## Configuration
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
configuration:
|
|
29
|
+
Add the transformer to your Jest configuration:
|
|
26
30
|
|
|
27
|
-
```
|
|
31
|
+
```js
|
|
28
32
|
// jest.config.js
|
|
29
33
|
const path = require('path');
|
|
30
34
|
|
|
@@ -55,35 +59,38 @@ module.exports = {
|
|
|
55
59
|
|
|
56
60
|
- Type: `Partial<StyleXOptions>`
|
|
57
61
|
- Optional
|
|
58
|
-
- Description: StyleX compiler options
|
|
59
|
-
|
|
62
|
+
- Description: StyleX compiler options passed to the transformer. For the
|
|
63
|
+
standard options, see the
|
|
64
|
+
[official StyleX documentation](https://stylexjs.com/docs/api/configuration/babel-plugin/).
|
|
60
65
|
|
|
61
66
|
> [!NOTE]
|
|
62
|
-
>
|
|
67
|
+
> The `include` and `exclude` options are exclusive to the Rust compiler
|
|
68
|
+
> and are not available in the official StyleX Babel plugin.
|
|
63
69
|
|
|
64
70
|
#### `rsOptions.include`
|
|
65
71
|
|
|
66
72
|
- Type: `(string | RegExp)[]`
|
|
67
73
|
- Optional
|
|
68
|
-
- Description:
|
|
69
|
-
When specified, only files matching at least one
|
|
70
|
-
Patterns are matched against paths relative to the current
|
|
71
|
-
|
|
74
|
+
- Description: Glob patterns or regular expressions selecting the files to
|
|
75
|
+
transform. When specified, only files matching at least one pattern are
|
|
76
|
+
transformed. Patterns are matched against paths relative to the current
|
|
77
|
+
working directory. Regular expressions support lookahead and lookbehind.
|
|
72
78
|
|
|
73
79
|
#### `rsOptions.exclude`
|
|
74
80
|
|
|
75
81
|
- Type: `(string | RegExp)[]`
|
|
76
82
|
- Optional
|
|
77
|
-
- Description:
|
|
78
|
-
|
|
79
|
-
Patterns are matched against paths relative to the
|
|
80
|
-
|
|
83
|
+
- Description: Glob patterns or regular expressions excluding files from the
|
|
84
|
+
transform. A file matching any exclude pattern is skipped even if it matches
|
|
85
|
+
an `include` pattern. Patterns are matched against paths relative to the
|
|
86
|
+
current working directory. Regular expressions support lookahead and
|
|
87
|
+
lookbehind.
|
|
81
88
|
|
|
82
89
|
### Path Filtering Examples
|
|
83
90
|
|
|
84
|
-
|
|
91
|
+
Include only specific directories:
|
|
85
92
|
|
|
86
|
-
```
|
|
93
|
+
```js
|
|
87
94
|
{
|
|
88
95
|
rsOptions: {
|
|
89
96
|
include: ['src/**/*.{ts,tsx}', 'app/**/*.{ts,tsx}'],
|
|
@@ -91,9 +98,9 @@ module.exports = {
|
|
|
91
98
|
}
|
|
92
99
|
```
|
|
93
100
|
|
|
94
|
-
|
|
101
|
+
Exclude test files:
|
|
95
102
|
|
|
96
|
-
```
|
|
103
|
+
```js
|
|
97
104
|
{
|
|
98
105
|
rsOptions: {
|
|
99
106
|
exclude: ['**/*.test.*', '**/*.spec.*', '**/__tests__/**'],
|
|
@@ -101,42 +108,27 @@ module.exports = {
|
|
|
101
108
|
}
|
|
102
109
|
```
|
|
103
110
|
|
|
104
|
-
|
|
111
|
+
Exclude `node_modules` except specific packages (negative lookahead):
|
|
105
112
|
|
|
106
|
-
```
|
|
113
|
+
```js
|
|
107
114
|
{
|
|
108
115
|
rsOptions: {
|
|
109
|
-
// Exclude all node_modules except @stylexjs/open-props
|
|
110
116
|
exclude: [/node_modules(?!\/@stylexjs\/open-props)/],
|
|
111
117
|
},
|
|
112
118
|
}
|
|
113
119
|
```
|
|
114
120
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
```javascript
|
|
118
|
-
{
|
|
119
|
-
rsOptions: {
|
|
120
|
-
include: ['src/**/*.{ts,tsx}'],
|
|
121
|
-
exclude: ['**/*.test.*', '**/*.stories.*'],
|
|
122
|
-
},
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## Example
|
|
121
|
+
## Chaining with other transformers
|
|
127
122
|
|
|
128
|
-
|
|
123
|
+
This transformer only compiles StyleX — TypeScript and JSX still need their own
|
|
124
|
+
transform. Chain it with `@swc/jest` (or another transformer) using
|
|
125
|
+
`jest-chain-transform`:
|
|
129
126
|
|
|
130
|
-
```
|
|
127
|
+
```js
|
|
131
128
|
// jest.config.js
|
|
132
|
-
const nextJest = require('next/jest');
|
|
133
129
|
const path = require('path');
|
|
134
130
|
|
|
135
|
-
|
|
136
|
-
dir: process.cwd(),
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
const customJestConfig = {
|
|
131
|
+
module.exports = {
|
|
140
132
|
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
|
|
141
133
|
testEnvironment: 'jsdom',
|
|
142
134
|
transform: {
|
|
@@ -160,34 +152,21 @@ const customJestConfig = {
|
|
|
160
152
|
[
|
|
161
153
|
'@swc/jest',
|
|
162
154
|
{
|
|
163
|
-
$schema: 'https://json.schemastore.org/swcrc',
|
|
164
155
|
jsc: {
|
|
165
156
|
parser: {
|
|
166
157
|
syntax: 'typescript',
|
|
167
158
|
tsx: true,
|
|
168
|
-
dynamicImport: true,
|
|
169
|
-
decorators: true,
|
|
170
|
-
dts: true,
|
|
171
159
|
},
|
|
172
160
|
transform: {
|
|
173
161
|
react: {
|
|
174
|
-
useBuiltins: true,
|
|
175
162
|
runtime: 'automatic',
|
|
176
163
|
},
|
|
177
164
|
},
|
|
178
165
|
target: 'esnext',
|
|
179
|
-
loose: false,
|
|
180
|
-
externalHelpers: false,
|
|
181
|
-
keepClassNames: true,
|
|
182
|
-
baseUrl: './',
|
|
183
|
-
paths: {
|
|
184
|
-
'@/*': ['./*'],
|
|
185
|
-
},
|
|
186
166
|
},
|
|
187
167
|
module: {
|
|
188
168
|
type: 'es6',
|
|
189
169
|
},
|
|
190
|
-
minify: false,
|
|
191
170
|
},
|
|
192
171
|
],
|
|
193
172
|
],
|
|
@@ -195,13 +174,40 @@ const customJestConfig = {
|
|
|
195
174
|
],
|
|
196
175
|
},
|
|
197
176
|
};
|
|
198
|
-
|
|
199
|
-
module.exports = customJestConfig;
|
|
200
177
|
```
|
|
201
178
|
|
|
202
|
-
|
|
203
|
-
[
|
|
179
|
+
A complete working configuration lives in the
|
|
180
|
+
[Next.js example app](https://github.com/Dwlad90/stylex-swc-plugin/tree/develop/apps/nextjs-example/jest.config.js).
|
|
181
|
+
|
|
182
|
+
## FAQ
|
|
183
|
+
|
|
184
|
+
### Why do my tests fail with "stylex.create should never be called"?
|
|
185
|
+
|
|
186
|
+
That error means the StyleX code reached the runtime uncompiled. Check that this
|
|
187
|
+
transformer is registered for the failing file's extension and that the file is
|
|
188
|
+
not excluded by your `rsOptions.include`/`exclude` patterns.
|
|
189
|
+
|
|
190
|
+
### Do I still need `babel-jest` or `@stylexjs/babel-plugin`?
|
|
191
|
+
|
|
192
|
+
No. This transformer replaces the Babel-based StyleX setup in Jest. For
|
|
193
|
+
TypeScript/JSX, chain it with `@swc/jest` as shown above instead of Babel.
|
|
194
|
+
|
|
195
|
+
### My theme tokens from `.stylex.ts` files don't resolve in tests
|
|
196
|
+
|
|
197
|
+
Set `unstable_moduleResolution` (usually `{ type: 'commonJS' }`) and mirror your
|
|
198
|
+
path aliases in `rsOptions.aliases`, exactly as in your build config.
|
|
199
|
+
|
|
200
|
+
### Is this an official StyleX package?
|
|
201
|
+
|
|
202
|
+
No. It is a community-maintained alternative to the official tooling and is not
|
|
203
|
+
affiliated with or supported by Meta.
|
|
204
|
+
|
|
205
|
+
## Documentation
|
|
206
|
+
|
|
207
|
+
- [StyleX documentation](https://stylexjs.com)
|
|
208
|
+
- [`@stylexswc/rs-compiler` compiler options](https://github.com/Dwlad90/stylex-swc-plugin/tree/develop/crates/stylex-rs-compiler)
|
|
204
209
|
|
|
205
210
|
## License
|
|
206
211
|
|
|
207
|
-
MIT — see
|
|
212
|
+
MIT — see
|
|
213
|
+
[LICENSE](https://github.com/Dwlad90/stylex-swc-plugin/blob/develop/LICENSE)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexswc/jest",
|
|
3
|
-
"description": "Jest transformer for
|
|
4
|
-
"version": "0.17.
|
|
3
|
+
"description": "Jest transformer for StyleX that compiles CSS-in-JS with the Rust NAPI-RS/SWC compiler, enabling Babel-free StyleX component tests.",
|
|
4
|
+
"version": "0.17.1-rc.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -18,22 +18,38 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@stylexswc/rs-compiler": "0.17.
|
|
21
|
+
"@stylexswc/rs-compiler": "0.17.1-rc.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@jest/transform": "^30.4.1",
|
|
25
25
|
"@jest/types": "^30.2.0",
|
|
26
|
-
"@stylexswc/eslint-config": "0.17.
|
|
27
|
-
"@stylexswc/typescript-config": "0.17.
|
|
26
|
+
"@stylexswc/eslint-config": "0.17.1-rc.1",
|
|
27
|
+
"@stylexswc/typescript-config": "0.17.1-rc.1",
|
|
28
28
|
"@types/node": "^26.1.0"
|
|
29
29
|
},
|
|
30
|
+
"bugs": "https://github.com/Dwlad90/stylex-swc-plugin/issues",
|
|
31
|
+
"homepage": "https://github.com/Dwlad90/stylex-swc-plugin/tree/develop/packages/jest#readme",
|
|
30
32
|
"keywords": [
|
|
33
|
+
"babel-free",
|
|
34
|
+
"css-in-js",
|
|
35
|
+
"css-in-js-testing",
|
|
31
36
|
"jest",
|
|
37
|
+
"jest-transform",
|
|
38
|
+
"jest-transformer",
|
|
39
|
+
"napi-rs",
|
|
40
|
+
"react-testing",
|
|
41
|
+
"rust",
|
|
32
42
|
"stylex",
|
|
33
|
-
"
|
|
43
|
+
"stylex-jest",
|
|
44
|
+
"swc",
|
|
45
|
+
"testing"
|
|
34
46
|
],
|
|
35
47
|
"main": "dist/index.js",
|
|
36
|
-
"repository":
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/Dwlad90/stylex-swc-plugin.git",
|
|
51
|
+
"directory": "packages/jest"
|
|
52
|
+
},
|
|
37
53
|
"scripts": {
|
|
38
54
|
"build": "scripty --ts",
|
|
39
55
|
"check:artifacts": "scripty",
|