@lowdefy/e2e-utils 0.0.0-experimental-20260202125814

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,164 @@
1
+ # @lowdefy/e2e-utils
2
+
3
+ Playwright testing utilities for Lowdefy applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add -D @lowdefy/e2e-utils @playwright/test
9
+ npx playwright install chromium
10
+ ```
11
+
12
+ ## Quick Start
13
+
14
+ Initialize e2e testing in your Lowdefy app:
15
+
16
+ ```bash
17
+ npx lowdefy-e2e init
18
+ ```
19
+
20
+ This creates:
21
+ - `e2e/playwright.config.js` - Pre-configured Playwright config
22
+ - `e2e/example.spec.js` - Starter test to copy from
23
+
24
+ Then run tests:
25
+
26
+ ```bash
27
+ pnpm e2e # Run tests
28
+ pnpm e2e:ui # Run with Playwright UI
29
+ ```
30
+
31
+ ## Core Helpers
32
+
33
+ Framework-level testing utilities:
34
+
35
+ ```javascript
36
+ import { ldf } from '@lowdefy/e2e-utils';
37
+
38
+ // Navigation
39
+ await ldf.goto(page, '/dashboard');
40
+ await ldf.waitForReady(page);
41
+ await ldf.expectNavigation(page, /\/tickets\/\d+/);
42
+ await ldf.waitForPage(page, '/settings');
43
+
44
+ // Requests
45
+ await ldf.waitForRequest(page, 'create_ticket');
46
+ const response = await ldf.getRequestResponse(page, 'get_users');
47
+
48
+ // State
49
+ const state = await ldf.getState(page);
50
+ const blockState = await ldf.getBlockState(page, 'my_input');
51
+ await ldf.expectState(page, 'form.title', 'Bug report');
52
+
53
+ // Block locator
54
+ const block = ldf.block(page, 'my_block');
55
+ await expect(block).toBeVisible();
56
+ ```
57
+
58
+ ## Block Helpers
59
+
60
+ Block-specific interactions (requires `@lowdefy/blocks-antd`):
61
+
62
+ ```javascript
63
+ import { button, selector, textInput } from '@lowdefy/e2e-utils';
64
+
65
+ // Button
66
+ await button.click(page, 'submit_btn');
67
+ await button.assertions.isVisible(page, 'submit_btn');
68
+ await button.assertions.isDisabled(page, 'submit_btn');
69
+ await button.assertions.isLoading(page, 'submit_btn');
70
+ await button.assertions.hasText(page, 'submit_btn', 'Submit');
71
+ await button.assertions.hasType(page, 'submit_btn', 'primary');
72
+
73
+ // Selector
74
+ await selector.select(page, 'priority', 'High');
75
+ await selector.clear(page, 'priority');
76
+ await selector.search(page, 'priority', 'Med');
77
+ await selector.assertions.isVisible(page, 'priority');
78
+ await selector.assertions.hasValue(page, 'priority', 'High');
79
+ await selector.assertions.isDisabled(page, 'priority');
80
+ await selector.assertions.hasPlaceholder(page, 'priority', 'Select...');
81
+
82
+ // TextInput
83
+ await textInput.fill(page, 'title', 'Bug report');
84
+ await textInput.clear(page, 'title');
85
+ await textInput.pressEnter(page, 'title');
86
+ await textInput.assertions.isVisible(page, 'title');
87
+ await textInput.assertions.hasValue(page, 'title', 'Bug report');
88
+ await textInput.assertions.isDisabled(page, 'title');
89
+ await textInput.assertions.hasPlaceholder(page, 'title', 'Enter title...');
90
+ ```
91
+
92
+ ## Complete Example
93
+
94
+ ```javascript
95
+ import { test, expect } from '@playwright/test';
96
+ import { ldf, button, textInput, selector } from '@lowdefy/e2e-utils';
97
+
98
+ test('create ticket workflow', async ({ page }) => {
99
+ // Navigate
100
+ await ldf.goto(page, '/tickets/new');
101
+
102
+ // Fill form (block helpers)
103
+ await textInput.fill(page, 'title', 'Bug report');
104
+ await textInput.fill(page, 'description', 'Login not working');
105
+ await selector.select(page, 'priority', 'High');
106
+
107
+ // Submit and verify (framework helpers)
108
+ await button.click(page, 'submit_btn');
109
+ await ldf.waitForRequest(page, 'create_ticket');
110
+ await ldf.expectNavigation(page, /\/tickets\/\d+/);
111
+ await ldf.expectState(page, 'ticket.status', 'open');
112
+ });
113
+ ```
114
+
115
+ ## Playwright Config
116
+
117
+ Use `createConfig` for a pre-configured Playwright setup:
118
+
119
+ ```javascript
120
+ // e2e/playwright.config.js
121
+ import { createConfig } from '@lowdefy/e2e-utils/config';
122
+
123
+ export default createConfig({
124
+ appDir: './', // Where lowdefy.yaml is
125
+ port: 3000, // Dev server port
126
+ testDir: 'e2e', // Test directory
127
+ testMatch: '**/*.spec.js',
128
+ });
129
+ ```
130
+
131
+ ## How It Works
132
+
133
+ These utilities access the Lowdefy client state via `window.lowdefy`, which is exposed in dev mode. This allows:
134
+
135
+ - Waiting for the Lowdefy client to initialize
136
+ - Checking request completion status
137
+ - Accessing page state
138
+ - Stable block selection via `#bl-{blockId}` IDs
139
+
140
+ **Note:** Tests must run against the Lowdefy dev server (`npx lowdefy dev`).
141
+
142
+ ## LLM Test Generation
143
+
144
+ These helpers are designed to be LLM-friendly. An LLM can read your `lowdefy.yaml` config and generate stable tests:
145
+
146
+ ```yaml
147
+ # lowdefy.yaml
148
+ blocks:
149
+ - id: title_input
150
+ type: TextInput
151
+ - id: priority
152
+ type: Selector
153
+ - id: submit_btn
154
+ type: Button
155
+ ```
156
+
157
+ LLM generates:
158
+ ```javascript
159
+ await textInput.fill(page, 'title_input', 'Bug report');
160
+ await selector.select(page, 'priority', 'High');
161
+ await button.click(page, 'submit_btn');
162
+ ```
163
+
164
+ Block IDs from config → stable, readable tests.
package/dist/config.js ADDED
@@ -0,0 +1,55 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import path from 'path';
16
+ import { fileURLToPath } from 'url';
17
+ import { defineConfig, devices } from '@playwright/test';
18
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
19
+ function createConfig({ appDir = './', buildDir = '.lowdefy/server/build', port = 3000, testDir = 'e2e', testMatch = '**/*.spec.js' } = {}) {
20
+ const cliCommand = 'npx lowdefy';
21
+ // Resolve absolute path for build directory
22
+ const absoluteBuildDir = path.resolve(appDir, buildDir);
23
+ // Set environment for fixtures to find build artifacts
24
+ process.env.LOWDEFY_BUILD_DIR = absoluteBuildDir;
25
+ return defineConfig({
26
+ testDir,
27
+ testMatch,
28
+ fullyParallel: true,
29
+ reporter: 'list',
30
+ globalSetup: path.join(__dirname, 'globalSetup.js'),
31
+ use: {
32
+ baseURL: `http://localhost:${port}`,
33
+ trace: 'on-first-retry'
34
+ },
35
+ projects: [
36
+ {
37
+ name: 'chromium',
38
+ use: {
39
+ ...devices['Desktop Chrome']
40
+ }
41
+ }
42
+ ],
43
+ webServer: {
44
+ // Start production server (build happens in globalSetup)
45
+ // NEXT_PUBLIC_LOWDEFY_E2E=true exposes window.lowdefy for state testing
46
+ command: `NEXT_PUBLIC_LOWDEFY_E2E=true ${cliCommand} start --port ${port}`,
47
+ url: `http://localhost:${port}`,
48
+ reuseExistingServer: true,
49
+ timeout: 60000,
50
+ cwd: appDir
51
+ }
52
+ });
53
+ }
54
+ export { createConfig };
55
+ export default createConfig;
@@ -0,0 +1,18 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export { getBlock } from './locators.js';
16
+ export { goto, waitForReady, expectNavigation, waitForPage } from './navigation.js';
17
+ export { waitForRequest, getRequestResponse } from './requests.js';
18
+ export { getState, getBlockState, expectState } from './state.js';
@@ -0,0 +1,18 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ function getBlock(page, blockId) {
16
+ return page.locator(`#bl-${blockId}`);
17
+ }
18
+ export { getBlock };
@@ -0,0 +1,37 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { expect } from '@playwright/test';
16
+ async function waitForReady(page) {
17
+ // Wait for Lowdefy client to initialize (context exists)
18
+ // Context key is "page:{pageId}" not just pageId
19
+ await page.waitForFunction(()=>{
20
+ const lowdefy = window.lowdefy;
21
+ return lowdefy && lowdefy.pageId && lowdefy.contexts[`page:${lowdefy.pageId}`];
22
+ }, {
23
+ timeout: 30000
24
+ });
25
+ }
26
+ async function goto(page, path) {
27
+ await page.goto(path);
28
+ await waitForReady(page);
29
+ }
30
+ async function expectNavigation(page, urlPattern) {
31
+ await expect(page).toHaveURL(urlPattern);
32
+ }
33
+ async function waitForPage(page, path) {
34
+ await page.waitForURL(path);
35
+ await waitForReady(page);
36
+ }
37
+ export { goto, waitForReady, expectNavigation, waitForPage };
@@ -0,0 +1,35 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ async function waitForRequest(page, requestId) {
16
+ // Wait for request to complete (loading === false)
17
+ await page.waitForFunction((reqId)=>{
18
+ const lowdefy = window.lowdefy;
19
+ if (!lowdefy) return false;
20
+ const pageId = lowdefy.pageId;
21
+ const requests = lowdefy.contexts?.[`page:${pageId}`]?.requests?.[reqId];
22
+ return requests && requests.length > 0 && requests[0].loading === false;
23
+ }, requestId, {
24
+ timeout: 30000
25
+ });
26
+ }
27
+ async function getRequestResponse(page, requestId) {
28
+ return page.evaluate((reqId)=>{
29
+ const lowdefy = window.lowdefy;
30
+ const pageId = lowdefy?.pageId;
31
+ const requests = lowdefy?.contexts?.[`page:${pageId}`]?.requests?.[reqId];
32
+ return requests?.[0]?.response;
33
+ }, requestId);
34
+ }
35
+ export { waitForRequest, getRequestResponse };
@@ -0,0 +1,35 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { expect } from '@playwright/test';
16
+ async function getState(page) {
17
+ return page.evaluate(()=>{
18
+ const lowdefy = window.lowdefy;
19
+ const pageId = lowdefy?.pageId;
20
+ return lowdefy?.contexts?.[`page:${pageId}`]?.state;
21
+ });
22
+ }
23
+ async function getBlockState(page, blockId) {
24
+ const state = await getState(page);
25
+ return state?.[blockId];
26
+ }
27
+ async function expectState(page, key, value, { timeout = 5000 } = {}) {
28
+ await expect.poll(async ()=>{
29
+ const state = await getState(page);
30
+ return key.split('.').reduce((obj, k)=>obj?.[k], state);
31
+ }, {
32
+ timeout
33
+ }).toEqual(value);
34
+ }
35
+ export { getState, getBlockState, expectState };
@@ -0,0 +1,54 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { test as base, expect } from '@playwright/test';
16
+ import createHelperRegistry from '../proxy/createHelperRegistry.js';
17
+ import createPageManager from '../proxy/createPageManager.js';
18
+ import { loadManifest } from '../testPrep/generateManifest.js';
19
+ // Create test with ldf fixture
20
+ export const test = base.extend({
21
+ // Worker-scoped fixtures (shared across tests in a worker)
22
+ helperRegistry: [
23
+ async ({}, use)=>{
24
+ const registry = createHelperRegistry();
25
+ await use(registry);
26
+ },
27
+ {
28
+ scope: 'worker'
29
+ }
30
+ ],
31
+ manifest: [
32
+ async ({}, use)=>{
33
+ // Load manifest from build directory (generated by globalSetup)
34
+ const buildDir = process.env.LOWDEFY_BUILD_DIR || '.lowdefy';
35
+ const manifest = loadManifest({
36
+ buildDir
37
+ });
38
+ await use(manifest);
39
+ },
40
+ {
41
+ scope: 'worker'
42
+ }
43
+ ],
44
+ // Test-scoped fixture - provides the ldf helper
45
+ ldf: async ({ page, manifest, helperRegistry }, use)=>{
46
+ const pageManager = createPageManager({
47
+ page,
48
+ manifest,
49
+ helperRegistry
50
+ });
51
+ await use(pageManager);
52
+ }
53
+ });
54
+ export { expect };
@@ -0,0 +1,35 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { execSync } from 'child_process';
16
+ import path from 'path';
17
+ import { generateManifest } from './testPrep/generateManifest.js';
18
+ async function globalSetup(config) {
19
+ // Get app directory from webServer config or use current directory
20
+ const appDir = config.webServer?.cwd || process.cwd();
21
+ const buildDir = process.env.LOWDEFY_BUILD_DIR || path.join(appDir, '.lowdefy/server/build');
22
+ console.log('[e2e-utils] Building Lowdefy app...');
23
+ execSync('npx lowdefy build', {
24
+ cwd: appDir,
25
+ stdio: 'inherit'
26
+ });
27
+ console.log('[e2e-utils] Build complete.');
28
+ console.log('[e2e-utils] Generating manifest...');
29
+ // Generate manifest from build artifacts
30
+ generateManifest({
31
+ buildDir
32
+ });
33
+ console.log(`[e2e-utils] Manifest generated at ${buildDir}/e2e-manifest.json`);
34
+ }
35
+ export default globalSetup;
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ // Core helpers
16
+ import { getBlock } from './core/locators.js';
17
+ import { goto, waitForReady, expectNavigation, waitForPage } from './core/navigation.js';
18
+ import { waitForRequest, getRequestResponse } from './core/requests.js';
19
+ import { getState, getBlockState, expectState } from './core/state.js';
20
+ export { getBlock };
21
+ export { goto, waitForReady, expectNavigation, waitForPage };
22
+ export { waitForRequest, getRequestResponse };
23
+ export { getState, getBlockState, expectState };
24
+ // Test prep utilities
25
+ import { generateManifest, loadManifest } from './testPrep/generateManifest.js';
26
+ export { generateManifest, loadManifest };
27
+ // Proxy utilities
28
+ import createHelperRegistry from './proxy/createHelperRegistry.js';
29
+ import createBlockProxy from './proxy/createBlockProxy.js';
30
+ import createPageManager from './proxy/createPageManager.js';
31
+ export { createHelperRegistry, createBlockProxy, createPageManager };
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ Copyright 2020-2024 Lowdefy, Inc
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ */ import fs from 'fs';
17
+ import path from 'path';
18
+ import { fileURLToPath } from 'url';
19
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
20
+ async function init() {
21
+ const cwd = process.cwd();
22
+ const e2eDir = path.join(cwd, 'e2e');
23
+ console.log('Setting up Lowdefy e2e testing...\n');
24
+ // Create e2e directory
25
+ if (!fs.existsSync(e2eDir)) {
26
+ fs.mkdirSync(e2eDir, {
27
+ recursive: true
28
+ });
29
+ console.log('Created e2e/');
30
+ }
31
+ // Copy templates
32
+ const templates = [
33
+ {
34
+ src: 'playwright.config.js.template',
35
+ dest: 'playwright.config.js'
36
+ },
37
+ {
38
+ src: 'example.spec.js.template',
39
+ dest: 'example.spec.js'
40
+ }
41
+ ];
42
+ for (const { src, dest } of templates){
43
+ const srcPath = path.join(__dirname, 'templates', src);
44
+ const destPath = path.join(e2eDir, dest);
45
+ if (!fs.existsSync(destPath)) {
46
+ fs.copyFileSync(srcPath, destPath);
47
+ console.log(`Created e2e/${dest}`);
48
+ } else {
49
+ console.log(`Skipped e2e/${dest} (already exists)`);
50
+ }
51
+ }
52
+ // Update package.json
53
+ const pkgPath = path.join(cwd, 'package.json');
54
+ if (fs.existsSync(pkgPath)) {
55
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
56
+ let updated = false;
57
+ pkg.scripts = pkg.scripts || {};
58
+ if (!pkg.scripts.e2e) {
59
+ pkg.scripts.e2e = 'playwright test';
60
+ updated = true;
61
+ }
62
+ if (!pkg.scripts['e2e:ui']) {
63
+ pkg.scripts['e2e:ui'] = 'playwright test --ui';
64
+ updated = true;
65
+ }
66
+ if (updated) {
67
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
68
+ console.log('Updated package.json with e2e scripts');
69
+ }
70
+ }
71
+ console.log('\n✓ E2E testing setup complete!\n');
72
+ console.log('Next steps:');
73
+ console.log(' 1. Install dependencies: pnpm add -D @lowdefy/e2e-utils @playwright/test');
74
+ console.log(' 2. Install browsers: npx playwright install chromium');
75
+ console.log(' 3. Run tests: pnpm e2e');
76
+ console.log(' 4. Or use UI mode: pnpm e2e:ui');
77
+ }
78
+ init().catch((err)=>{
79
+ console.error('Error:', err.message);
80
+ process.exit(1);
81
+ });
@@ -0,0 +1,28 @@
1
+ import { test, expect } from '@playwright/test';
2
+ import { ldf, button, textInput, selector } from '@lowdefy/e2e-utils';
3
+
4
+ test('homepage loads', async ({ page }) => {
5
+ await ldf.goto(page, '/');
6
+
7
+ // Replace with your own assertions
8
+ await expect(page).toHaveTitle(/./);
9
+ });
10
+
11
+ // Example: Testing a form submission
12
+ // Uncomment and modify for your app:
13
+ //
14
+ // test('submit contact form', async ({ page }) => {
15
+ // await ldf.goto(page, '/contact');
16
+ //
17
+ // // Fill form fields
18
+ // await textInput.fill(page, 'name_input', 'John Doe');
19
+ // await textInput.fill(page, 'email_input', 'john@example.com');
20
+ // await selector.select(page, 'category', 'Support');
21
+ //
22
+ // // Submit
23
+ // await button.click(page, 'submit_btn');
24
+ //
25
+ // // Wait for request and verify
26
+ // await ldf.waitForRequest(page, 'send_message');
27
+ // await ldf.expectNavigation(page, '/thank-you');
28
+ // });
@@ -0,0 +1,6 @@
1
+ import { createConfig } from '@lowdefy/e2e-utils/config';
2
+
3
+ export default createConfig({
4
+ appDir: './',
5
+ port: 3000,
6
+ });
@@ -0,0 +1,44 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ function createBlockProxy({ page, blockMap, helperRegistry }) {
16
+ return new Proxy({}, {
17
+ get (_, blockId) {
18
+ if (typeof blockId !== 'string') return undefined;
19
+ const blockInfo = blockMap[blockId];
20
+ if (!blockInfo) {
21
+ const available = Object.keys(blockMap).join(', ');
22
+ throw new Error(`Block "${blockId}" not found on page. Available blocks: ${available || '(none)'}`);
23
+ }
24
+ // Return a proxy that routes method calls to the helper
25
+ return new Proxy({}, {
26
+ get (_, methodName) {
27
+ if (typeof methodName !== 'string') return undefined;
28
+ return async (...args)=>{
29
+ const helper = await helperRegistry.get(blockInfo.helper);
30
+ if (!helper) {
31
+ throw new Error(`Block type "${blockInfo.type}" does not have e2e helpers.\n` + `Add e2e.js to: ${blockInfo.helper.replace('/e2e/', '/src/blocks/')}/e2e.js`);
32
+ }
33
+ if (typeof helper[methodName] !== 'function') {
34
+ const available = Object.keys(helper).filter((k)=>typeof helper[k] === 'function').join(', ');
35
+ throw new Error(`Block type "${blockInfo.type}" has no method "${methodName}".\n` + `Available methods: ${available || '(none)'}`);
36
+ }
37
+ return helper[methodName](page, blockId, ...args);
38
+ };
39
+ }
40
+ });
41
+ }
42
+ });
43
+ }
44
+ export default createBlockProxy;
@@ -0,0 +1,37 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ function createHelperRegistry() {
16
+ const cache = new Map();
17
+ return {
18
+ async get (helperPath) {
19
+ if (!cache.has(helperPath)) {
20
+ try {
21
+ const module = await import(helperPath);
22
+ cache.set(helperPath, module.default ?? module);
23
+ } catch (e) {
24
+ cache.set(helperPath, null);
25
+ }
26
+ }
27
+ return cache.get(helperPath);
28
+ },
29
+ has (helperPath) {
30
+ return cache.has(helperPath);
31
+ },
32
+ clear () {
33
+ cache.clear();
34
+ }
35
+ };
36
+ }
37
+ export default createHelperRegistry;
@@ -0,0 +1,53 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { getBlock } from '../core/locators.js';
16
+ import { waitForReady } from '../core/navigation.js';
17
+ import { getState, getBlockState, expectState } from '../core/state.js';
18
+ import createBlockProxy from './createBlockProxy.js';
19
+ function createPageManager({ page, manifest, helperRegistry }) {
20
+ let currentBlockMap = null;
21
+ let currentPageId = null;
22
+ return {
23
+ async goto (path) {
24
+ await page.goto(path);
25
+ await waitForReady(page);
26
+ currentPageId = await page.evaluate(()=>window.lowdefy?.pageId);
27
+ currentBlockMap = manifest.pages[currentPageId];
28
+ if (!currentBlockMap) {
29
+ const available = Object.keys(manifest.pages).join(', ');
30
+ throw new Error(`Page "${currentPageId}" not found in manifest. Available pages: ${available || '(none)'}`);
31
+ }
32
+ },
33
+ get blocks () {
34
+ if (!currentBlockMap) {
35
+ throw new Error('Call goto() before accessing blocks');
36
+ }
37
+ return createBlockProxy({
38
+ page,
39
+ blockMap: currentBlockMap,
40
+ helperRegistry
41
+ });
42
+ },
43
+ get pageId () {
44
+ return currentPageId;
45
+ },
46
+ // Core helpers
47
+ block: (blockId)=>getBlock(page, blockId),
48
+ getState: ()=>getState(page),
49
+ getBlockState: (blockId)=>getBlockState(page, blockId),
50
+ expectState: (key, value, opts)=>expectState(page, key, value, opts)
51
+ };
52
+ }
53
+ export default createPageManager;
@@ -0,0 +1,51 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ function getBlocksArray(container) {
16
+ if (!container) return [];
17
+ if (Array.isArray(container)) return container;
18
+ if (container['~arr']) return container['~arr'];
19
+ return [];
20
+ }
21
+ function extractBlockMap({ pageConfig, typesBlocks }) {
22
+ const blockMap = {};
23
+ function traverse(obj) {
24
+ if (!obj || typeof obj !== 'object') return;
25
+ // If this object has blockId and type, record it
26
+ if (obj.blockId && obj.type) {
27
+ const packageName = typesBlocks[obj.type]?.package;
28
+ if (packageName) {
29
+ blockMap[obj.blockId] = {
30
+ type: obj.type,
31
+ helper: `${packageName}/e2e/${obj.type}`
32
+ };
33
+ }
34
+ }
35
+ // Traverse areas - area.blocks is { "~arr": [...blocks...] }
36
+ if (obj.areas) {
37
+ Object.values(obj.areas).forEach((area)=>{
38
+ const blocks = getBlocksArray(area.blocks);
39
+ blocks.forEach((block)=>traverse(block));
40
+ });
41
+ }
42
+ // Traverse direct blocks array (may also be { "~arr": [...] })
43
+ if (obj.blocks) {
44
+ const blocks = getBlocksArray(obj.blocks);
45
+ blocks.forEach((block)=>traverse(block));
46
+ }
47
+ }
48
+ traverse(pageConfig);
49
+ return blockMap;
50
+ }
51
+ export default extractBlockMap;
@@ -0,0 +1,52 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import fs from 'fs';
16
+ import path from 'path';
17
+ import extractBlockMap from './extractBlockMap.js';
18
+ function generateManifest({ buildDir = '.lowdefy' }) {
19
+ const typesPath = path.join(buildDir, 'types.json');
20
+ if (!fs.existsSync(typesPath)) {
21
+ throw new Error(`Build artifacts not found at ${buildDir}. Run 'lowdefy build' first.`);
22
+ }
23
+ const types = JSON.parse(fs.readFileSync(typesPath, 'utf-8'));
24
+ const pagesDir = path.join(buildDir, 'pages');
25
+ const manifest = {
26
+ pages: {}
27
+ };
28
+ if (fs.existsSync(pagesDir)) {
29
+ for (const pageId of fs.readdirSync(pagesDir)){
30
+ const pageConfigPath = path.join(pagesDir, pageId, `${pageId}.json`);
31
+ if (fs.existsSync(pageConfigPath)) {
32
+ const pageConfig = JSON.parse(fs.readFileSync(pageConfigPath, 'utf-8'));
33
+ manifest.pages[pageId] = extractBlockMap({
34
+ pageConfig,
35
+ typesBlocks: types.blocks ?? {}
36
+ });
37
+ }
38
+ }
39
+ }
40
+ const manifestPath = path.join(buildDir, 'e2e-manifest.json');
41
+ fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
42
+ return manifest;
43
+ }
44
+ function loadManifest({ buildDir = '.lowdefy' } = {}) {
45
+ const manifestPath = path.join(buildDir, 'e2e-manifest.json');
46
+ if (!fs.existsSync(manifestPath)) {
47
+ throw new Error(`E2E manifest not found at ${manifestPath}. Run test prep or generateManifest() first.`);
48
+ }
49
+ return JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
50
+ }
51
+ export { generateManifest, loadManifest };
52
+ export default generateManifest;
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@lowdefy/e2e-utils",
3
+ "version": "0.0.0-experimental-20260202125814",
4
+ "license": "Apache-2.0",
5
+ "description": "Lowdefy E2E Testing Utilities for Playwright",
6
+ "homepage": "https://lowdefy.com",
7
+ "keywords": [
8
+ "lowdefy",
9
+ "e2e",
10
+ "playwright",
11
+ "testing"
12
+ ],
13
+ "bugs": {
14
+ "url": "https://github.com/lowdefy/lowdefy/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/lowdefy/lowdefy.git"
19
+ },
20
+ "type": "module",
21
+ "bin": {
22
+ "lowdefy-e2e": "./dist/init/index.js"
23
+ },
24
+ "exports": {
25
+ ".": "./dist/index.js",
26
+ "./config": "./dist/config.js",
27
+ "./fixtures": "./dist/fixtures/index.js"
28
+ },
29
+ "files": [
30
+ "dist/*"
31
+ ],
32
+ "dependencies": {
33
+ "@playwright/test": "1.50.1"
34
+ },
35
+ "peerDependencies": {
36
+ "@lowdefy/blocks-antd": "0.0.0-experimental-20260202125814"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "@lowdefy/blocks-antd": {
40
+ "optional": true
41
+ }
42
+ },
43
+ "devDependencies": {
44
+ "@swc/cli": "0.1.63",
45
+ "@swc/core": "1.3.99",
46
+ "copyfiles": "2.4.1"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "scripts": {
52
+ "build": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start && pnpm copyfiles",
53
+ "clean": "rm -rf dist",
54
+ "copyfiles": "copyfiles -u 1 \"./src/init/templates/*\" dist"
55
+ }
56
+ }