vease 3.0.0-rc.2 → 3.0.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.
@@ -1,44 +1,20 @@
1
1
  import { navigateToApp } from "./navigate.js";
2
- import { waitForActionSettled } from "#ogw_e2e/wait_for_action_settled.js";
3
- import { expect, test as test$1 } from "@playwright/test";
4
- import { consola } from "consola";
2
+ import { expect } from "@playwright/test";
5
3
  import fs from "node:fs";
6
4
  import path from "node:path";
7
5
  import os from "node:os";
6
+ import { test as test$1 } from "#ogw_e2e/app_test.js";
8
7
  //#region tests/e2e/utils/fixtures.ts
9
- const MILLISECONDS_PER_SECOND = 1e3;
10
8
  const BUSY_TIMEOUT_MS = 3e4;
11
- const OGW_SUITE_TEST_FILE_EXTENSION = ".test.ts";
12
- const OGW_SUITE_FILE_REGEX = /tests[/\\]browser[/\\]suites[/\\](?<suite>.+)\.js$/u;
13
- const APP_LAUNCH_TIMEOUT_MS = 18e4;
14
- function sanitizeForFilePath(name) {
15
- return name.replaceAll(/[^\dA-Za-z\u0080-\uFFFF-]+/gu, "-");
16
- }
17
- function screenshotPath(testInfo) {
18
- const titles = testInfo.titlePath.slice(1);
19
- const suite = OGW_SUITE_FILE_REGEX.exec(testInfo.file)?.groups?.suite;
20
- if (suite !== void 0) return [...`${suite.replaceAll("\\", "/")}${OGW_SUITE_TEST_FILE_EXTENSION}`.split("/"), `${sanitizeForFilePath(titles.slice(1).join(" "))}.png`];
21
- return [...path.relative(testInfo.project.testDir, testInfo.file).split(path.sep), `${sanitizeForFilePath(titles.join(" "))}.png`];
22
- }
23
9
  const test = test$1.extend({
24
10
  mode: ["DEFAULT", {
25
11
  option: true,
26
12
  scope: "worker"
27
13
  }],
28
- suiteId: ["default", {
29
- option: true,
30
- scope: "worker"
31
- }],
32
- afterAppLaunch: [async ({}, use) => {
33
- await use(async () => {});
34
- }, { scope: "worker" }],
35
- beforeAppClose: [async ({}, use) => {
36
- await use(async () => {});
14
+ desktopApp: [async ({}, use) => {
15
+ await use({});
37
16
  }, { scope: "worker" }],
38
- screenshotMask: [async ({}, use) => {
39
- await use({ locators: [] });
40
- }, { scope: "test" }],
41
- app: [async ({ mode, playwright, browserName, headless, channel, launchOptions, afterAppLaunch, beforeAppClose }, use, workerInfo) => {
17
+ launchApp: [async ({ mode, playwright, browserName, headless, channel, launchOptions, desktopApp }, use, workerInfo) => {
42
18
  const configPath = fs.mkdtempSync(path.join(os.tmpdir(), `vease-e2e-worker${workerInfo.parallelIndex}-`));
43
19
  process.env.XDG_CONFIG_HOME = configPath;
44
20
  process.env.APPDATA = configPath;
@@ -49,69 +25,34 @@ const test = test$1.extend({
49
25
  channel
50
26
  });
51
27
  }
52
- let openApp = void 0;
53
- const app = {
54
- get window() {
55
- if (openApp === void 0) throw new Error("The app is not open");
56
- return openApp.window;
57
- },
58
- get electronApp() {
59
- return openApp?.electronApp;
60
- },
61
- open: async () => {
62
- if (openApp === void 0) {
63
- openApp = await navigateToApp(mode, launchBrowser);
64
- await afterAppLaunch(openApp.window);
65
- }
66
- return openApp.window;
67
- },
68
- close: async () => {
69
- if (openApp !== void 0) {
70
- const { window, cleanup } = openApp;
71
- openApp = void 0;
72
- await beforeAppClose(window);
28
+ await use(async () => {
29
+ const { window, cleanup, electronApp } = await navigateToApp(mode, launchBrowser);
30
+ desktopApp.electronApp = electronApp;
31
+ return {
32
+ window,
33
+ cleanup: async () => {
34
+ desktopApp.electronApp = void 0;
73
35
  await cleanup();
74
36
  }
75
- }
76
- };
77
- await use(app);
78
- await app.close();
37
+ };
38
+ });
79
39
  fs.rmSync(configPath, {
80
40
  recursive: true,
81
41
  force: true
82
42
  });
83
43
  }, { scope: "worker" }],
84
- restartApp: [async ({ app }, use) => {
85
- await use(async () => {
86
- await app.close();
87
- return await app.open();
44
+ beforeScreenshot: [async ({}, use) => {
45
+ await use(async (window) => {
46
+ await expect(window.getByTestId("microservicesBusyIndicator")).toBeHidden({ timeout: BUSY_TIMEOUT_MS });
88
47
  });
89
48
  }, { scope: "worker" }],
90
- window: [async ({ app }, use) => {
91
- await use(await app.open());
92
- }, {
93
- scope: "test",
94
- timeout: APP_LAUNCH_TIMEOUT_MS
95
- }],
96
- logTestProgress: [async ({}, use, testInfo) => {
97
- const name = `${path.basename(testInfo.file)} › ${testInfo.title}`;
98
- consola.info(`\u001B[33m[START]\u001B[0m ${name}`);
99
- const start = Date.now();
100
- await use(void 0);
101
- const statusColor = testInfo.status === "passed" ? "\x1B[32m" : "\x1B[31m";
102
- const status = (testInfo.status ?? "done").toUpperCase();
103
- const duration = ((Date.now() - start) / MILLISECONDS_PER_SECOND).toFixed(2);
104
- consola.info(`\u001B[35m[END]\u001B[0m ${name} : ${statusColor}TEST ${status}\u001B[0m (${duration}s)`);
105
- }, { auto: true }],
106
- autoScreenshot: [async ({ app, screenshotMask }, use, testInfo) => {
107
- await use(void 0);
108
- const { window } = app;
109
- if (testInfo.status === testInfo.expectedStatus) {
110
- await expect(window.getByTestId("microservicesBusyIndicator")).toBeHidden({ timeout: BUSY_TIMEOUT_MS });
111
- await waitForActionSettled(window);
112
- await expect(window).toHaveScreenshot(screenshotPath(testInfo), { mask: [window.getByTestId("accountNavButton"), ...screenshotMask.locators] });
113
- }
114
- }, { auto: true }]
49
+ appScreenshotMask: [async ({}, use) => {
50
+ await use((window) => [window.getByTestId("accountNavButton")]);
51
+ }, { scope: "worker" }],
52
+ electronApp: async ({ app, desktopApp }, use) => {
53
+ await app.open();
54
+ await use(desktopApp.electronApp);
55
+ }
115
56
  });
116
57
  //#endregion
117
58
  export { test };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vease",
3
- "version": "3.0.0-rc.2",
3
+ "version": "3.0.1-rc.1",
4
4
  "description": "Desktop and cloud software for data visualization",
5
5
  "keywords": [
6
6
  "Desktop",
@@ -1,129 +1,53 @@
1
+ // The test of Vease: the app test of OpenGeodeWeb-Front (one app per worker, opened and closed by the tests, a
2
+ // Screenshot at the end of each passing test), launched in the mode of the project (browser, cloud or desktop)
3
+
1
4
  // Node imports
2
5
  import fs from "node:fs";
3
6
  import os from "node:os";
4
7
  import path from "node:path";
5
8
 
6
9
  // Third party imports
7
- import type { Browser, Locator, Page, TestInfo } from "@playwright/test";
8
- // oxlint-disable-next-line eslint/no-duplicate-imports
9
- import { test as base, expect } from "@playwright/test";
10
+ import type { Browser } from "@playwright/test";
10
11
  import type { ElectronApplication } from "playwright";
11
- import { consola } from "consola";
12
+ // oxlint-disable-next-line eslint/no-duplicate-imports
13
+ import { expect } from "@playwright/test";
12
14
 
13
15
  // Local imports
16
+ import { test as appTest } from "#ogw_e2e/app_test.js";
14
17
  import { navigateToApp } from "./navigate";
15
- import { waitForActionSettled } from "#ogw_e2e/wait_for_action_settled.js";
16
18
 
17
- const MILLISECONDS_PER_SECOND = 1000;
18
19
  // Whole download deadline of a basemap build in OpenGeodeWeb-Back (FETCH_DEADLINE_SECONDS)
19
20
  const BUSY_TIMEOUT_MS = 30_000;
20
- const OGW_SUITE_TEST_FILE_EXTENSION = ".test.ts";
21
- // Built suite files of OpenGeodeWeb-Front, where the tests of its suites are located
22
- const OGW_SUITE_FILE_REGEX = /tests[/\\]browser[/\\]suites[/\\](?<suite>.+)\.js$/u;
23
- // Launching the app: browser or Electron, back and viewer, then afterAppLaunch
24
- const APP_LAUNCH_TIMEOUT_MS = 180_000;
25
21
 
26
- // Same as Playwright's {testName}: every ASCII character except letters, digits and "-" becomes "-"
27
- function sanitizeForFilePath(name: string): string {
28
- return name.replaceAll(/[^\dA-Za-z\u0080-\uFFFF-]+/gu, "-");
29
- }
30
-
31
- // Screenshots/<test file path>/<test name>.png. The OpenGeodeWeb-Front suites (run from opengeodeweb_front.test.ts,
32
- // One describe each) keep the folders of their own test files, tests/browser/tests/<suite>.test.ts
33
- function screenshotPath(testInfo: TestInfo): string[] {
34
- const titles = testInfo.titlePath.slice(1);
35
- const suite = OGW_SUITE_FILE_REGEX.exec(testInfo.file)?.groups?.suite;
36
- if (suite !== undefined) {
37
- return [
38
- ...`${suite.replaceAll("\\", "/")}${OGW_SUITE_TEST_FILE_EXTENSION}`.split("/"),
39
- `${sanitizeForFilePath(titles.slice(1).join(" "))}.png`,
40
- ];
41
- }
42
- return [
43
- ...path.relative(testInfo.project.testDir, testInfo.file).split(path.sep),
44
- `${sanitizeForFilePath(titles.join(" "))}.png`,
45
- ];
46
- }
47
-
48
- interface ScreenshotMask {
49
- locators: Locator[];
50
- }
51
-
52
- interface RunningApp {
53
- // Page of the open app (throws if the app is closed)
54
- readonly window: Page;
55
- // Only set in DESKTOP mode, while the app is open
22
+ // The Electron app of the open app, in DESKTOP mode
23
+ interface DesktopApp {
56
24
  electronApp?: ElectronApplication;
57
- // Launches the app if it is not open
58
- open: () => Promise<Page>;
59
- // Closes the app if it is open
60
- close: () => Promise<void>;
61
25
  }
62
26
 
63
27
  interface WorkerFixtures {
64
28
  mode: string;
65
- suiteId: string;
66
- // Run on each launched app before its first test (Vease-Modeling loads its extension), and before closing it
67
- afterAppLaunch: (window: Page) => Promise<void>;
68
- beforeAppClose: (window: Page) => Promise<void>;
69
- app: RunningApp;
70
- restartApp: () => Promise<Page>;
29
+ desktopApp: DesktopApp;
71
30
  }
72
31
 
73
32
  interface TestFixtures {
74
- window: Page;
75
- screenshotMask: ScreenshotMask;
76
- logTestProgress: undefined;
77
- autoScreenshot: undefined;
33
+ // Only set in DESKTOP mode
34
+ electronApp: ElectronApplication | undefined;
78
35
  }
79
36
 
80
- const test = base.extend<TestFixtures, WorkerFixtures>({
37
+ const test = appTest.extend<TestFixtures, WorkerFixtures>({
81
38
  mode: ["DEFAULT", { option: true, scope: "worker" }],
82
39
 
83
- suiteId: ["default", { option: true, scope: "worker" }],
84
-
85
- afterAppLaunch: [
40
+ desktopApp: [
86
41
  // oxlint-disable-next-line no-empty-pattern
87
42
  async ({}, use): Promise<void> => {
88
- await use(async (): Promise<void> => {
89
- // Nothing to do by default
90
- });
43
+ await use({});
91
44
  },
92
45
  { scope: "worker" },
93
46
  ],
94
47
 
95
- beforeAppClose: [
96
- // oxlint-disable-next-line no-empty-pattern
97
- async ({}, use): Promise<void> => {
98
- await use(async (): Promise<void> => {
99
- // Nothing to do by default
100
- });
101
- },
102
- { scope: "worker" },
103
- ],
104
-
105
- screenshotMask: [
106
- // oxlint-disable-next-line no-empty-pattern
107
- async ({}, use): Promise<void> => {
108
- await use({ locators: [] });
109
- },
110
- { scope: "test" },
111
- ],
112
-
113
- // The app of the worker: opened by the first test that uses it (or a beforeAll), closed by app.close or at the end of
114
- // The worker. A test file opens it, runs its tests and closes it; so does each suite of opengeodeweb_front.test.ts
115
- app: [
48
+ launchApp: [
116
49
  async (
117
- {
118
- mode,
119
- playwright,
120
- browserName,
121
- headless,
122
- channel,
123
- launchOptions,
124
- afterAppLaunch,
125
- beforeAppClose,
126
- },
50
+ { mode, playwright, browserName, headless, channel, launchOptions, desktopApp },
127
51
  use,
128
52
  workerInfo,
129
53
  ): Promise<void> => {
@@ -142,97 +66,49 @@ const test = base.extend<TestFixtures, WorkerFixtures>({
142
66
  });
143
67
  return browser;
144
68
  }
145
- let openApp: Awaited<ReturnType<typeof navigateToApp>> | undefined = undefined;
146
- const app: RunningApp = {
147
- get window(): Page {
148
- if (openApp === undefined) {
149
- throw new Error("The app is not open");
150
- }
151
- return openApp.window;
152
- },
153
- get electronApp(): ElectronApplication | undefined {
154
- return openApp?.electronApp;
155
- },
156
- open: async (): Promise<Page> => {
157
- if (openApp === undefined) {
158
- openApp = await navigateToApp(mode, launchBrowser);
159
- await afterAppLaunch(openApp.window);
160
- }
161
- return openApp.window;
162
- },
163
- close: async (): Promise<void> => {
164
- if (openApp !== undefined) {
165
- const { window, cleanup } = openApp;
166
- openApp = undefined;
167
- await beforeAppClose(window);
69
+ await use(async () => {
70
+ const { window, cleanup, electronApp } = await navigateToApp(mode, launchBrowser);
71
+ desktopApp.electronApp = electronApp;
72
+ return {
73
+ window,
74
+ cleanup: async (): Promise<void> => {
75
+ desktopApp.electronApp = undefined;
168
76
  await cleanup();
169
- }
170
- },
171
- };
172
- await use(app);
173
- await app.close();
77
+ },
78
+ };
79
+ });
174
80
  fs.rmSync(configPath, { recursive: true, force: true });
175
81
  },
176
82
  { scope: "worker" },
177
83
  ],
178
84
 
179
- // Kills the running app and launches a new one, like a user closing and reopening it
180
- restartApp: [
181
- async ({ app }, use): Promise<void> => {
182
- await use(async (): Promise<Page> => {
183
- await app.close();
184
- const window = await app.open();
185
- return window;
85
+ // Never capture while the microservices are still busy (busy indicator bar, half-rendered viewer)
86
+ // A basemap build waits on external tile servers longer than waitForActionSettled does
87
+ beforeScreenshot: [
88
+ // oxlint-disable-next-line no-empty-pattern
89
+ async ({}, use): Promise<void> => {
90
+ await use(async (window) => {
91
+ await expect(window.getByTestId("microservicesBusyIndicator")).toBeHidden({
92
+ timeout: BUSY_TIMEOUT_MS,
93
+ });
186
94
  });
187
95
  },
188
96
  { scope: "worker" },
189
97
  ],
190
98
 
191
- // Page of the app, opened if needed: it follows restartApp
192
- window: [
193
- async ({ app }, use): Promise<void> => {
194
- await use(await app.open());
195
- },
196
- { scope: "test", timeout: APP_LAUNCH_TIMEOUT_MS },
197
- ],
198
-
199
- logTestProgress: [
99
+ // The account icon depends on login state (only cloud is logged in)
100
+ appScreenshotMask: [
200
101
  // oxlint-disable-next-line no-empty-pattern
201
- async ({}, use, testInfo): Promise<void> => {
202
- const name = `${path.basename(testInfo.file)} › ${testInfo.title}`;
203
- consola.info(`\u001B[33m[START]\u001B[0m ${name}`);
204
- const start = Date.now();
205
- await use(undefined);
206
- const statusColor = testInfo.status === "passed" ? "\u001B[32m" : "\u001B[31m";
207
- const status = (testInfo.status ?? "done").toUpperCase();
208
- const duration = ((Date.now() - start) / MILLISECONDS_PER_SECOND).toFixed(2);
209
- consola.info(
210
- `\u001B[35m[END]\u001B[0m ${name} : ${statusColor}TEST ${status}\u001B[0m (${duration}s)`,
211
- );
102
+ async ({}, use): Promise<void> => {
103
+ await use((window) => [window.getByTestId("accountNavButton")]);
212
104
  },
213
- { auto: true },
105
+ { scope: "worker" },
214
106
  ],
215
107
 
216
- autoScreenshot: [
217
- async ({ app, screenshotMask }, use, testInfo): Promise<void> => {
218
- await use(undefined);
219
- // Read at teardown: the test may have restarted the app
220
- const { window } = app;
221
- if (testInfo.status === testInfo.expectedStatus) {
222
- // Never capture while the microservices are still busy (busy indicator bar, half-rendered viewer)
223
- // A basemap build waits on external tile servers longer than waitForActionSettled does
224
- await expect(window.getByTestId("microservicesBusyIndicator")).toBeHidden({
225
- timeout: BUSY_TIMEOUT_MS,
226
- });
227
- await waitForActionSettled(window);
228
- // The account icon depends on login state (only cloud is logged in)
229
- await expect(window).toHaveScreenshot(screenshotPath(testInfo), {
230
- mask: [window.getByTestId("accountNavButton"), ...screenshotMask.locators],
231
- });
232
- }
233
- },
234
- { auto: true },
235
- ],
108
+ electronApp: async ({ app, desktopApp }, use): Promise<void> => {
109
+ await app.open();
110
+ await use(desktopApp.electronApp);
111
+ },
236
112
  });
237
113
 
238
114
  export { test };