@lynx-js/react 0.118.0 → 0.119.0
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/CHANGELOG.md +44 -0
- package/package.json +25 -3
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/lib/alog/elementPAPICall.js +1 -0
- package/runtime/lib/alog/elementPAPICall.js.map +1 -1
- package/runtime/lib/debug/component-stack.d.ts +0 -6
- package/runtime/lib/debug/component-stack.js.map +1 -1
- package/runtime/lib/gesture/processGesture.js +103 -11
- package/runtime/lib/gesture/processGesture.js.map +1 -1
- package/runtime/lib/hooks/mainThread.d.ts +17 -0
- package/runtime/lib/hooks/mainThread.js +152 -0
- package/runtime/lib/hooks/mainThread.js.map +1 -0
- package/runtime/lib/hooks/react.d.ts +1 -2
- package/runtime/lib/hooks/react.js +8 -14
- package/runtime/lib/hooks/react.js.map +1 -1
- package/runtime/lib/lifecycle/event/jsReady.js +3 -1
- package/runtime/lib/lifecycle/event/jsReady.js.map +1 -1
- package/runtime/lib/lifecycle/render.js +0 -6
- package/runtime/lib/lifecycle/render.js.map +1 -1
- package/runtime/lib/renderToOpcodes/constants.d.ts +1 -0
- package/runtime/lib/renderToOpcodes/constants.js +1 -0
- package/runtime/lib/renderToOpcodes/constants.js.map +1 -1
- package/runtime/lib/renderToOpcodes/index.js +3 -1
- package/runtime/lib/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/testing-library/README.md +48 -9
- package/testing-library/dist/0~123.js +43 -0
- package/testing-library/dist/881.js +1 -0
- package/testing-library/dist/entry.d.ts +1 -0
- package/testing-library/dist/env/index.d.ts +2 -0
- package/testing-library/dist/env/index.js +661 -0
- package/testing-library/dist/env/rstest.d.ts +1 -0
- package/testing-library/dist/env/rstest.js +6 -0
- package/testing-library/dist/env/vitest.d.ts +3 -0
- package/testing-library/dist/env/vitest.js +8 -662
- package/testing-library/dist/fire-event.d.ts +111 -0
- package/testing-library/dist/index.d.ts +18 -6
- package/testing-library/dist/plugins/index.d.ts +2 -0
- package/testing-library/dist/plugins/index.js +282 -0
- package/testing-library/dist/plugins/vitest.d.ts +26 -0
- package/testing-library/dist/pure.js +2 -2
- package/testing-library/dist/rstest-config.d.ts +25 -0
- package/testing-library/dist/rstest-config.js +61 -0
- package/testing-library/dist/setupFiles/common/bootstrap.js +2 -0
- package/testing-library/dist/{vitest-global-setup.js → setupFiles/common/runtime-setup.js} +25 -39
- package/testing-library/dist/setupFiles/inner/rstest.js +7 -0
- package/testing-library/dist/setupFiles/inner/vitest.js +11 -0
- package/testing-library/dist/setupFiles/rstest.js +21 -0
- package/testing-library/dist/setupFiles/vitest.js +20 -0
- package/testing-library/dist/vitest.config.d.ts +6 -0
- package/testing-library/dist/vitest.config.js +4 -257
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +10 -0
- package/testing-library/types/vitest-config.d.ts +0 -20
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
export declare const fireEvent: any;
|
|
2
|
+
export declare const eventMap: {
|
|
3
|
+
tap: {
|
|
4
|
+
defaultInit: {};
|
|
5
|
+
};
|
|
6
|
+
longtap: {
|
|
7
|
+
defaultInit: {};
|
|
8
|
+
};
|
|
9
|
+
bgload: {
|
|
10
|
+
defaultInit: {};
|
|
11
|
+
};
|
|
12
|
+
bgerror: {
|
|
13
|
+
defaultInit: {};
|
|
14
|
+
};
|
|
15
|
+
touchstart: {
|
|
16
|
+
defaultInit: {};
|
|
17
|
+
};
|
|
18
|
+
touchmove: {
|
|
19
|
+
defaultInit: {};
|
|
20
|
+
};
|
|
21
|
+
touchcancel: {
|
|
22
|
+
defaultInit: {};
|
|
23
|
+
};
|
|
24
|
+
touchend: {
|
|
25
|
+
defaultInit: {};
|
|
26
|
+
};
|
|
27
|
+
longpress: {
|
|
28
|
+
defaultInit: {};
|
|
29
|
+
};
|
|
30
|
+
transitionstart: {
|
|
31
|
+
defaultInit: {};
|
|
32
|
+
};
|
|
33
|
+
transitioncancel: {
|
|
34
|
+
defaultInit: {};
|
|
35
|
+
};
|
|
36
|
+
transitionend: {
|
|
37
|
+
defaultInit: {};
|
|
38
|
+
};
|
|
39
|
+
animationstart: {
|
|
40
|
+
defaultInit: {};
|
|
41
|
+
};
|
|
42
|
+
animationiteration: {
|
|
43
|
+
defaultInit: {};
|
|
44
|
+
};
|
|
45
|
+
animationcancel: {
|
|
46
|
+
defaultInit: {};
|
|
47
|
+
};
|
|
48
|
+
animationend: {
|
|
49
|
+
defaultInit: {};
|
|
50
|
+
};
|
|
51
|
+
mousedown: {
|
|
52
|
+
defaultInit: {};
|
|
53
|
+
};
|
|
54
|
+
mouseup: {
|
|
55
|
+
defaultInit: {};
|
|
56
|
+
};
|
|
57
|
+
mousemove: {
|
|
58
|
+
defaultInit: {};
|
|
59
|
+
};
|
|
60
|
+
mouseclick: {
|
|
61
|
+
defaultInit: {};
|
|
62
|
+
};
|
|
63
|
+
mousedblclick: {
|
|
64
|
+
defaultInit: {};
|
|
65
|
+
};
|
|
66
|
+
mouselongpress: {
|
|
67
|
+
defaultInit: {};
|
|
68
|
+
};
|
|
69
|
+
wheel: {
|
|
70
|
+
defaultInit: {};
|
|
71
|
+
};
|
|
72
|
+
keydown: {
|
|
73
|
+
defaultInit: {};
|
|
74
|
+
};
|
|
75
|
+
keyup: {
|
|
76
|
+
defaultInit: {};
|
|
77
|
+
};
|
|
78
|
+
focus: {
|
|
79
|
+
defaultInit: {};
|
|
80
|
+
};
|
|
81
|
+
blur: {
|
|
82
|
+
defaultInit: {};
|
|
83
|
+
};
|
|
84
|
+
layoutchange: {
|
|
85
|
+
defaultInit: {};
|
|
86
|
+
};
|
|
87
|
+
scrolltoupper: {
|
|
88
|
+
defaultInit: {};
|
|
89
|
+
};
|
|
90
|
+
scrolltolower: {
|
|
91
|
+
defaultInit: {};
|
|
92
|
+
};
|
|
93
|
+
scroll: {
|
|
94
|
+
defaultInit: {};
|
|
95
|
+
};
|
|
96
|
+
scrollend: {
|
|
97
|
+
defaultInit: {};
|
|
98
|
+
};
|
|
99
|
+
contentsizechanged: {
|
|
100
|
+
defaultInit: {};
|
|
101
|
+
};
|
|
102
|
+
scrolltoupperedge: {
|
|
103
|
+
defaultInit: {};
|
|
104
|
+
};
|
|
105
|
+
scrolltoloweredge: {
|
|
106
|
+
defaultInit: {};
|
|
107
|
+
};
|
|
108
|
+
scrolltonormalstate: {
|
|
109
|
+
defaultInit: {};
|
|
110
|
+
};
|
|
111
|
+
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { act } from 'preact/test-utils';
|
|
2
2
|
import { ARIARole } from 'aria-query';
|
|
3
|
-
import { JSDOM } from 'jsdom';
|
|
4
3
|
import { OptionsReceived } from 'pretty-format';
|
|
5
4
|
import * as prettyFormat from 'pretty-format';
|
|
6
5
|
|
|
@@ -775,6 +774,7 @@ declare const initElementTree: () => {
|
|
|
775
774
|
__AddDataset(e: LynxElement, key: string, value: string): void;
|
|
776
775
|
__SetDataset(e: LynxElement, dataset: any): void;
|
|
777
776
|
__SetGestureDetector(e: LynxElement, id: number, type: number, config: any, relationMap: Record<string, number[]>): void;
|
|
777
|
+
__RemoveGestureDetector(e: LynxElement, id: number): void;
|
|
778
778
|
__GetDataset(e: LynxElement): DOMStringMap;
|
|
779
779
|
__RemoveElement(parent: LynxElement, child: LynxElement): void;
|
|
780
780
|
__InsertElementBefore(parent: LynxElement, child: LynxElement, ref?: LynxElement | undefined): void;
|
|
@@ -883,6 +883,15 @@ declare interface LynxElement extends HTMLElement {
|
|
|
883
883
|
parentNode: LynxElement;
|
|
884
884
|
}
|
|
885
885
|
|
|
886
|
+
/**
|
|
887
|
+
* The host environment used to initialize `LynxTestingEnv`.
|
|
888
|
+
*
|
|
889
|
+
* @public
|
|
890
|
+
*/
|
|
891
|
+
declare interface LynxEnv {
|
|
892
|
+
window: Window & typeof globalThis;
|
|
893
|
+
}
|
|
894
|
+
|
|
886
895
|
/**
|
|
887
896
|
* The `globalThis` object of Lynx dual thread environment.
|
|
888
897
|
*
|
|
@@ -904,8 +913,9 @@ declare interface LynxGlobalThis {
|
|
|
904
913
|
*
|
|
905
914
|
* ```ts
|
|
906
915
|
* import { LynxTestingEnv } from '@lynx-js/testing-environment';
|
|
916
|
+
* import { JSDOM } from 'jsdom';
|
|
907
917
|
*
|
|
908
|
-
* const lynxTestingEnv = new LynxTestingEnv(new JSDOM());
|
|
918
|
+
* const lynxTestingEnv = new LynxTestingEnv({ window: new JSDOM().window });
|
|
909
919
|
*
|
|
910
920
|
* lynxTestingEnv.switchToMainThread();
|
|
911
921
|
* // use the main thread Element PAPI
|
|
@@ -926,8 +936,9 @@ export declare class LynxTestingEnv {
|
|
|
926
936
|
*
|
|
927
937
|
* ```ts
|
|
928
938
|
* import { LynxTestingEnv } from '@lynx-js/testing-environment';
|
|
939
|
+
* import { JSDOM } from 'jsdom';
|
|
929
940
|
*
|
|
930
|
-
* const lynxTestingEnv = new LynxTestingEnv(new JSDOM());
|
|
941
|
+
* const lynxTestingEnv = new LynxTestingEnv({ window: new JSDOM().window });
|
|
931
942
|
*
|
|
932
943
|
* lynxTestingEnv.switchToBackgroundThread();
|
|
933
944
|
* // use the background thread global object
|
|
@@ -942,8 +953,9 @@ export declare class LynxTestingEnv {
|
|
|
942
953
|
*
|
|
943
954
|
* ```ts
|
|
944
955
|
* import { LynxTestingEnv } from '@lynx-js/testing-environment';
|
|
956
|
+
* import { JSDOM } from 'jsdom';
|
|
945
957
|
*
|
|
946
|
-
* const lynxTestingEnv = new LynxTestingEnv(new JSDOM());
|
|
958
|
+
* const lynxTestingEnv = new LynxTestingEnv({ window: new JSDOM().window });
|
|
947
959
|
*
|
|
948
960
|
* lynxTestingEnv.switchToMainThread();
|
|
949
961
|
* // use the main thread global object
|
|
@@ -953,8 +965,8 @@ export declare class LynxTestingEnv {
|
|
|
953
965
|
* ```
|
|
954
966
|
*/
|
|
955
967
|
mainThread: LynxGlobalThis & ElementTreeGlobals;
|
|
956
|
-
|
|
957
|
-
constructor(
|
|
968
|
+
env: LynxEnv;
|
|
969
|
+
constructor(env?: LynxEnv);
|
|
958
970
|
injectGlobals(): void;
|
|
959
971
|
switchToBackgroundThread(): void;
|
|
960
972
|
switchToMainThread(): void;
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { VitestPackageInstaller } from "vitest/node";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { createRequire } from "../881.js";
|
|
5
|
+
const vitest_filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const vitest_dirname = node_path.dirname(vitest_filename);
|
|
7
|
+
const vitest_require = createRequire(import.meta.url);
|
|
8
|
+
function testingLibraryPlugin(options) {
|
|
9
|
+
const runtimeOSSPkgName = '@lynx-js/react';
|
|
10
|
+
const runtimePkgName = options?.runtimePkgName ?? runtimeOSSPkgName;
|
|
11
|
+
const runtimeDir = node_path.dirname(vitest_require.resolve(`${runtimePkgName}/package.json`));
|
|
12
|
+
const runtimeOSSDir = node_path.dirname(vitest_require.resolve(`${runtimeOSSPkgName}/package.json`, {
|
|
13
|
+
paths: [
|
|
14
|
+
runtimeDir,
|
|
15
|
+
vitest_dirname
|
|
16
|
+
]
|
|
17
|
+
}));
|
|
18
|
+
const preactDir = node_path.dirname(vitest_require.resolve('preact/package.json', {
|
|
19
|
+
paths: [
|
|
20
|
+
runtimeOSSDir
|
|
21
|
+
]
|
|
22
|
+
}));
|
|
23
|
+
const runtimeOSSAlias = generateAlias(runtimeOSSPkgName, runtimeOSSDir, runtimeDir);
|
|
24
|
+
let runtimeAlias = [];
|
|
25
|
+
if (runtimePkgName !== runtimeOSSPkgName) runtimeAlias = generateAlias(runtimePkgName, runtimeDir, vitest_dirname);
|
|
26
|
+
const preactAlias = generateAlias('preact', preactDir, runtimeOSSDir);
|
|
27
|
+
preactAlias.forEach((alias)=>{
|
|
28
|
+
alias.replacement = alias.replacement.replace(/\.js$/, '.mjs');
|
|
29
|
+
});
|
|
30
|
+
const reactAlias = [
|
|
31
|
+
{
|
|
32
|
+
find: /^react$/,
|
|
33
|
+
replacement: vitest_require.resolve(runtimeOSSPkgName, {
|
|
34
|
+
paths: [
|
|
35
|
+
runtimeDir,
|
|
36
|
+
vitest_dirname
|
|
37
|
+
]
|
|
38
|
+
})
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
find: /^react\/jsx-runtime$/,
|
|
42
|
+
replacement: vitest_require.resolve(node_path.posix.join(runtimeOSSPkgName, 'jsx-runtime'), {
|
|
43
|
+
paths: [
|
|
44
|
+
runtimeDir,
|
|
45
|
+
vitest_dirname
|
|
46
|
+
]
|
|
47
|
+
})
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
find: /^react\/jsx-dev-runtime$/,
|
|
51
|
+
replacement: vitest_require.resolve(node_path.posix.join(runtimeOSSPkgName, 'jsx-dev-runtime'), {
|
|
52
|
+
paths: [
|
|
53
|
+
runtimeDir,
|
|
54
|
+
vitest_dirname
|
|
55
|
+
]
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
];
|
|
59
|
+
function transformReactCompilerPlugin() {
|
|
60
|
+
let rootContext, compilerDeps, babel;
|
|
61
|
+
function resolveCompilerDeps(rootContext) {
|
|
62
|
+
const missingBabelPackages = [];
|
|
63
|
+
const [babelPath, babelPluginReactCompilerPath, babelPluginSyntaxJsxPath, babelPluginSyntaxTypescriptPath] = [
|
|
64
|
+
'@babel/core',
|
|
65
|
+
'babel-plugin-react-compiler',
|
|
66
|
+
'@babel/plugin-syntax-jsx',
|
|
67
|
+
"@babel/plugin-syntax-typescript"
|
|
68
|
+
].map((name)=>{
|
|
69
|
+
try {
|
|
70
|
+
return vitest_require.resolve(name, {
|
|
71
|
+
paths: [
|
|
72
|
+
rootContext
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
} catch {
|
|
76
|
+
missingBabelPackages.push(name);
|
|
77
|
+
}
|
|
78
|
+
return '';
|
|
79
|
+
});
|
|
80
|
+
if (missingBabelPackages.length > 0) throw new Error(`With \`experimental_enableReactCompiler\` enabled, you need to install \`${missingBabelPackages.join('`, `')}\` in your project root to use React Compiler.`);
|
|
81
|
+
return {
|
|
82
|
+
babelPath,
|
|
83
|
+
babelPluginReactCompilerPath,
|
|
84
|
+
babelPluginSyntaxJsxPath,
|
|
85
|
+
babelPluginSyntaxTypescriptPath
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
name: 'transformReactCompilerPlugin',
|
|
90
|
+
enforce: 'pre',
|
|
91
|
+
config (config) {
|
|
92
|
+
rootContext = config.root;
|
|
93
|
+
const reactCompilerRuntimeAlias = [];
|
|
94
|
+
try {
|
|
95
|
+
reactCompilerRuntimeAlias.push({
|
|
96
|
+
find: /^react-compiler-runtime$/,
|
|
97
|
+
replacement: node_path.join(node_path.dirname(vitest_require.resolve('react-compiler-runtime/package.json', {
|
|
98
|
+
paths: [
|
|
99
|
+
rootContext
|
|
100
|
+
]
|
|
101
|
+
})), 'src', 'index.ts')
|
|
102
|
+
});
|
|
103
|
+
} catch (e) {}
|
|
104
|
+
let mergedAlias = [
|
|
105
|
+
...reactCompilerRuntimeAlias
|
|
106
|
+
];
|
|
107
|
+
if (config.test?.alias) mergedAlias = Array.isArray(config.test.alias) ? [
|
|
108
|
+
...config.test.alias,
|
|
109
|
+
...mergedAlias
|
|
110
|
+
] : [
|
|
111
|
+
...Object.entries(config.test.alias).map(([key, value])=>({
|
|
112
|
+
find: key,
|
|
113
|
+
replacement: value
|
|
114
|
+
})),
|
|
115
|
+
...mergedAlias
|
|
116
|
+
];
|
|
117
|
+
config.test = config.test || {};
|
|
118
|
+
config.test.alias = mergedAlias;
|
|
119
|
+
compilerDeps = resolveCompilerDeps(rootContext);
|
|
120
|
+
const { babelPath } = compilerDeps;
|
|
121
|
+
babel = vitest_require(babelPath);
|
|
122
|
+
},
|
|
123
|
+
async transform (sourceText, sourcePath) {
|
|
124
|
+
if (/\.(?:jsx|tsx)$/.test(sourcePath)) {
|
|
125
|
+
const { babelPluginReactCompilerPath, babelPluginSyntaxJsxPath, babelPluginSyntaxTypescriptPath } = compilerDeps;
|
|
126
|
+
const isTSX = sourcePath.endsWith('.tsx');
|
|
127
|
+
try {
|
|
128
|
+
const result = babel.transformSync(sourceText, {
|
|
129
|
+
plugins: [
|
|
130
|
+
[
|
|
131
|
+
babelPluginReactCompilerPath,
|
|
132
|
+
{
|
|
133
|
+
target: '17'
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
babelPluginSyntaxJsxPath,
|
|
137
|
+
isTSX ? [
|
|
138
|
+
babelPluginSyntaxTypescriptPath,
|
|
139
|
+
{
|
|
140
|
+
isTSX: true
|
|
141
|
+
}
|
|
142
|
+
] : null
|
|
143
|
+
].filter(Boolean),
|
|
144
|
+
filename: sourcePath,
|
|
145
|
+
ast: false,
|
|
146
|
+
sourceMaps: true
|
|
147
|
+
});
|
|
148
|
+
if (result?.code != null && result?.map != null) return {
|
|
149
|
+
code: result.code,
|
|
150
|
+
map: result.map
|
|
151
|
+
};
|
|
152
|
+
this.error(`babel-plugin-react-compiler transform failed for ${sourcePath}: ${result ? 'missing code or map' : 'no result'}`);
|
|
153
|
+
} catch (e) {
|
|
154
|
+
this.error(e);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
let config;
|
|
162
|
+
function transformReactLynxPlugin() {
|
|
163
|
+
return {
|
|
164
|
+
name: 'transformReactLynxPlugin',
|
|
165
|
+
enforce: 'pre',
|
|
166
|
+
async buildStart () {
|
|
167
|
+
await ensurePackagesInstalled();
|
|
168
|
+
},
|
|
169
|
+
transform (sourceText, sourcePath) {
|
|
170
|
+
const id = sourcePath;
|
|
171
|
+
const regex = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)(\?.*)?$/;
|
|
172
|
+
if (!regex.test(id)) return null;
|
|
173
|
+
const { transformReactLynxSync } = vitest_require('@lynx-js/react/transform');
|
|
174
|
+
const relativePath = normalizeSlashes(node_path.relative(config.root, sourcePath));
|
|
175
|
+
const basename = node_path.basename(sourcePath);
|
|
176
|
+
const result = transformReactLynxSync(sourceText, {
|
|
177
|
+
mode: 'test',
|
|
178
|
+
pluginName: '',
|
|
179
|
+
filename: basename,
|
|
180
|
+
sourcemap: true,
|
|
181
|
+
snapshot: {
|
|
182
|
+
preserveJsx: false,
|
|
183
|
+
runtimePkg: `${runtimePkgName}/internal`,
|
|
184
|
+
jsxImportSource: runtimePkgName,
|
|
185
|
+
filename: relativePath,
|
|
186
|
+
target: 'MIXED'
|
|
187
|
+
},
|
|
188
|
+
engineVersion: options?.engineVersion ?? '',
|
|
189
|
+
dynamicImport: {
|
|
190
|
+
injectLazyBundle: false,
|
|
191
|
+
layer: 'test',
|
|
192
|
+
runtimePkg: `${runtimePkgName}/internal`
|
|
193
|
+
},
|
|
194
|
+
directiveDCE: false,
|
|
195
|
+
defineDCE: false,
|
|
196
|
+
shake: false,
|
|
197
|
+
compat: false,
|
|
198
|
+
worklet: {
|
|
199
|
+
filename: relativePath,
|
|
200
|
+
runtimePkg: `${runtimePkgName}/internal`,
|
|
201
|
+
target: 'MIXED'
|
|
202
|
+
},
|
|
203
|
+
refresh: false,
|
|
204
|
+
cssScope: false
|
|
205
|
+
});
|
|
206
|
+
if (result.errors.length > 0) result.errors.forEach((error)=>{
|
|
207
|
+
this.error(error.text ?? 'Unknown error', {
|
|
208
|
+
line: 1,
|
|
209
|
+
column: 1,
|
|
210
|
+
...error.location
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
if (result.warnings.length > 0) result.warnings.forEach((warning)=>{
|
|
214
|
+
this.warn(warning.text ?? 'Unknown warning', {
|
|
215
|
+
line: 1,
|
|
216
|
+
column: 1,
|
|
217
|
+
...warning.location
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
return {
|
|
221
|
+
code: result.code,
|
|
222
|
+
map: result.map
|
|
223
|
+
};
|
|
224
|
+
},
|
|
225
|
+
config: ()=>({
|
|
226
|
+
test: {
|
|
227
|
+
environment: vitest_require.resolve(`${runtimeOSSDir}/testing-library/dist/env/vitest`),
|
|
228
|
+
globals: true,
|
|
229
|
+
setupFiles: [
|
|
230
|
+
vitest_require.resolve('../setupFiles/vitest')
|
|
231
|
+
],
|
|
232
|
+
alias: [
|
|
233
|
+
...runtimeOSSAlias,
|
|
234
|
+
...runtimeAlias,
|
|
235
|
+
...preactAlias,
|
|
236
|
+
...reactAlias
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
}),
|
|
240
|
+
configResolved (_config) {
|
|
241
|
+
config = _config;
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
return [
|
|
246
|
+
...options?.experimental_enableReactCompiler ? [
|
|
247
|
+
transformReactCompilerPlugin()
|
|
248
|
+
] : [],
|
|
249
|
+
transformReactLynxPlugin()
|
|
250
|
+
];
|
|
251
|
+
}
|
|
252
|
+
async function ensurePackagesInstalled() {
|
|
253
|
+
const installer = new VitestPackageInstaller();
|
|
254
|
+
const installed = await installer.ensureInstalled('jsdom', process.cwd());
|
|
255
|
+
if (!installed) {
|
|
256
|
+
console.log('ReactLynx Testing Library requires jsdom to be installed.');
|
|
257
|
+
process.exit(1);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function generateAlias(pkgName, pkgDir, resolveDir) {
|
|
261
|
+
const pkgExports = vitest_require(node_path.join(pkgDir, 'package.json')).exports;
|
|
262
|
+
if (!pkgExports || 'object' != typeof pkgExports) return [];
|
|
263
|
+
const pkgAlias = [];
|
|
264
|
+
Object.keys(pkgExports).forEach((key)=>{
|
|
265
|
+
const name = node_path.posix.join(pkgName, key);
|
|
266
|
+
const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
267
|
+
pkgAlias.push({
|
|
268
|
+
find: new RegExp('^' + escapedName + '$'),
|
|
269
|
+
replacement: vitest_require.resolve(name, {
|
|
270
|
+
paths: [
|
|
271
|
+
resolveDir,
|
|
272
|
+
vitest_dirname
|
|
273
|
+
]
|
|
274
|
+
})
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
return pkgAlias;
|
|
278
|
+
}
|
|
279
|
+
function normalizeSlashes(file) {
|
|
280
|
+
return file.replaceAll(node_path.win32.sep, '/');
|
|
281
|
+
}
|
|
282
|
+
export { testingLibraryPlugin as vitestTestingLibraryPlugin };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Vite } from 'vitest/node';
|
|
2
|
+
export interface TestingLibraryOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The package name of the ReactLynx runtime package.
|
|
5
|
+
*
|
|
6
|
+
* @default `@lynx-js/react`
|
|
7
|
+
*/
|
|
8
|
+
runtimePkgName?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The engine version to use for the transform.
|
|
11
|
+
*
|
|
12
|
+
* @default `''`
|
|
13
|
+
*/
|
|
14
|
+
engineVersion?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Enable experimental React Compiler support.
|
|
17
|
+
*
|
|
18
|
+
* Requires `@babel/core`, `babel-plugin-react-compiler`,
|
|
19
|
+
* `@babel/plugin-syntax-jsx`, and `@babel/plugin-syntax-typescript`
|
|
20
|
+
* to be installed in your project.
|
|
21
|
+
*
|
|
22
|
+
* @default `false`
|
|
23
|
+
*/
|
|
24
|
+
experimental_enableReactCompiler?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare function testingLibraryPlugin(options?: TestingLibraryOptions): Vite.PluginOption;
|
|
@@ -14477,7 +14477,7 @@ function pure_render(ui, { queries, wrapper: WrapperComponent, enableMainThread
|
|
|
14477
14477
|
});
|
|
14478
14478
|
},
|
|
14479
14479
|
asFragment: ()=>{
|
|
14480
|
-
const { document: document1 } = lynxTestingEnv.
|
|
14480
|
+
const { document: document1 } = lynxTestingEnv.env.window;
|
|
14481
14481
|
const container = lynxTestingEnv.mainThread.elementTree.root;
|
|
14482
14482
|
if ('function' == typeof document1.createRange) return document1.createRange().createContextualFragment(container.innerHTML);
|
|
14483
14483
|
{
|
|
@@ -14497,7 +14497,7 @@ function cleanup() {
|
|
|
14497
14497
|
});
|
|
14498
14498
|
lynxTestingEnv.mainThread.elementTree.root = void 0;
|
|
14499
14499
|
clearPage();
|
|
14500
|
-
lynxTestingEnv.
|
|
14500
|
+
lynxTestingEnv.env.window.document.body.innerHTML = '';
|
|
14501
14501
|
if (isMainThread) globalThis.lynxTestingEnv.switchToMainThread();
|
|
14502
14502
|
}
|
|
14503
14503
|
function renderHook(renderCallback, options) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ExtendConfig, ExtendConfigFn } from '@rstest/core';
|
|
2
|
+
export interface LynxConfigOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The root path of the project.
|
|
5
|
+
*
|
|
6
|
+
* @default `process.cwd()`
|
|
7
|
+
*/
|
|
8
|
+
rootPath?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The path to the Lynx config file.
|
|
11
|
+
*
|
|
12
|
+
* @default `lynx.config.ts`
|
|
13
|
+
*/
|
|
14
|
+
configPath?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface RstestConfigOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Customize the generated rstest config.
|
|
19
|
+
*/
|
|
20
|
+
modifyRstestConfig?: (config: ExtendConfig) => ExtendConfig | Promise<ExtendConfig>;
|
|
21
|
+
}
|
|
22
|
+
export interface LynxRstestConfigOptions extends LynxConfigOptions, RstestConfigOptions {
|
|
23
|
+
}
|
|
24
|
+
export declare function withDefaultConfig(options?: RstestConfigOptions): ExtendConfigFn;
|
|
25
|
+
export declare function withLynxConfig(options?: LynxRstestConfigOptions): ExtendConfigFn;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createRequire } from "./881.js";
|
|
2
|
+
const rstest_config_require = createRequire(import.meta.url);
|
|
3
|
+
function createDefaultRstestConfig() {
|
|
4
|
+
return {
|
|
5
|
+
testEnvironment: 'jsdom',
|
|
6
|
+
setupFiles: [
|
|
7
|
+
rstest_config_require.resolve('./setupFiles/rstest')
|
|
8
|
+
],
|
|
9
|
+
globals: true
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function normalizeSetupFiles(setupFiles) {
|
|
13
|
+
if (!setupFiles) return [];
|
|
14
|
+
return Array.isArray(setupFiles) ? setupFiles : [
|
|
15
|
+
setupFiles
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
async function applyRstestConfigModifier(config, modifyRstestConfig) {
|
|
19
|
+
if (!modifyRstestConfig) return config;
|
|
20
|
+
return await modifyRstestConfig(config);
|
|
21
|
+
}
|
|
22
|
+
function withDefaultConfig(options) {
|
|
23
|
+
return async ()=>await applyRstestConfigModifier(createDefaultRstestConfig(), options?.modifyRstestConfig);
|
|
24
|
+
}
|
|
25
|
+
function withLynxConfig(options) {
|
|
26
|
+
return async ()=>{
|
|
27
|
+
const { loadConfig } = await import("@lynx-js/rspeedy");
|
|
28
|
+
const lynxConfig = await loadConfig({
|
|
29
|
+
cwd: options?.rootPath,
|
|
30
|
+
configPath: options?.configPath
|
|
31
|
+
});
|
|
32
|
+
const { toRstestConfig } = await import("./0~123.js").then((mod)=>({
|
|
33
|
+
toRstestConfig: mod.toRstestConfig
|
|
34
|
+
}));
|
|
35
|
+
const rstestConfig = toRstestConfig({
|
|
36
|
+
rsbuildConfig: lynxConfig.content
|
|
37
|
+
});
|
|
38
|
+
const defaultConfig = createDefaultRstestConfig();
|
|
39
|
+
const setupFiles = Array.from(new Set([
|
|
40
|
+
...normalizeSetupFiles(rstestConfig.setupFiles),
|
|
41
|
+
...normalizeSetupFiles(defaultConfig.setupFiles)
|
|
42
|
+
]));
|
|
43
|
+
const mergedConfig = {
|
|
44
|
+
...rstestConfig,
|
|
45
|
+
...defaultConfig,
|
|
46
|
+
plugins: [
|
|
47
|
+
...rstestConfig.plugins || [],
|
|
48
|
+
{
|
|
49
|
+
name: 'lynx-adapter:remove-useless-plugins',
|
|
50
|
+
remove: [
|
|
51
|
+
'lynx:rsbuild:qrcode'
|
|
52
|
+
],
|
|
53
|
+
setup: ()=>{}
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
setupFiles
|
|
57
|
+
};
|
|
58
|
+
return await applyRstestConfigModifier(mergedConfig, options?.modifyRstestConfig);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export { withDefaultConfig, withLynxConfig };
|