rwsdk 1.0.0-beta.3 → 1.0.0-beta.5
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/lib/e2e/constants.d.mts +12 -0
- package/dist/lib/e2e/constants.mjs +40 -0
- package/dist/lib/e2e/environment.mjs +1 -1
- package/dist/lib/e2e/testHarness.d.mts +2 -1
- package/dist/lib/e2e/testHarness.mjs +2 -38
- package/dist/runtime/client/client.d.ts +1 -0
- package/dist/runtime/client/client.js +1 -0
- package/dist/runtime/client/navigation.d.ts +8 -0
- package/dist/runtime/client/navigation.js +38 -31
- package/dist/runtime/entries/clientSSR.d.ts +1 -0
- package/dist/runtime/entries/clientSSR.js +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const SETUP_PLAYGROUND_ENV_TIMEOUT: number;
|
|
2
|
+
export declare const DEPLOYMENT_TIMEOUT: number;
|
|
3
|
+
export declare const DEPLOYMENT_MIN_TRIES: number;
|
|
4
|
+
export declare const DEPLOYMENT_CHECK_TIMEOUT: number;
|
|
5
|
+
export declare const PUPPETEER_TIMEOUT: number;
|
|
6
|
+
export declare const HYDRATION_TIMEOUT: number;
|
|
7
|
+
export declare const DEV_SERVER_TIMEOUT: number;
|
|
8
|
+
export declare const DEV_SERVER_MIN_TRIES: number;
|
|
9
|
+
export declare const SETUP_WAIT_TIMEOUT: number;
|
|
10
|
+
export declare const TEST_MAX_RETRIES: number;
|
|
11
|
+
export declare const TEST_MAX_RETRIES_PER_CODE: number;
|
|
12
|
+
export declare const INSTALL_DEPENDENCIES_RETRIES: number;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const SETUP_PLAYGROUND_ENV_TIMEOUT = process.env
|
|
2
|
+
.RWSDK_SETUP_PLAYGROUND_ENV_TIMEOUT
|
|
3
|
+
? parseInt(process.env.RWSDK_SETUP_PLAYGROUND_ENV_TIMEOUT, 10)
|
|
4
|
+
: 15 * 60 * 1000;
|
|
5
|
+
export const DEPLOYMENT_TIMEOUT = process.env.RWSDK_DEPLOYMENT_TIMEOUT
|
|
6
|
+
? parseInt(process.env.RWSDK_DEPLOYMENT_TIMEOUT, 10)
|
|
7
|
+
: 5 * 60 * 1000;
|
|
8
|
+
export const DEPLOYMENT_MIN_TRIES = process.env.RWSDK_DEPLOYMENT_MIN_TRIES
|
|
9
|
+
? parseInt(process.env.RWSDK_DEPLOYMENT_MIN_TRIES, 10)
|
|
10
|
+
: 5;
|
|
11
|
+
export const DEPLOYMENT_CHECK_TIMEOUT = process.env
|
|
12
|
+
.RWSDK_DEPLOYMENT_CHECK_TIMEOUT
|
|
13
|
+
? parseInt(process.env.RWSDK_DEPLOYMENT_CHECK_TIMEOUT, 10)
|
|
14
|
+
: 5 * 60 * 1000;
|
|
15
|
+
export const PUPPETEER_TIMEOUT = process.env.RWSDK_PUPPETEER_TIMEOUT
|
|
16
|
+
? parseInt(process.env.RWSDK_PUPPETEER_TIMEOUT, 10)
|
|
17
|
+
: 60 * 1000 * 2;
|
|
18
|
+
export const HYDRATION_TIMEOUT = process.env.RWSDK_HYDRATION_TIMEOUT
|
|
19
|
+
? parseInt(process.env.RWSDK_HYDRATION_TIMEOUT, 10)
|
|
20
|
+
: 5000;
|
|
21
|
+
export const DEV_SERVER_TIMEOUT = process.env.RWSDK_DEV_SERVER_TIMEOUT
|
|
22
|
+
? parseInt(process.env.RWSDK_DEV_SERVER_TIMEOUT, 10)
|
|
23
|
+
: 5 * 60 * 1000;
|
|
24
|
+
export const DEV_SERVER_MIN_TRIES = process.env.RWSDK_DEV_SERVER_MIN_TRIES
|
|
25
|
+
? parseInt(process.env.RWSDK_DEV_SERVER_MIN_TRIES, 10)
|
|
26
|
+
: 5;
|
|
27
|
+
export const SETUP_WAIT_TIMEOUT = process.env.RWSDK_SETUP_WAIT_TIMEOUT
|
|
28
|
+
? parseInt(process.env.RWSDK_SETUP_WAIT_TIMEOUT, 10)
|
|
29
|
+
: 10 * 60 * 1000;
|
|
30
|
+
export const TEST_MAX_RETRIES = process.env.RWSDK_TEST_MAX_RETRIES
|
|
31
|
+
? parseInt(process.env.RWSDK_TEST_MAX_RETRIES, 10)
|
|
32
|
+
: 10;
|
|
33
|
+
export const TEST_MAX_RETRIES_PER_CODE = process.env
|
|
34
|
+
.RWSDK_TEST_MAX_RETRIES_PER_CODE
|
|
35
|
+
? parseInt(process.env.RWSDK_TEST_MAX_RETRIES_PER_CODE, 10)
|
|
36
|
+
: 6;
|
|
37
|
+
export const INSTALL_DEPENDENCIES_RETRIES = process.env
|
|
38
|
+
.RWSDK_INSTALL_DEPENDENCIES_RETRIES
|
|
39
|
+
? parseInt(process.env.RWSDK_INSTALL_DEPENDENCIES_RETRIES, 10)
|
|
40
|
+
: 10;
|
|
@@ -8,8 +8,8 @@ import { basename, join, relative, resolve } from "path";
|
|
|
8
8
|
import tmp from "tmp-promise";
|
|
9
9
|
import { $ } from "../../lib/$.mjs";
|
|
10
10
|
import { ROOT_DIR } from "../constants.mjs";
|
|
11
|
+
import { INSTALL_DEPENDENCIES_RETRIES } from "./constants.mjs";
|
|
11
12
|
import { retry } from "./retry.mjs";
|
|
12
|
-
import { INSTALL_DEPENDENCIES_RETRIES } from "./testHarness.mjs";
|
|
13
13
|
const log = debug("rwsdk:e2e:environment");
|
|
14
14
|
const getTempDir = async () => {
|
|
15
15
|
return tmp.dir({ unsafeCleanup: true });
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type Browser, type Page } from "puppeteer-core";
|
|
2
2
|
import { test } from "vitest";
|
|
3
|
+
import { DEPLOYMENT_CHECK_TIMEOUT, DEPLOYMENT_MIN_TRIES, DEPLOYMENT_TIMEOUT, DEV_SERVER_MIN_TRIES, DEV_SERVER_TIMEOUT, HYDRATION_TIMEOUT, INSTALL_DEPENDENCIES_RETRIES, PUPPETEER_TIMEOUT, SETUP_PLAYGROUND_ENV_TIMEOUT, SETUP_WAIT_TIMEOUT, TEST_MAX_RETRIES, TEST_MAX_RETRIES_PER_CODE } from "./constants.mjs";
|
|
3
4
|
export type { Browser, Page } from "puppeteer-core";
|
|
4
|
-
export
|
|
5
|
+
export { DEPLOYMENT_CHECK_TIMEOUT, DEPLOYMENT_MIN_TRIES, DEPLOYMENT_TIMEOUT, DEV_SERVER_MIN_TRIES, DEV_SERVER_TIMEOUT, HYDRATION_TIMEOUT, INSTALL_DEPENDENCIES_RETRIES, PUPPETEER_TIMEOUT, SETUP_PLAYGROUND_ENV_TIMEOUT, SETUP_WAIT_TIMEOUT, TEST_MAX_RETRIES, TEST_MAX_RETRIES_PER_CODE, };
|
|
5
6
|
interface DevServerInstance {
|
|
6
7
|
url: string;
|
|
7
8
|
stopDev: () => Promise<void>;
|
|
@@ -4,48 +4,12 @@ import path, { basename, dirname, join as pathJoin } from "path";
|
|
|
4
4
|
import puppeteer from "puppeteer-core";
|
|
5
5
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, test, } from "vitest";
|
|
6
6
|
import { launchBrowser } from "./browser.mjs";
|
|
7
|
+
import { DEPLOYMENT_CHECK_TIMEOUT, DEPLOYMENT_MIN_TRIES, DEPLOYMENT_TIMEOUT, DEV_SERVER_MIN_TRIES, DEV_SERVER_TIMEOUT, HYDRATION_TIMEOUT, INSTALL_DEPENDENCIES_RETRIES, PUPPETEER_TIMEOUT, SETUP_PLAYGROUND_ENV_TIMEOUT, SETUP_WAIT_TIMEOUT, TEST_MAX_RETRIES, TEST_MAX_RETRIES_PER_CODE, } from "./constants.mjs";
|
|
7
8
|
import { runDevServer } from "./dev.mjs";
|
|
8
9
|
import { poll, pollValue } from "./poll.mjs";
|
|
9
10
|
import { deleteD1Database, deleteWorker, isRelatedToTest, runRelease, } from "./release.mjs";
|
|
10
11
|
import { setupTarballEnvironment } from "./tarball.mjs";
|
|
11
|
-
|
|
12
|
-
.RWSDK_SETUP_PLAYGROUND_ENV_TIMEOUT
|
|
13
|
-
? parseInt(process.env.RWSDK_SETUP_PLAYGROUND_ENV_TIMEOUT, 10)
|
|
14
|
-
: 15 * 60 * 1000;
|
|
15
|
-
const DEPLOYMENT_TIMEOUT = process.env.RWSDK_DEPLOYMENT_TIMEOUT
|
|
16
|
-
? parseInt(process.env.RWSDK_DEPLOYMENT_TIMEOUT, 10)
|
|
17
|
-
: 5 * 60 * 1000;
|
|
18
|
-
const DEPLOYMENT_MIN_TRIES = process.env.RWSDK_DEPLOYMENT_MIN_TRIES
|
|
19
|
-
? parseInt(process.env.RWSDK_DEPLOYMENT_MIN_TRIES, 10)
|
|
20
|
-
: 5;
|
|
21
|
-
const DEPLOYMENT_CHECK_TIMEOUT = process.env.RWSDK_DEPLOYMENT_CHECK_TIMEOUT
|
|
22
|
-
? parseInt(process.env.RWSDK_DEPLOYMENT_CHECK_TIMEOUT, 10)
|
|
23
|
-
: 5 * 60 * 1000;
|
|
24
|
-
const PUPPETEER_TIMEOUT = process.env.RWSDK_PUPPETEER_TIMEOUT
|
|
25
|
-
? parseInt(process.env.RWSDK_PUPPETEER_TIMEOUT, 10)
|
|
26
|
-
: 60 * 1000 * 2;
|
|
27
|
-
const HYDRATION_TIMEOUT = process.env.RWSDK_HYDRATION_TIMEOUT
|
|
28
|
-
? parseInt(process.env.RWSDK_HYDRATION_TIMEOUT, 10)
|
|
29
|
-
: 5000;
|
|
30
|
-
const DEV_SERVER_TIMEOUT = process.env.RWSDK_DEV_SERVER_TIMEOUT
|
|
31
|
-
? parseInt(process.env.RWSDK_DEV_SERVER_TIMEOUT, 10)
|
|
32
|
-
: 5 * 60 * 1000;
|
|
33
|
-
const DEV_SERVER_MIN_TRIES = process.env.RWSDK_DEV_SERVER_MIN_TRIES
|
|
34
|
-
? parseInt(process.env.RWSDK_DEV_SERVER_MIN_TRIES, 10)
|
|
35
|
-
: 5;
|
|
36
|
-
const SETUP_WAIT_TIMEOUT = process.env.RWSDK_SETUP_WAIT_TIMEOUT
|
|
37
|
-
? parseInt(process.env.RWSDK_SETUP_WAIT_TIMEOUT, 10)
|
|
38
|
-
: 10 * 60 * 1000;
|
|
39
|
-
const TEST_MAX_RETRIES = process.env.RWSDK_TEST_MAX_RETRIES
|
|
40
|
-
? parseInt(process.env.RWSDK_TEST_MAX_RETRIES, 10)
|
|
41
|
-
: 10;
|
|
42
|
-
const TEST_MAX_RETRIES_PER_CODE = process.env.RWSDK_TEST_MAX_RETRIES_PER_CODE
|
|
43
|
-
? parseInt(process.env.RWSDK_TEST_MAX_RETRIES_PER_CODE, 10)
|
|
44
|
-
: 6;
|
|
45
|
-
export const INSTALL_DEPENDENCIES_RETRIES = process.env
|
|
46
|
-
.RWSDK_INSTALL_DEPENDENCIES_RETRIES
|
|
47
|
-
? parseInt(process.env.RWSDK_INSTALL_DEPENDENCIES_RETRIES, 10)
|
|
48
|
-
: 10;
|
|
12
|
+
export { DEPLOYMENT_CHECK_TIMEOUT, DEPLOYMENT_MIN_TRIES, DEPLOYMENT_TIMEOUT, DEV_SERVER_MIN_TRIES, DEV_SERVER_TIMEOUT, HYDRATION_TIMEOUT, INSTALL_DEPENDENCIES_RETRIES, PUPPETEER_TIMEOUT, SETUP_PLAYGROUND_ENV_TIMEOUT, SETUP_WAIT_TIMEOUT, TEST_MAX_RETRIES, TEST_MAX_RETRIES_PER_CODE, };
|
|
49
13
|
// Environment variable flags for skipping tests
|
|
50
14
|
const SKIP_DEV_SERVER_TESTS = process.env.RWSDK_SKIP_DEV === "1";
|
|
51
15
|
const SKIP_DEPLOYMENT_TESTS = process.env.RWSDK_SKIP_DEPLOY === "1";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "./setWebpackRequire";
|
|
2
2
|
export { default as React } from "react";
|
|
3
3
|
export { ClientOnly } from "./ClientOnly.js";
|
|
4
|
+
export { initClientNavigation, navigate } from "./navigation.js";
|
|
4
5
|
import type { HydrationOptions, Transport } from "./types";
|
|
5
6
|
export declare const fetchTransport: Transport;
|
|
6
7
|
export declare const initClient: ({ transport, hydrateRootOptions, handleResponse, }?: {
|
|
@@ -11,6 +11,7 @@ import { createFromFetch, createFromReadableStream, encodeReply, } from "react-s
|
|
|
11
11
|
import { rscStream } from "rsc-html-stream/client";
|
|
12
12
|
export { default as React } from "react";
|
|
13
13
|
export { ClientOnly } from "./ClientOnly.js";
|
|
14
|
+
export { initClientNavigation, navigate } from "./navigation.js";
|
|
14
15
|
export const fetchTransport = (transportContext) => {
|
|
15
16
|
const fetchCallServer = async (id, args) => {
|
|
16
17
|
const url = new URL(window.location.href);
|
|
@@ -4,6 +4,14 @@ export interface ClientNavigationOptions {
|
|
|
4
4
|
scrollBehavior?: "auto" | "smooth" | "instant";
|
|
5
5
|
}
|
|
6
6
|
export declare function validateClickEvent(event: MouseEvent, target: HTMLElement): boolean;
|
|
7
|
+
export interface NavigateOptions {
|
|
8
|
+
history?: "push" | "replace";
|
|
9
|
+
info?: {
|
|
10
|
+
scrollToTop?: boolean;
|
|
11
|
+
scrollBehavior?: "auto" | "smooth" | "instant";
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare function navigate(href: string, options?: NavigateOptions): Promise<void>;
|
|
7
15
|
export declare function initClientNavigation(opts?: ClientNavigationOptions): {
|
|
8
16
|
handleResponse: (response: Response) => boolean;
|
|
9
17
|
};
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
function saveScrollPosition(x, y) {
|
|
2
|
-
window.history.replaceState({
|
|
3
|
-
...window.history.state,
|
|
4
|
-
scrollX: x,
|
|
5
|
-
scrollY: y,
|
|
6
|
-
}, "", window.location.href);
|
|
7
|
-
}
|
|
8
1
|
export function validateClickEvent(event, target) {
|
|
9
2
|
// should this only work for left click?
|
|
10
3
|
if (event.button !== 0) {
|
|
@@ -37,19 +30,43 @@ export function validateClickEvent(event, target) {
|
|
|
37
30
|
}
|
|
38
31
|
return true;
|
|
39
32
|
}
|
|
33
|
+
let IS_CLIENT_NAVIGATION = false;
|
|
34
|
+
export async function navigate(href, options = { history: "push" }) {
|
|
35
|
+
if (!IS_CLIENT_NAVIGATION) {
|
|
36
|
+
window.location.href = href;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
saveScrollPosition(window.scrollX, window.scrollY);
|
|
40
|
+
const url = window.location.origin + href;
|
|
41
|
+
if (options.history === "push") {
|
|
42
|
+
window.history.pushState({ path: href }, "", url);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
window.history.replaceState({ path: href }, "", url);
|
|
46
|
+
}
|
|
47
|
+
await globalThis.__rsc_callServer;
|
|
48
|
+
const scrollToTop = options.info?.scrollToTop ?? true;
|
|
49
|
+
const scrollBehavior = options.info?.scrollBehavior ?? "instant";
|
|
50
|
+
if (scrollToTop && history.scrollRestoration === "auto") {
|
|
51
|
+
window.scrollTo({
|
|
52
|
+
top: 0,
|
|
53
|
+
left: 0,
|
|
54
|
+
behavior: scrollBehavior,
|
|
55
|
+
});
|
|
56
|
+
saveScrollPosition(0, 0);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function saveScrollPosition(x, y) {
|
|
60
|
+
window.history.replaceState({
|
|
61
|
+
...window.history.state,
|
|
62
|
+
scrollX: x,
|
|
63
|
+
scrollY: y,
|
|
64
|
+
}, "", window.location.href);
|
|
65
|
+
}
|
|
40
66
|
export function initClientNavigation(opts = {}) {
|
|
41
|
-
|
|
42
|
-
onNavigate: async function onNavigate() {
|
|
43
|
-
// @ts-expect-error
|
|
44
|
-
await globalThis.__rsc_callServer();
|
|
45
|
-
},
|
|
46
|
-
scrollToTop: true,
|
|
47
|
-
scrollBehavior: "instant",
|
|
48
|
-
...opts,
|
|
49
|
-
};
|
|
67
|
+
IS_CLIENT_NAVIGATION = true;
|
|
50
68
|
history.scrollRestoration = "auto";
|
|
51
69
|
document.addEventListener("click", async function handleClickEvent(event) {
|
|
52
|
-
// Prevent default navigation
|
|
53
70
|
if (!validateClickEvent(event, event.target)) {
|
|
54
71
|
return;
|
|
55
72
|
}
|
|
@@ -57,28 +74,18 @@ export function initClientNavigation(opts = {}) {
|
|
|
57
74
|
const el = event.target;
|
|
58
75
|
const a = el.closest("a");
|
|
59
76
|
const href = a?.getAttribute("href");
|
|
60
|
-
|
|
61
|
-
window.history.pushState({ path: href }, "", window.location.origin + href);
|
|
62
|
-
await options.onNavigate();
|
|
63
|
-
if (options.scrollToTop && history.scrollRestoration === "auto") {
|
|
64
|
-
window.scrollTo({
|
|
65
|
-
top: 0,
|
|
66
|
-
left: 0,
|
|
67
|
-
behavior: options.scrollBehavior,
|
|
68
|
-
});
|
|
69
|
-
saveScrollPosition(0, 0);
|
|
70
|
-
}
|
|
71
|
-
history.scrollRestoration = "auto";
|
|
77
|
+
navigate(href);
|
|
72
78
|
}, true);
|
|
73
79
|
window.addEventListener("popstate", async function handlePopState() {
|
|
74
|
-
|
|
75
|
-
await
|
|
80
|
+
// @ts-expect-error
|
|
81
|
+
await globalThis.__rsc_callServer();
|
|
76
82
|
});
|
|
77
83
|
// Return a handleResponse function for use with initClient
|
|
78
84
|
return {
|
|
79
85
|
handleResponse: function handleResponse(response) {
|
|
80
86
|
if (!response.ok) {
|
|
81
87
|
// Redirect to the current page (window.location) to show the error
|
|
88
|
+
// This means the page that produced the error is called twice.
|
|
82
89
|
window.location.href = window.location.href;
|
|
83
90
|
return false;
|
|
84
91
|
}
|