@atomic-testing/react-legacy 0.80.0 → 0.84.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/dist/index.cjs +13 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.mjs +3 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +23 -23
- package/src/createTestEngine.ts +2 -3
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -6,16 +7,12 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
9
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
19
16
|
}
|
|
20
17
|
return to;
|
|
21
18
|
};
|
|
@@ -23,14 +20,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
20
|
value: mod,
|
|
24
21
|
enumerable: true
|
|
25
22
|
}) : target, mod));
|
|
26
|
-
|
|
27
23
|
//#endregion
|
|
28
|
-
let react_dom = require("react-dom");
|
|
29
|
-
react_dom = __toESM(react_dom);
|
|
30
|
-
let react_dom_test_utils = require("react-dom/test-utils");
|
|
31
24
|
let _atomic_testing_core = require("@atomic-testing/core");
|
|
32
25
|
let _atomic_testing_react_core = require("@atomic-testing/react-core");
|
|
33
|
-
|
|
26
|
+
let react_dom = require("react-dom");
|
|
27
|
+
react_dom = __toESM(react_dom);
|
|
28
|
+
let react_dom_test_utils_js = require("react-dom/test-utils.js");
|
|
34
29
|
//#region src/createTestEngine.ts
|
|
35
30
|
let _rootId = 0;
|
|
36
31
|
function getNextRootElementId() {
|
|
@@ -51,7 +46,7 @@ function createTestEngine(node, partDefinitions, option) {
|
|
|
51
46
|
const container = rootEl.appendChild(document.createElement("div"));
|
|
52
47
|
const rootId = getNextRootElementId();
|
|
53
48
|
container.setAttribute(rootElementAttributeName, rootId);
|
|
54
|
-
(0,
|
|
49
|
+
(0, react_dom_test_utils_js.act)(() => {
|
|
55
50
|
react_dom.default.render(node, container);
|
|
56
51
|
});
|
|
57
52
|
const cleanup = () => {
|
|
@@ -79,8 +74,8 @@ function createRenderedTestEngine(rootElement, partDefinitions, _option) {
|
|
|
79
74
|
};
|
|
80
75
|
return new _atomic_testing_core.TestEngine((0, _atomic_testing_core.byAttribute)(rootElementAttributeName, rootId), new _atomic_testing_react_core.ReactInteractor(), { parts: partDefinitions }, cleanup);
|
|
81
76
|
}
|
|
82
|
-
|
|
83
77
|
//#endregion
|
|
84
78
|
exports.createRenderedTestEngine = createRenderedTestEngine;
|
|
85
79
|
exports.createTestEngine = createTestEngine;
|
|
80
|
+
|
|
86
81
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["TestEngine","ReactInteractor"],"sources":["../src/createTestEngine.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["TestEngine","ReactInteractor"],"sources":["../src/createTestEngine.ts"],"sourcesContent":["import { byAttribute, ScenePart, TestEngine } from '@atomic-testing/core';\nimport { ReactInteractor } from '@atomic-testing/react-core';\nimport { ReactElement } from 'react';\nimport ReactDOM from 'react-dom';\nimport { act } from 'react-dom/test-utils';\n\nimport { IReactTestEngineOption } from './types';\n\nlet _rootId = 0;\nfunction getNextRootElementId() {\n return `${_rootId++}`;\n}\n\nconst rootElementAttributeName = 'data-atomic-testing-react-legacy';\n\n/**\n * Create test engine for React 17 or before, for React 18 or later, use @atomic-testing/react-18 or @atomic-testing/react-19\n * This function takes a react node and render it into a container element. For rendered\n * components, use createRenderedLegacyTestEngine\n * @param node The React node to render\n * @param partDefinitions The scene part definitions\n * @param option\n * @returns The test engine\n */\nexport function createTestEngine<T extends ScenePart>(\n node: ReactElement,\n partDefinitions: T,\n option?: Readonly<Partial<IReactTestEngineOption>>\n): TestEngine<T> {\n const rootEl = option?.rootElement ?? document.body;\n const container = rootEl.appendChild(document.createElement('div'));\n const rootId = getNextRootElementId();\n container.setAttribute(rootElementAttributeName, rootId);\n\n act(() => {\n ReactDOM.render(node, container);\n });\n const cleanup = () => {\n ReactDOM.unmountComponentAtNode(container);\n rootEl.removeChild(container);\n return Promise.resolve();\n };\n\n const engine = new TestEngine(\n byAttribute(rootElementAttributeName, rootId),\n new ReactInteractor(),\n {\n parts: partDefinitions,\n },\n cleanup\n );\n\n return engine;\n}\n\n/**\n * Create test engine for React 17 or before, for React 18 or later, use @atomic-testing/react-18 or @atomic-testing/react-19\n * This function takes an html element purportedly rendered by React and create a test engine for it, it\n * can be useful in environment such as Storybook where Storybook renders the component and the test\n * @param rootElement The React node to render\n * @param partDefinitions The scene part definitions\n * @param option\n * @returns The test engine\n */\nexport function createRenderedTestEngine<T extends ScenePart>(\n rootElement: HTMLElement,\n partDefinitions: T,\n _option?: Readonly<Partial<IReactTestEngineOption>>\n): TestEngine<T> {\n const rootId = getNextRootElementId();\n rootElement.setAttribute(rootElementAttributeName, rootId);\n\n const cleanup = () => {\n rootElement.removeAttribute(rootElementAttributeName);\n return Promise.resolve();\n };\n\n const engine = new TestEngine(\n byAttribute(rootElementAttributeName, rootId),\n new ReactInteractor(),\n {\n parts: partDefinitions,\n },\n cleanup\n );\n\n return engine;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,IAAI,UAAU;AACd,SAAS,uBAAuB;CAC9B,OAAO,GAAG;AACZ;AAEA,MAAM,2BAA2B;;;;;;;;;;AAWjC,SAAgB,iBACd,MACA,iBACA,QACe;CACf,MAAM,SAAS,QAAQ,eAAe,SAAS;CAC/C,MAAM,YAAY,OAAO,YAAY,SAAS,cAAc,KAAK,CAAC;CAClE,MAAM,SAAS,qBAAqB;CACpC,UAAU,aAAa,0BAA0B,MAAM;CAEvD,CAAA,GAAA,wBAAA,IAAA,OAAU;EACR,UAAA,QAAS,OAAO,MAAM,SAAS;CACjC,CAAC;CACD,MAAM,gBAAgB;EACpB,UAAA,QAAS,uBAAuB,SAAS;EACzC,OAAO,YAAY,SAAS;EAC5B,OAAO,QAAQ,QAAQ;CACzB;CAWA,OAAO,IATYA,qBAAAA,YAAAA,GAAAA,qBAAAA,YAAAA,CACL,0BAA0B,MAAM,GAC5C,IAAIC,2BAAAA,gBAAgB,GACpB,EACE,OAAO,gBACT,GACA,OAGU;AACd;;;;;;;;;;AAWA,SAAgB,yBACd,aACA,iBACA,SACe;CACf,MAAM,SAAS,qBAAqB;CACpC,YAAY,aAAa,0BAA0B,MAAM;CAEzD,MAAM,gBAAgB;EACpB,YAAY,gBAAgB,wBAAwB;EACpD,OAAO,QAAQ,QAAQ;CACzB;CAWA,OAAO,IATYD,qBAAAA,YAAAA,GAAAA,qBAAAA,YAAAA,CACL,0BAA0B,MAAM,GAC5C,IAAIC,2BAAAA,gBAAgB,GACpB,EACE,OAAO,gBACT,GACA,OAGU;AACd"}
|
package/dist/index.d.cts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import ReactDOM from "react-dom";
|
|
2
|
-
import { act } from "react-dom/test-utils";
|
|
3
1
|
import { TestEngine, byAttribute } from "@atomic-testing/core";
|
|
4
2
|
import { ReactInteractor } from "@atomic-testing/react-core";
|
|
5
|
-
|
|
3
|
+
import ReactDOM from "react-dom";
|
|
4
|
+
import { act } from "react-dom/test-utils.js";
|
|
6
5
|
//#region src/createTestEngine.ts
|
|
7
6
|
let _rootId = 0;
|
|
8
7
|
function getNextRootElementId() {
|
|
@@ -51,7 +50,7 @@ function createRenderedTestEngine(rootElement, partDefinitions, _option) {
|
|
|
51
50
|
};
|
|
52
51
|
return new TestEngine(byAttribute(rootElementAttributeName, rootId), new ReactInteractor(), { parts: partDefinitions }, cleanup);
|
|
53
52
|
}
|
|
54
|
-
|
|
55
53
|
//#endregion
|
|
56
54
|
export { createRenderedTestEngine, createTestEngine };
|
|
55
|
+
|
|
57
56
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/createTestEngine.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/createTestEngine.ts"],"sourcesContent":["import { byAttribute, ScenePart, TestEngine } from '@atomic-testing/core';\nimport { ReactInteractor } from '@atomic-testing/react-core';\nimport { ReactElement } from 'react';\nimport ReactDOM from 'react-dom';\nimport { act } from 'react-dom/test-utils';\n\nimport { IReactTestEngineOption } from './types';\n\nlet _rootId = 0;\nfunction getNextRootElementId() {\n return `${_rootId++}`;\n}\n\nconst rootElementAttributeName = 'data-atomic-testing-react-legacy';\n\n/**\n * Create test engine for React 17 or before, for React 18 or later, use @atomic-testing/react-18 or @atomic-testing/react-19\n * This function takes a react node and render it into a container element. For rendered\n * components, use createRenderedLegacyTestEngine\n * @param node The React node to render\n * @param partDefinitions The scene part definitions\n * @param option\n * @returns The test engine\n */\nexport function createTestEngine<T extends ScenePart>(\n node: ReactElement,\n partDefinitions: T,\n option?: Readonly<Partial<IReactTestEngineOption>>\n): TestEngine<T> {\n const rootEl = option?.rootElement ?? document.body;\n const container = rootEl.appendChild(document.createElement('div'));\n const rootId = getNextRootElementId();\n container.setAttribute(rootElementAttributeName, rootId);\n\n act(() => {\n ReactDOM.render(node, container);\n });\n const cleanup = () => {\n ReactDOM.unmountComponentAtNode(container);\n rootEl.removeChild(container);\n return Promise.resolve();\n };\n\n const engine = new TestEngine(\n byAttribute(rootElementAttributeName, rootId),\n new ReactInteractor(),\n {\n parts: partDefinitions,\n },\n cleanup\n );\n\n return engine;\n}\n\n/**\n * Create test engine for React 17 or before, for React 18 or later, use @atomic-testing/react-18 or @atomic-testing/react-19\n * This function takes an html element purportedly rendered by React and create a test engine for it, it\n * can be useful in environment such as Storybook where Storybook renders the component and the test\n * @param rootElement The React node to render\n * @param partDefinitions The scene part definitions\n * @param option\n * @returns The test engine\n */\nexport function createRenderedTestEngine<T extends ScenePart>(\n rootElement: HTMLElement,\n partDefinitions: T,\n _option?: Readonly<Partial<IReactTestEngineOption>>\n): TestEngine<T> {\n const rootId = getNextRootElementId();\n rootElement.setAttribute(rootElementAttributeName, rootId);\n\n const cleanup = () => {\n rootElement.removeAttribute(rootElementAttributeName);\n return Promise.resolve();\n };\n\n const engine = new TestEngine(\n byAttribute(rootElementAttributeName, rootId),\n new ReactInteractor(),\n {\n parts: partDefinitions,\n },\n cleanup\n );\n\n return engine;\n}\n"],"mappings":";;;;;AAQA,IAAI,UAAU;AACd,SAAS,uBAAuB;CAC9B,OAAO,GAAG;AACZ;AAEA,MAAM,2BAA2B;;;;;;;;;;AAWjC,SAAgB,iBACd,MACA,iBACA,QACe;CACf,MAAM,SAAS,QAAQ,eAAe,SAAS;CAC/C,MAAM,YAAY,OAAO,YAAY,SAAS,cAAc,KAAK,CAAC;CAClE,MAAM,SAAS,qBAAqB;CACpC,UAAU,aAAa,0BAA0B,MAAM;CAEvD,UAAU;EACR,SAAS,OAAO,MAAM,SAAS;CACjC,CAAC;CACD,MAAM,gBAAgB;EACpB,SAAS,uBAAuB,SAAS;EACzC,OAAO,YAAY,SAAS;EAC5B,OAAO,QAAQ,QAAQ;CACzB;CAWA,OAAO,IATY,WACjB,YAAY,0BAA0B,MAAM,GAC5C,IAAI,gBAAgB,GACpB,EACE,OAAO,gBACT,GACA,OAGU;AACd;;;;;;;;;;AAWA,SAAgB,yBACd,aACA,iBACA,SACe;CACf,MAAM,SAAS,qBAAqB;CACpC,YAAY,aAAa,0BAA0B,MAAM;CAEzD,MAAM,gBAAgB;EACpB,YAAY,gBAAgB,wBAAwB;EACpD,OAAO,QAAQ,QAAQ;CACzB;CAWA,OAAO,IATY,WACjB,YAAY,0BAA0B,MAAM,GAC5C,IAAI,gBAAgB,GACpB,EACE,OAAO,gBACT,GACA,OAGU;AACd"}
|
package/package.json
CHANGED
|
@@ -1,30 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomic-testing/react-legacy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.84.1",
|
|
4
4
|
"description": "Adapter for testing React 17 and earlier",
|
|
5
|
-
"main": "dist/index.cjs",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist",
|
|
9
|
-
"src"
|
|
10
|
-
],
|
|
11
|
-
"author": "Tianzhen Lin <tangent@usa.net>",
|
|
12
5
|
"keywords": [
|
|
13
|
-
"
|
|
6
|
+
"legacy",
|
|
14
7
|
"react",
|
|
15
|
-
"
|
|
8
|
+
"testing"
|
|
16
9
|
],
|
|
17
10
|
"license": "MIT",
|
|
11
|
+
"author": "Tianzhen Lin <tangent@usa.net>",
|
|
18
12
|
"repository": {
|
|
19
13
|
"type": "git",
|
|
20
14
|
"url": "https://github.com/atomic-testing/atomic-testing.git",
|
|
21
15
|
"directory": "packages/react-legacy"
|
|
22
16
|
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"main": "dist/index.cjs",
|
|
22
|
+
"module": "dist/index.mjs",
|
|
23
|
+
"types": "dist/index.d.cts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"import": "./dist/index.mjs",
|
|
28
|
+
"require": "./dist/index.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
23
31
|
"dependencies": {
|
|
24
32
|
"react-dom": "^17.0.0",
|
|
25
|
-
"@atomic-testing/core": "0.
|
|
26
|
-
"@atomic-testing/
|
|
27
|
-
"@atomic-testing/
|
|
33
|
+
"@atomic-testing/dom-core": "0.84.1",
|
|
34
|
+
"@atomic-testing/core": "0.84.1",
|
|
35
|
+
"@atomic-testing/react-core": "0.84.1"
|
|
28
36
|
},
|
|
29
37
|
"devDependencies": {
|
|
30
38
|
"@types/react": "^17.0.0",
|
|
@@ -33,22 +41,14 @@
|
|
|
33
41
|
"react-dom": "^17.0.0"
|
|
34
42
|
},
|
|
35
43
|
"peerDependencies": {
|
|
36
|
-
"@testing-library/dom": ">=
|
|
44
|
+
"@testing-library/dom": ">=10.4.1",
|
|
37
45
|
"@testing-library/react": ">=12.0.0",
|
|
38
46
|
"@testing-library/user-event": ">=14.0.0",
|
|
39
47
|
"react": "^16 || ^17",
|
|
40
48
|
"react-dom": "^16 || ^17"
|
|
41
49
|
},
|
|
42
|
-
"types": "dist/index.d.cts",
|
|
43
|
-
"exports": {
|
|
44
|
-
".": {
|
|
45
|
-
"types": "./dist/index.d.mts",
|
|
46
|
-
"import": "./dist/index.mjs",
|
|
47
|
-
"require": "./dist/index.cjs"
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsdown",
|
|
52
|
-
"check:type": "
|
|
52
|
+
"check:type": "tsgo --noEmit"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/src/createTestEngine.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import { byAttribute, ScenePart, TestEngine } from '@atomic-testing/core';
|
|
2
|
+
import { ReactInteractor } from '@atomic-testing/react-core';
|
|
1
3
|
import { ReactElement } from 'react';
|
|
2
4
|
import ReactDOM from 'react-dom';
|
|
3
5
|
import { act } from 'react-dom/test-utils';
|
|
4
6
|
|
|
5
|
-
import { byAttribute, ScenePart, TestEngine } from '@atomic-testing/core';
|
|
6
|
-
import { ReactInteractor } from '@atomic-testing/react-core';
|
|
7
|
-
|
|
8
7
|
import { IReactTestEngineOption } from './types';
|
|
9
8
|
|
|
10
9
|
let _rootId = 0;
|