@kasperpeulen/vitest-plugin-nextjs 0.0.0-alpha.0 → 0.1.0-alpha.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/README.md +249 -2
- package/dist/_virtual/_rolldown/runtime.js +14 -0
- package/dist/action-ids.d.ts +18 -0
- package/dist/action-ids.js +44 -0
- package/dist/adapter.d.ts +8 -0
- package/dist/adapter.js +12 -0
- package/dist/app-requests.d.ts +63 -0
- package/dist/app-requests.js +253 -0
- package/dist/browser-context.d.ts +24 -0
- package/dist/browser-context.js +157 -0
- package/dist/build-output.d.ts +68 -0
- package/dist/build-output.js +216 -0
- package/dist/build.d.ts +26 -0
- package/dist/build.js +39 -0
- package/dist/built-files.d.ts +9 -0
- package/dist/built-files.js +22 -0
- package/dist/cache.d.ts +44 -0
- package/dist/cache.js +99 -0
- package/dist/client-components.d.ts +3 -0
- package/dist/client-components.js +4 -0
- package/dist/client-file-key.d.ts +5 -0
- package/dist/client-file-key.js +5 -0
- package/dist/client-files.d.ts +83 -0
- package/dist/client-files.js +186 -0
- package/dist/client-graph.d.ts +94 -0
- package/dist/client-graph.js +266 -0
- package/dist/client-modules.d.ts +10 -0
- package/dist/client-modules.js +43 -0
- package/dist/client.d.ts +42 -0
- package/dist/client.js +263 -0
- package/dist/commonjs.d.ts +44 -0
- package/dist/commonjs.js +111 -0
- package/dist/compat/browser/client.d.ts +19 -0
- package/dist/compat/browser/client.js +13 -0
- package/dist/compat/build.d.ts +145 -0
- package/dist/compat/build.js +149 -0
- package/dist/compat/checks.d.ts +16 -0
- package/dist/compat/checks.js +148 -0
- package/dist/compat/patches.d.ts +13 -0
- package/dist/compat/patches.js +30 -0
- package/dist/compat/paths.d.ts +74 -0
- package/dist/compat/paths.js +160 -0
- package/dist/compat/rsc/handlers.d.ts +2 -0
- package/dist/compat/rsc/handlers.js +2 -0
- package/dist/compat/rsc/prerender.d.ts +10 -0
- package/dist/compat/rsc/prerender.js +9 -0
- package/dist/compat/server/headers.d.ts +3 -0
- package/dist/compat/server/headers.js +3 -0
- package/dist/compat/ssr/build-output.d.ts +4 -0
- package/dist/compat/ssr/build-output.js +3 -0
- package/dist/compat/ssr/cache.d.ts +6 -0
- package/dist/compat/ssr/cache.js +6 -0
- package/dist/compat/ssr/handler.d.ts +8 -0
- package/dist/compat/ssr/handler.js +8 -0
- package/dist/compat/ssr/node-server.d.ts +5 -0
- package/dist/compat/ssr/node-server.js +4 -0
- package/dist/compat/ssr/render-errors.d.ts +4 -0
- package/dist/compat/ssr/render-errors.js +4 -0
- package/dist/compat/ssr/senders.d.ts +6 -0
- package/dist/compat/ssr/senders.js +6 -0
- package/dist/compat/types.d.ts +8 -0
- package/dist/compat/types.js +1 -0
- package/dist/compile.d.ts +31 -0
- package/dist/compile.js +140 -0
- package/dist/disk.d.ts +16 -0
- package/dist/disk.js +13 -0
- package/dist/document-loads.d.ts +15 -0
- package/dist/document-loads.js +53 -0
- package/dist/document.d.ts +79 -0
- package/dist/document.js +328 -0
- package/dist/downloads.d.ts +15 -0
- package/dist/downloads.js +71 -0
- package/dist/esm-require.d.ts +11 -0
- package/dist/esm-require.js +32 -0
- package/dist/fast-crypto/index.js +1093 -0
- package/dist/fast-crypto.d.ts +20 -0
- package/dist/fast-crypto.js +151 -0
- package/dist/flight.d.ts +19 -0
- package/dist/flight.js +42 -0
- package/dist/form-submission.d.ts +15 -0
- package/dist/form-submission.js +27 -0
- package/dist/from-page.d.ts +5 -0
- package/dist/from-page.js +44 -0
- package/dist/globals.d.ts +1 -0
- package/dist/globals.js +197 -0
- package/dist/host-document.d.ts +26 -0
- package/dist/host-document.js +34 -0
- package/dist/index.d.ts +280 -0
- package/dist/index.js +281 -0
- package/dist/internal.d.ts +2 -0
- package/dist/internal.js +3 -0
- package/dist/leftovers.d.ts +11 -0
- package/dist/leftovers.js +55 -0
- package/dist/mode.d.ts +169 -0
- package/dist/mode.js +31 -0
- package/dist/node/LICENSES.md +3540 -0
- package/dist/node/assert/strict.js +29 -0
- package/dist/node/assert.js +3044 -0
- package/dist/node/buffer.js +1499 -0
- package/dist/node/child_process.js +45 -0
- package/dist/node/cluster.js +85 -0
- package/dist/node/console.js +96 -0
- package/dist/node/constants.js +495 -0
- package/dist/node/crypto.js +1388 -0
- package/dist/node/dgram.js +78 -0
- package/dist/node/diagnostics_channel.js +122 -0
- package/dist/node/dns/promises.js +129 -0
- package/dist/node/dns.js +137 -0
- package/dist/node/domain.js +43 -0
- package/dist/node/events.js +1155 -0
- package/dist/node/fs/promises.js +40 -0
- package/dist/node/fs.js +10375 -0
- package/dist/node/http.js +326 -0
- package/dist/node/http2.js +305 -0
- package/dist/node/https.js +57 -0
- package/dist/node/inspector/promises.js +66 -0
- package/dist/node/inspector.js +76 -0
- package/dist/node/module.js +205 -0
- package/dist/node/net.js +392 -0
- package/dist/node/os.js +259 -0
- package/dist/node/path/posix.js +25 -0
- package/dist/node/path/win32.js +25 -0
- package/dist/node/path.js +384 -0
- package/dist/node/perf_hooks.js +313 -0
- package/dist/node/process.js +452 -0
- package/dist/node/punycode.js +178 -0
- package/dist/node/querystring.js +934 -0
- package/dist/node/readline/promises.js +71 -0
- package/dist/node/readline.js +56 -0
- package/dist/node/repl.js +44 -0
- package/dist/node/sqlite.js +22 -0
- package/dist/node/stream/consumers.js +47 -0
- package/dist/node/stream/promises.js +6 -0
- package/dist/node/stream/web.js +52 -0
- package/dist/node/stream.js +4323 -0
- package/dist/node/string_decoder.js +276 -0
- package/dist/node/sys.js +6 -0
- package/dist/node/timers/promises.js +71 -0
- package/dist/node/timers.js +133 -0
- package/dist/node/tls.js +122 -0
- package/dist/node/trace_events.js +23 -0
- package/dist/node/tty.js +69 -0
- package/dist/node/url.js +1426 -0
- package/dist/node/util/types.js +1456 -0
- package/dist/node/util.js +4807 -0
- package/dist/node/v8.js +160 -0
- package/dist/node/vm.js +88 -0
- package/dist/node/wasi.js +16 -0
- package/dist/node/worker_threads.js +123 -0
- package/dist/node/zlib.js +1396 -0
- package/dist/node-builtins.d.ts +40 -0
- package/dist/node-builtins.js +74 -0
- package/dist/node-on-page.d.ts +46 -0
- package/dist/node-on-page.js +101 -0
- package/dist/node-platform.d.ts +36 -0
- package/dist/node-platform.js +152 -0
- package/dist/node-rendered.d.ts +21 -0
- package/dist/node-rendered.js +26 -0
- package/dist/node-server.d.ts +46 -0
- package/dist/node-server.js +193 -0
- package/dist/optimizer-cache-key.d.ts +26 -0
- package/dist/optimizer-cache-key.js +73 -0
- package/dist/own-package.d.ts +1 -0
- package/dist/own-package.js +6 -0
- package/dist/page-store.d.ts +33 -0
- package/dist/page-store.js +80 -0
- package/dist/page-timers.d.ts +22 -0
- package/dist/page-timers.js +47 -0
- package/dist/page.d.ts +112 -0
- package/dist/page.js +549 -0
- package/dist/paths.d.ts +13 -0
- package/dist/paths.js +47 -0
- package/dist/plugin.d.ts +22 -0
- package/dist/plugin.js +995 -0
- package/dist/prerender-verdict.d.ts +8 -0
- package/dist/prerender-verdict.js +67 -0
- package/dist/project/context.d.ts +546 -0
- package/dist/project/context.js +111 -0
- package/dist/project/entries.d.ts +42 -0
- package/dist/project/entries.js +189 -0
- package/dist/project/env-worker.d.ts +1 -0
- package/dist/project/env-worker.js +9 -0
- package/dist/project/env.d.ts +36 -0
- package/dist/project/env.js +82 -0
- package/dist/project/layers.d.ts +31 -0
- package/dist/project/layers.js +150 -0
- package/dist/project/loaders.d.ts +71 -0
- package/dist/project/loaders.js +300 -0
- package/dist/project/metadata.d.ts +8 -0
- package/dist/project/metadata.js +34 -0
- package/dist/project/module-exports.d.ts +29 -0
- package/dist/project/module-exports.js +77 -0
- package/dist/project/routes.d.ts +19 -0
- package/dist/project/routes.js +92 -0
- package/dist/project/routing.d.ts +46 -0
- package/dist/project/routing.js +280 -0
- package/dist/project/transform.d.ts +8 -0
- package/dist/project/transform.js +110 -0
- package/dist/project/webpack.d.ts +46 -0
- package/dist/project/webpack.js +160 -0
- package/dist/project.d.ts +264 -0
- package/dist/project.js +58 -0
- package/dist/registry-global.d.ts +5 -0
- package/dist/registry-global.js +5 -0
- package/dist/registry.d.ts +241 -0
- package/dist/registry.js +30 -0
- package/dist/route-chunks.d.ts +13 -0
- package/dist/route-chunks.js +32 -0
- package/dist/route-lookup.d.ts +34 -0
- package/dist/route-lookup.js +207 -0
- package/dist/routes-ahead-shared.d.ts +17 -0
- package/dist/routes-ahead-shared.js +9 -0
- package/dist/routes-ahead.d.ts +10 -0
- package/dist/routes-ahead.js +54 -0
- package/dist/rsc.d.ts +19 -0
- package/dist/rsc.js +171 -0
- package/dist/server-action.d.ts +9 -0
- package/dist/server-action.js +15 -0
- package/dist/server-code.d.ts +176 -0
- package/dist/server-code.js +357 -0
- package/dist/server-in-front.d.ts +37 -0
- package/dist/server-in-front.js +90 -0
- package/dist/server-layers.d.ts +22 -0
- package/dist/server-layers.js +33 -0
- package/dist/setup-browser.d.ts +1 -0
- package/dist/setup-browser.js +8 -0
- package/dist/setup-node.d.ts +1 -0
- package/dist/setup-node.js +6 -0
- package/dist/setup.d.ts +8 -0
- package/dist/setup.js +62 -0
- package/dist/speed-features.d.ts +13 -0
- package/dist/speed-features.js +95 -0
- package/dist/ssr.d.ts +70 -0
- package/dist/ssr.js +480 -0
- package/dist/static-build.d.ts +36 -0
- package/dist/static-build.js +92 -0
- package/dist/storage.d.ts +31 -0
- package/dist/storage.js +94 -0
- package/dist/styles-shared.d.ts +137 -0
- package/dist/styles-shared.js +124 -0
- package/dist/styles.d.ts +102 -0
- package/dist/styles.js +730 -0
- package/dist/stylesheet-versions.d.ts +17 -0
- package/dist/stylesheet-versions.js +43 -0
- package/dist/tester.html +10 -0
- package/dist/use-cache.d.ts +15 -0
- package/dist/use-cache.js +93 -0
- package/dist/vitest-version.d.ts +6 -0
- package/dist/vitest-version.js +12 -0
- package/package.json +125 -4
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import "./globals.js";
|
|
2
|
+
import { createEnvironmentRunner, environmentModule } from "@kasperpeulen/vitest-plugin-rsc/internal/utils";
|
|
3
|
+
//#region src/server-layers.ts
|
|
4
|
+
/**
|
|
5
|
+
* The rsc layer: Server Components, Server Actions, route handlers and the
|
|
6
|
+
* Flight encoder, see rsc.ts. The document's own module graph.
|
|
7
|
+
*/
|
|
8
|
+
function rscLayer() {
|
|
9
|
+
return import("./rsc.js");
|
|
10
|
+
}
|
|
11
|
+
let loading;
|
|
12
|
+
let loaded;
|
|
13
|
+
/**
|
|
14
|
+
* The ssr layer: Next's request handler and HTML renderer, see ssr.ts, with
|
|
15
|
+
* the rsc layer, which a request needs too. It starts to load the first time
|
|
16
|
+
* something asks for it: a request that the server handles, or the entry of
|
|
17
|
+
* the server's API as it evaluates. The server in front of the app needs
|
|
18
|
+
* neither layer: see server-in-front.ts. A build fetches the layer's file
|
|
19
|
+
* when its runner asks for it: see built-layers.ts.
|
|
20
|
+
*/
|
|
21
|
+
function ssrLayer() {
|
|
22
|
+
if (!loading) {
|
|
23
|
+
loading = Promise.all([rscLayer(), createEnvironmentRunner("next_ssr").import(environmentModule("next_ssr", "@kasperpeulen/vitest-plugin-nextjs/ssr"))]).then(([, layer]) => loaded = layer);
|
|
24
|
+
loading.catch(() => {});
|
|
25
|
+
}
|
|
26
|
+
return loading;
|
|
27
|
+
}
|
|
28
|
+
/** The ssr layer once it has loaded: until then there is nothing of it to settle or reset. */
|
|
29
|
+
function loadedSsrLayer() {
|
|
30
|
+
return loaded;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { loadedSsrLayer, rscLayer, ssrLayer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { findOnEveryChange } from "./speed-features.js";
|
|
2
|
+
import { setUpTestFiles } from "./setup.js";
|
|
3
|
+
import { page, server } from "vitest/browser";
|
|
4
|
+
//#region src/setup-browser.ts
|
|
5
|
+
await setUpTestFiles(server.config.setupFiles);
|
|
6
|
+
findOnEveryChange(page.getByText(""));
|
|
7
|
+
//#endregion
|
|
8
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/setup.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/setup.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The hooks of every test file, whose setup files are `setupFiles`, as the
|
|
4
|
+
* config of the run has them. Resolves once the ssr layer has loaded.
|
|
5
|
+
*/
|
|
6
|
+
declare function setUpTestFiles(setupFiles: readonly string[]): Promise<void>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { setUpTestFiles };
|
package/dist/setup.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { registry } from "./registry.js";
|
|
2
|
+
import { pollOnEveryChange } from "./speed-features.js";
|
|
3
|
+
import { ssrLayer } from "./server-layers.js";
|
|
4
|
+
import { forgetClientFiles, linkStylesheetsOf, loadedAsClientFile } from "./client-graph.js";
|
|
5
|
+
import { leaveKeptAppWithPage, noRouter } from "./page.js";
|
|
6
|
+
import { keepHostDocument } from "./host-document.js";
|
|
7
|
+
import { cleanup, newBrowserContext } from "./index.js";
|
|
8
|
+
import { routesAheadEvent } from "./routes-ahead-shared.js";
|
|
9
|
+
import { askDevServer, forgetHeardVersions } from "@kasperpeulen/vitest-plugin-rsc/internal/utils";
|
|
10
|
+
import { afterAll, afterEach, beforeAll, beforeEach, expect, vi } from "vitest";
|
|
11
|
+
import "virtual:vitest-plugin-rsc/next-fast-crypto";
|
|
12
|
+
//#region src/setup.ts
|
|
13
|
+
/**
|
|
14
|
+
* The hooks of every test file, whose setup files are `setupFiles`, as the
|
|
15
|
+
* config of the run has them. Resolves once the ssr layer has loaded.
|
|
16
|
+
*/
|
|
17
|
+
async function setUpTestFiles(setupFiles) {
|
|
18
|
+
forgetClientFiles();
|
|
19
|
+
forgetHeardVersions();
|
|
20
|
+
let nodeFiles = [...setupFiles];
|
|
21
|
+
registry.nodeFiles = () => nodeFiles;
|
|
22
|
+
let clientFile = false;
|
|
23
|
+
let keptDocument;
|
|
24
|
+
beforeAll(async ({}, suite) => {
|
|
25
|
+
nodeFiles = [...setupFiles, suite.file.filepath];
|
|
26
|
+
clientFile = loadedAsClientFile(suite.file.filepath);
|
|
27
|
+
if (clientFile) keptDocument = keepHostDocument((url) => reportError(noRouter(url)));
|
|
28
|
+
await linkStylesheetsOf(nodeFiles);
|
|
29
|
+
compileRoutesAhead(suite.file.filepath);
|
|
30
|
+
}, 0);
|
|
31
|
+
afterAll(async () => {
|
|
32
|
+
try {
|
|
33
|
+
await leaveKeptAppWithPage("the end of the test file");
|
|
34
|
+
} finally {
|
|
35
|
+
keptDocument?.();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
await ssrLayer();
|
|
39
|
+
afterEach(() => cleanup());
|
|
40
|
+
beforeEach(async () => {
|
|
41
|
+
await (clientFile ? cleanup() : newBrowserContext());
|
|
42
|
+
await linkStylesheetsOf(nodeFiles);
|
|
43
|
+
});
|
|
44
|
+
pollOnEveryChange(expect, () => vi.isFakeTimers());
|
|
45
|
+
}
|
|
46
|
+
function compileRoutesAhead(testFile) {
|
|
47
|
+
const tell = (news) => {
|
|
48
|
+
askDevServer(routesAheadEvent, news).catch(() => {});
|
|
49
|
+
};
|
|
50
|
+
tell({ testFile });
|
|
51
|
+
const opened = /* @__PURE__ */ new Set();
|
|
52
|
+
registry.routeOpened = (entry) => {
|
|
53
|
+
if (opened.has(entry)) return;
|
|
54
|
+
opened.add(entry);
|
|
55
|
+
tell({
|
|
56
|
+
testFile,
|
|
57
|
+
opened: entry
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { setUpTestFiles };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SpeedFeature } from "./mode.js";
|
|
2
|
+
|
|
3
|
+
//#region src/speed-features.d.ts
|
|
4
|
+
/** Whether a speed feature is on in the page. */
|
|
5
|
+
declare function speedFeature(feature: SpeedFeature): boolean;
|
|
6
|
+
/** With `watchDom`, has `locator` (a Locator of `vitest/browser`) look on every change of the document. */
|
|
7
|
+
declare function findOnEveryChange(locator: object): void;
|
|
8
|
+
/** With `watchDom`, has `expect.poll()`, and so `expect.element()`, look again on the next change of the document. */
|
|
9
|
+
declare function pollOnEveryChange(expect: {
|
|
10
|
+
poll?: unknown;
|
|
11
|
+
}, fakeTimers: () => boolean): void;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { findOnEveryChange, pollOnEveryChange, speedFeature };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { registry } from "./registry.js";
|
|
2
|
+
//#region src/speed-features.ts
|
|
3
|
+
/** Whether a speed feature is on in the page. */
|
|
4
|
+
function speedFeature(feature) {
|
|
5
|
+
return registry.speedFeatures?.[feature] === true;
|
|
6
|
+
}
|
|
7
|
+
const findInterval = 5;
|
|
8
|
+
const setTimeout = globalThis.setTimeout;
|
|
9
|
+
const clearTimeout = globalThis.clearTimeout;
|
|
10
|
+
const changeEvents = [
|
|
11
|
+
"input",
|
|
12
|
+
"change",
|
|
13
|
+
"focusin",
|
|
14
|
+
"focusout",
|
|
15
|
+
"load",
|
|
16
|
+
"error",
|
|
17
|
+
"transitionend",
|
|
18
|
+
"animationend"
|
|
19
|
+
];
|
|
20
|
+
const observed = {
|
|
21
|
+
subtree: true,
|
|
22
|
+
childList: true,
|
|
23
|
+
attributes: true,
|
|
24
|
+
characterData: true
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Resolves on the next change of the document from now on: a mutation of the
|
|
28
|
+
* DOM, one of `changeEvents`, or `findInterval` for what changes without
|
|
29
|
+
* either, like a value that a script sets.
|
|
30
|
+
*/
|
|
31
|
+
function nextChange() {
|
|
32
|
+
return new Promise((resolve) => {
|
|
33
|
+
const done = () => {
|
|
34
|
+
observer.disconnect();
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
for (const type of changeEvents) document.removeEventListener(type, done, true);
|
|
37
|
+
resolve();
|
|
38
|
+
};
|
|
39
|
+
const observer = new MutationObserver(done);
|
|
40
|
+
observer.observe(document, observed);
|
|
41
|
+
for (const type of changeEvents) document.addEventListener(type, done, true);
|
|
42
|
+
const timer = setTimeout(done, findInterval);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const onEveryChange = Symbol.for("vitest-plugin-rsc:find-on-every-change");
|
|
46
|
+
/** With `watchDom`, has `locator` (a Locator of `vitest/browser`) look on every change of the document. */
|
|
47
|
+
function findOnEveryChange(locator) {
|
|
48
|
+
if (!speedFeature("watchDom")) return;
|
|
49
|
+
let proto = Object.getPrototypeOf(locator);
|
|
50
|
+
while (proto && !Object.prototype.hasOwnProperty.call(proto, "findElement")) proto = Object.getPrototypeOf(proto);
|
|
51
|
+
if (!proto || typeof proto.findElement !== "function" || onEveryChange in proto.findElement) return;
|
|
52
|
+
const vitests = proto.findElement;
|
|
53
|
+
const vitest = () => globalThis.__vitest_browser_runner__;
|
|
54
|
+
async function find(options = {}) {
|
|
55
|
+
const strict = options.strict ?? true;
|
|
56
|
+
const timeout = options.timeout ?? vitest()?.runner?._deadline?.derive() ?? 6e4;
|
|
57
|
+
const start = performance.now();
|
|
58
|
+
for (;;) {
|
|
59
|
+
const elements = this.elements();
|
|
60
|
+
if (elements.length === 1 || elements.length > 1 && !strict) return elements[0];
|
|
61
|
+
if (elements.length > 1 || performance.now() - start >= timeout) return vitests.call(this, {
|
|
62
|
+
...options,
|
|
63
|
+
timeout: 0
|
|
64
|
+
});
|
|
65
|
+
await nextChange();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
proto.findElement = Object.assign(find, { [onEveryChange]: true });
|
|
69
|
+
}
|
|
70
|
+
const pollsOnEveryChange = Symbol.for("vitest-plugin-rsc:poll-on-every-change");
|
|
71
|
+
/** With `watchDom`, has `expect.poll()`, and so `expect.element()`, look again on the next change of the document. */
|
|
72
|
+
function pollOnEveryChange(expect, fakeTimers) {
|
|
73
|
+
if (!speedFeature("watchDom")) return;
|
|
74
|
+
const vitests = expect.poll;
|
|
75
|
+
if (typeof vitests !== "function" || pollsOnEveryChange in vitests) return;
|
|
76
|
+
function poll(fn, options) {
|
|
77
|
+
if (options?.interval !== void 0 || fakeTimers()) return vitests.call(this, fn, options);
|
|
78
|
+
let changed;
|
|
79
|
+
async function polled(...args) {
|
|
80
|
+
if (changed) await changed;
|
|
81
|
+
try {
|
|
82
|
+
return await fn.apply(this, args);
|
|
83
|
+
} finally {
|
|
84
|
+
changed = nextChange();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return vitests.call(this, polled, {
|
|
88
|
+
...options,
|
|
89
|
+
interval: 0
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
expect.poll = Object.assign(poll, { [pollsOnEveryChange]: true });
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { findOnEveryChange, pollOnEveryChange, speedFeature };
|
package/dist/ssr.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Opened, ServerRequest } from "./registry.js";
|
|
2
|
+
import { resetCaches } from "./cache.js";
|
|
3
|
+
|
|
4
|
+
//#region src/ssr.d.ts
|
|
5
|
+
declare namespace ssr_d_exports {
|
|
6
|
+
export { HandleOptions, ShellErrorAnswer, handleRequest, resetCaches, settleRequests, shellErrorAnswer };
|
|
7
|
+
}
|
|
8
|
+
type HandleOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* For a request the server makes to itself while it handles one, which
|
|
11
|
+
* cannot wait for that one to finish.
|
|
12
|
+
*/
|
|
13
|
+
nested?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* What a request gets that the server has nothing for: no route, and no
|
|
16
|
+
* redirect or rewrite, after the middleware has let it through. The
|
|
17
|
+
* not-found page of the app, or with `"pass"` no response: a deployment
|
|
18
|
+
* looks for a file then, which here is the network's to answer.
|
|
19
|
+
*/
|
|
20
|
+
unrouted?: "not-found" | "pass";
|
|
21
|
+
/**
|
|
22
|
+
* What the request opens, in place of what `renderServer()` opened: the
|
|
23
|
+
* route of a node of its own, for this request only, or with `null`
|
|
24
|
+
* nothing.
|
|
25
|
+
*/
|
|
26
|
+
opened?: Opened | null;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the request loads a page into the document, which starts the
|
|
29
|
+
* files of its route as the server renders it: see `preloadRoute()` of the
|
|
30
|
+
* registry.
|
|
31
|
+
*/
|
|
32
|
+
pageLoad?: boolean;
|
|
33
|
+
};
|
|
34
|
+
/** The Next.js server of this app. Without a response only with `unrouted: "pass"`. */
|
|
35
|
+
declare function handleRequest(request: ServerRequest, options?: HandleOptions & {
|
|
36
|
+
unrouted?: "not-found";
|
|
37
|
+
}): Promise<Response>;
|
|
38
|
+
declare function handleRequest(request: ServerRequest, options: HandleOptions): Promise<Response | undefined>;
|
|
39
|
+
/** How the server answers the document of a page whose render failed: see `shellErrorAnswer()`. */
|
|
40
|
+
type ShellErrorAnswer = {
|
|
41
|
+
status: number;
|
|
42
|
+
location?: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* How Next's server answers the document of a page when an error fails the
|
|
46
|
+
* render of its HTML before any of it is out, by the digest of the error, as
|
|
47
|
+
* Next's renderer does in the `catch` of `renderToStream()` (app-render.js):
|
|
48
|
+
* the status of a `notFound()`, `forbidden()` or `unauthorized()`, the 307 or
|
|
49
|
+
* 308 of a `redirect()` and where it goes, without the app's `basePath`, and
|
|
50
|
+
* 500 for any other error. For a page that the server renders no HTML of: see
|
|
51
|
+
* `renderFailureOf()` in page.ts.
|
|
52
|
+
*/
|
|
53
|
+
declare function shellErrorAnswer(digest: string): ShellErrorAnswer;
|
|
54
|
+
/**
|
|
55
|
+
* Ends the requests the server is still handling, when a page is left.
|
|
56
|
+
*
|
|
57
|
+
* A request that has its answer is writing the body: a short wait, then a
|
|
58
|
+
* stop. A test can end while a page streams, on data that will never come.
|
|
59
|
+
*
|
|
60
|
+
* A request that has no answer yet runs code of the app, like a Server Action
|
|
61
|
+
* or a route handler, and nothing can stop that. So it is waited for, and
|
|
62
|
+
* then for the body it writes. So is what requests do after their response,
|
|
63
|
+
* like `after()`. What comes next is not to run while any of that still reads
|
|
64
|
+
* or sets the stores of a request, which would be the ones of the requests
|
|
65
|
+
* that come next. A request that is sent in the meantime waits for all of
|
|
66
|
+
* that, and is dropped: it is one of the page that was left.
|
|
67
|
+
*/
|
|
68
|
+
declare function settleRequests(): Promise<void>;
|
|
69
|
+
//#endregion
|
|
70
|
+
export { HandleOptions, ShellErrorAnswer, handleRequest, resetCaches, settleRequests, shellErrorAnswer, ssr_d_exports };
|