wrangler 0.0.0-e043479 → 0.0.0-e0489587
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 +47 -16
- package/bin/wrangler.js +95 -32
- package/config-schema.json +3059 -0
- package/kv-asset-handler.js +1 -0
- package/package.json +148 -89
- package/templates/__tests__/pages-dev-util.test.ts +128 -0
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/checked-fetch.js +30 -0
- package/templates/facade.d.ts +19 -0
- package/templates/gitignore +170 -0
- package/templates/init-tests/test-jest-new-worker.js +23 -0
- package/templates/init-tests/test-vitest-new-worker.js +24 -0
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +67 -0
- package/templates/middleware/loader-modules.ts +134 -0
- package/templates/middleware/loader-sw.ts +229 -0
- package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +15 -0
- package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
- package/templates/middleware/middleware-serve-static-assets.ts +56 -0
- package/templates/modules-watch-stub.js +4 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.js +3 -3
- package/templates/new-worker.ts +22 -4
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-dev-pipeline.ts +32 -0
- package/templates/pages-dev-util.ts +55 -0
- package/templates/pages-shim.ts +9 -0
- package/templates/pages-template-plugin.ts +190 -0
- package/templates/pages-template-worker.ts +198 -0
- package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
- package/templates/startDevWorker/ProxyWorker.ts +334 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +105 -0
- package/templates/tsconfig.json +6 -103
- package/wrangler-dist/InspectorProxyWorker.js +464 -0
- package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
- package/wrangler-dist/ProxyWorker.js +240 -0
- package/wrangler-dist/ProxyWorker.js.map +6 -0
- package/wrangler-dist/cli.d.ts +26375 -0
- package/wrangler-dist/cli.js +202160 -132057
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/import_meta_url.js +0 -3
- package/miniflare-config-stubs/.env.empty +0 -0
- package/miniflare-config-stubs/package.empty.json +0 -1
- package/miniflare-config-stubs/wrangler.empty.toml +0 -0
- package/pages/functions/buildWorker.ts +0 -62
- package/pages/functions/filepath-routing.test.ts +0 -123
- package/pages/functions/filepath-routing.ts +0 -178
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -151
- package/pages/functions/template-worker.ts +0 -130
- package/src/__tests__/configuration.test.ts +0 -2186
- package/src/__tests__/dev.test.tsx +0 -247
- package/src/__tests__/guess-worker-format.test.ts +0 -66
- package/src/__tests__/helpers/clipboardy-mock.js +0 -4
- package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
- package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
- package/src/__tests__/helpers/mock-account-id.ts +0 -44
- package/src/__tests__/helpers/mock-bin.ts +0 -36
- package/src/__tests__/helpers/mock-cfetch.ts +0 -207
- package/src/__tests__/helpers/mock-console.ts +0 -70
- package/src/__tests__/helpers/mock-dialogs.ts +0 -65
- package/src/__tests__/helpers/mock-kv.ts +0 -40
- package/src/__tests__/helpers/mock-stdin.ts +0 -103
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/helpers/mock-web-socket.ts +0 -29
- package/src/__tests__/helpers/run-in-tmp.ts +0 -29
- package/src/__tests__/helpers/run-wrangler.ts +0 -16
- package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
- package/src/__tests__/index.test.ts +0 -866
- package/src/__tests__/jest.setup.ts +0 -69
- package/src/__tests__/kv.test.ts +0 -1408
- package/src/__tests__/logout.test.ts +0 -50
- package/src/__tests__/package-manager.test.ts +0 -206
- package/src/__tests__/parse.test.ts +0 -322
- package/src/__tests__/publish.test.ts +0 -2139
- package/src/__tests__/r2.test.ts +0 -198
- package/src/__tests__/secret.test.ts +0 -425
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/__tests__/tail.test.ts +0 -564
- package/src/__tests__/whoami.test.tsx +0 -86
- package/src/api/form_data.ts +0 -217
- package/src/api/preview.ts +0 -147
- package/src/api/worker.ts +0 -186
- package/src/bundle.ts +0 -133
- package/src/cfetch/index.ts +0 -104
- package/src/cfetch/internal.ts +0 -133
- package/src/cli.ts +0 -19
- package/src/config/README.md +0 -107
- package/src/config/config.ts +0 -270
- package/src/config/diagnostics.ts +0 -80
- package/src/config/environment.ts +0 -305
- package/src/config/index.ts +0 -52
- package/src/config/validation-helpers.ts +0 -370
- package/src/config/validation.ts +0 -1019
- package/src/dev.tsx +0 -960
- package/src/dialogs.tsx +0 -77
- package/src/entry.ts +0 -57
- package/src/environment-variables.ts +0 -33
- package/src/guess-worker-format.ts +0 -68
- package/src/index.tsx +0 -2302
- package/src/inspect.ts +0 -609
- package/src/kv.tsx +0 -339
- package/src/module-collection.ts +0 -170
- package/src/open-in-browser.ts +0 -13
- package/src/package-manager.ts +0 -126
- package/src/pages.tsx +0 -1045
- package/src/parse.ts +0 -183
- package/src/paths.ts +0 -26
- package/src/proxy.ts +0 -376
- package/src/publish.ts +0 -363
- package/src/r2.ts +0 -50
- package/src/reporting.ts +0 -115
- package/src/sites.tsx +0 -238
- package/src/tail/filters.ts +0 -279
- package/src/tail/index.ts +0 -299
- package/src/tail/printing.ts +0 -62
- package/src/user.tsx +0 -1063
- package/src/whoami.tsx +0 -69
- package/templates/static-asset-facade.js +0 -47
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import * as util from "node:util";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* We use this module to mock console methods, and optionally
|
|
5
|
-
* assert on the values they're called with in our tests.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
let logSpy: jest.SpyInstance,
|
|
9
|
-
errorSpy: jest.SpyInstance,
|
|
10
|
-
warnSpy: jest.SpyInstance;
|
|
11
|
-
|
|
12
|
-
const std = {
|
|
13
|
-
get out() {
|
|
14
|
-
return normalizeOutput(logSpy);
|
|
15
|
-
},
|
|
16
|
-
get err() {
|
|
17
|
-
return normalizeOutput(errorSpy);
|
|
18
|
-
},
|
|
19
|
-
get warn() {
|
|
20
|
-
return normalizeOutput(warnSpy);
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
function normalizeOutput(spy: jest.SpyInstance): string {
|
|
25
|
-
return stripTrailingWhitespace(
|
|
26
|
-
normalizeSlashes(stripTimings(captureCalls(spy)))
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function captureCalls(spy: jest.SpyInstance): string {
|
|
31
|
-
return spy.mock.calls
|
|
32
|
-
.map((args: unknown[]) => util.format("%s", ...args))
|
|
33
|
-
.join("\n");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function mockConsoleMethods() {
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
logSpy = jest.spyOn(console, "log").mockImplementation();
|
|
39
|
-
errorSpy = jest.spyOn(console, "error").mockImplementation();
|
|
40
|
-
warnSpy = jest.spyOn(console, "warn").mockImplementation();
|
|
41
|
-
});
|
|
42
|
-
afterEach(() => {
|
|
43
|
-
logSpy.mockRestore();
|
|
44
|
-
errorSpy.mockRestore();
|
|
45
|
-
warnSpy.mockRestore();
|
|
46
|
-
});
|
|
47
|
-
return std;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Ensure slashes in the `str` are OS file-system agnostic.
|
|
52
|
-
*
|
|
53
|
-
* Use this in snapshot tests to be resilient to file-system differences.
|
|
54
|
-
*/
|
|
55
|
-
export function normalizeSlashes(str: string): string {
|
|
56
|
-
return str.replace(/\\/g, "/");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Strip "timing data" out of the `stdout` string, since this is not always deterministic.
|
|
61
|
-
*
|
|
62
|
-
* Use this in snapshot tests to be resilient to slight changes in timing of processing.
|
|
63
|
-
*/
|
|
64
|
-
export function stripTimings(stdout: string): string {
|
|
65
|
-
return stdout.replace(/\(\d+\.\d+ sec\)/g, "(TIMINGS)");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function stripTrailingWhitespace(str: string): string {
|
|
69
|
-
return str.replace(/[^\S\n]+\n/g, "\n");
|
|
70
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { confirm, prompt } from "../../dialogs";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The expected values for a confirmation request.
|
|
5
|
-
*/
|
|
6
|
-
export interface ConfirmExpectation {
|
|
7
|
-
/** The text expected to be seen in the confirmation dialog. */
|
|
8
|
-
text: string;
|
|
9
|
-
/** The mock response send back from the confirmation dialog. */
|
|
10
|
-
result: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Mock the implementation of `confirm()` that will respond with configured results
|
|
15
|
-
* for configured confirmation text messages.
|
|
16
|
-
*
|
|
17
|
-
* If there is a call to `confirm()` that does not match any of the expectations
|
|
18
|
-
* then an error is thrown.
|
|
19
|
-
*/
|
|
20
|
-
export function mockConfirm(...expectations: ConfirmExpectation[]) {
|
|
21
|
-
(confirm as jest.Mock).mockImplementation((text: string) => {
|
|
22
|
-
for (const { text: expectedText, result } of expectations) {
|
|
23
|
-
if (text === expectedText) {
|
|
24
|
-
return Promise.resolve(result);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
throw new Error(`Unexpected confirmation message: ${text}`);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The expected values for a prompt request.
|
|
33
|
-
*/
|
|
34
|
-
export interface PromptExpectation {
|
|
35
|
-
/** The text expected to be seen in the prompt dialog. */
|
|
36
|
-
text: string;
|
|
37
|
-
/** The type of the prompt. */
|
|
38
|
-
type: "text" | "password";
|
|
39
|
-
/** The mock response send back from the prompt dialog. */
|
|
40
|
-
result: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Mock the implementation of `prompt()` that will respond with configured results
|
|
45
|
-
* for configured prompt text messages.
|
|
46
|
-
*
|
|
47
|
-
* If there is a call to `prompt()` that does not match any of the expectations
|
|
48
|
-
* then an error is thrown.
|
|
49
|
-
*/
|
|
50
|
-
export function mockPrompt(...expectations: PromptExpectation[]) {
|
|
51
|
-
(prompt as jest.Mock).mockImplementation(
|
|
52
|
-
(text: string, type: "text" | "password") => {
|
|
53
|
-
for (const {
|
|
54
|
-
text: expectedText,
|
|
55
|
-
type: expectedType,
|
|
56
|
-
result,
|
|
57
|
-
} of expectations) {
|
|
58
|
-
if (text === expectedText && type == expectedType) {
|
|
59
|
-
return Promise.resolve(result);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
throw new Error(`Unexpected confirmation message: ${text}`);
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { createFetchResult, setMockRawResponse } from "./mock-cfetch";
|
|
2
|
-
|
|
3
|
-
export function mockKeyListRequest(
|
|
4
|
-
expectedNamespaceId: string,
|
|
5
|
-
expectedKeys: string[],
|
|
6
|
-
keysPerRequest = 1000,
|
|
7
|
-
blankCursorValue: "" | undefined | null = undefined
|
|
8
|
-
) {
|
|
9
|
-
const requests = { count: 0 };
|
|
10
|
-
// See https://api.cloudflare.com/#workers-kv-namespace-list-a-namespace-s-keys
|
|
11
|
-
const expectedKeyObjects = expectedKeys.map((name) => ({
|
|
12
|
-
name,
|
|
13
|
-
expiration: 123456789,
|
|
14
|
-
metadata: {},
|
|
15
|
-
}));
|
|
16
|
-
setMockRawResponse(
|
|
17
|
-
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/keys",
|
|
18
|
-
"GET",
|
|
19
|
-
([_url, accountId, namespaceId], _init, query) => {
|
|
20
|
-
requests.count++;
|
|
21
|
-
expect(accountId).toEqual("some-account-id");
|
|
22
|
-
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
23
|
-
if (expectedKeyObjects.length <= keysPerRequest) {
|
|
24
|
-
return createFetchResult(expectedKeyObjects);
|
|
25
|
-
} else {
|
|
26
|
-
const start = parseInt(query.get("cursor") ?? "0") || 0;
|
|
27
|
-
const end = start + keysPerRequest;
|
|
28
|
-
const cursor = end < expectedKeyObjects.length ? end : blankCursorValue;
|
|
29
|
-
return createFetchResult(
|
|
30
|
-
expectedKeyObjects.slice(start, end),
|
|
31
|
-
true,
|
|
32
|
-
[],
|
|
33
|
-
[],
|
|
34
|
-
{ cursor }
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
);
|
|
39
|
-
return requests;
|
|
40
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
const ORIGINAL_STDIN = process.stdin;
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Mock process.stdin so that we can pipe in text for non-interactive mode tests.
|
|
5
|
-
*/
|
|
6
|
-
export function useMockStdin({ isTTY }: { isTTY: boolean }) {
|
|
7
|
-
const mockStdin = new MockStdIn(isTTY);
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
mockStdin.reset();
|
|
11
|
-
Object.defineProperty(process, "stdin", {
|
|
12
|
-
value: mockStdin,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: false,
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
Object.defineProperty(process, "stdin", {
|
|
20
|
-
value: ORIGINAL_STDIN,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: false,
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
return mockStdin;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const failCallback: (value: unknown) => void = () => {
|
|
30
|
-
throw new Error(
|
|
31
|
-
"TEST FAILURE: stdin callback called before being initialized."
|
|
32
|
-
);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* A mock version of `process.std`, which can be used to simulate piping data
|
|
37
|
-
* into the wrangler process in non-interactive mode.
|
|
38
|
-
*/
|
|
39
|
-
class MockStdIn {
|
|
40
|
-
private endCallback = failCallback;
|
|
41
|
-
private errorCallback = failCallback;
|
|
42
|
-
private chunks: string[] = [];
|
|
43
|
-
private error: Error | undefined;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Set this to true if you want the stdin stream to error.
|
|
47
|
-
*/
|
|
48
|
-
throwError(error: Error) {
|
|
49
|
-
this.error = error;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Call this to clean out the chunks that are queued for sending.
|
|
54
|
-
*/
|
|
55
|
-
reset() {
|
|
56
|
-
this.chunks.length = 0;
|
|
57
|
-
this.error = undefined;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Queue up some chunks to be sent.
|
|
62
|
-
*/
|
|
63
|
-
send(...chunks: string[]) {
|
|
64
|
-
this.chunks.push(...chunks);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
constructor(
|
|
68
|
-
/**
|
|
69
|
-
* Used by wrangler to check whether stdin is interactive.
|
|
70
|
-
*/
|
|
71
|
-
readonly isTTY: boolean
|
|
72
|
-
) {}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Used by wrangler to add event listeners.
|
|
76
|
-
*/
|
|
77
|
-
on(eventName: string, callback: () => void) {
|
|
78
|
-
switch (eventName) {
|
|
79
|
-
case "readable":
|
|
80
|
-
setImmediate(callback);
|
|
81
|
-
break;
|
|
82
|
-
case "end":
|
|
83
|
-
this.endCallback = callback;
|
|
84
|
-
break;
|
|
85
|
-
case "error":
|
|
86
|
-
this.errorCallback = callback;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Used by wrangler to get the next chunk of data in the stream.
|
|
93
|
-
*/
|
|
94
|
-
read() {
|
|
95
|
-
if (this.error) {
|
|
96
|
-
setImmediate(() => this.errorCallback(this.error));
|
|
97
|
-
}
|
|
98
|
-
if (this.chunks.length === 0) {
|
|
99
|
-
setImmediate(this.endCallback);
|
|
100
|
-
}
|
|
101
|
-
return this.chunks.shift() ?? null;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
|
|
5
|
-
export function writeUserConfig(
|
|
6
|
-
oauth_token?: string,
|
|
7
|
-
refresh_token?: string,
|
|
8
|
-
expiration_time?: string
|
|
9
|
-
) {
|
|
10
|
-
const lines: string[] = [];
|
|
11
|
-
if (oauth_token) {
|
|
12
|
-
lines.push(`oauth_token = "${oauth_token}"`);
|
|
13
|
-
}
|
|
14
|
-
if (refresh_token) {
|
|
15
|
-
lines.push(`refresh_token = "${refresh_token}"`);
|
|
16
|
-
}
|
|
17
|
-
if (expiration_time) {
|
|
18
|
-
lines.push(`expiration_time = "${expiration_time}"`);
|
|
19
|
-
}
|
|
20
|
-
const configPath = path.join(os.homedir(), ".wrangler/config");
|
|
21
|
-
mkdirSync(configPath, { recursive: true });
|
|
22
|
-
writeFileSync(
|
|
23
|
-
path.join(configPath, "default.toml"),
|
|
24
|
-
lines.join("\n"),
|
|
25
|
-
"utf-8"
|
|
26
|
-
);
|
|
27
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { WebSocket } from "mock-socket";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A version of the mock WebSocket that supports the methods that we use.
|
|
5
|
-
*/
|
|
6
|
-
export class MockWebSocket extends WebSocket {
|
|
7
|
-
on(event: string | symbol, listener: (...args: unknown[]) => void): this {
|
|
8
|
-
switch (event) {
|
|
9
|
-
case "message":
|
|
10
|
-
this.onmessage = ({ data }) => {
|
|
11
|
-
listener(data);
|
|
12
|
-
};
|
|
13
|
-
break;
|
|
14
|
-
case "open":
|
|
15
|
-
this.onopen = listener;
|
|
16
|
-
break;
|
|
17
|
-
case "close":
|
|
18
|
-
this.onclose = listener;
|
|
19
|
-
break;
|
|
20
|
-
default:
|
|
21
|
-
throw new Error("Unknown event type: " + event.toString());
|
|
22
|
-
}
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
terminate() {
|
|
27
|
-
this.close();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
|
|
5
|
-
const originalCwd = process.cwd();
|
|
6
|
-
|
|
7
|
-
export function runInTempDir({ homedir }: { homedir?: string } = {}) {
|
|
8
|
-
let tmpDir: string;
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "wrangler-tests"));
|
|
12
|
-
process.chdir(tmpDir);
|
|
13
|
-
if (homedir !== undefined) {
|
|
14
|
-
// Override where the home directory is so that we can write our own user config,
|
|
15
|
-
// without destroying the real thing.
|
|
16
|
-
fs.mkdirSync(homedir);
|
|
17
|
-
// Note it is very important that we use the "default" value from "node:os" (e.g. `import os from "node:os";`)
|
|
18
|
-
// rather than an alias to the module (e.g. `import * as os from "node:os";`).
|
|
19
|
-
// This is because the module gets transpiled so that the "method" `homedir()` gets converted to a
|
|
20
|
-
// getter that is not configurable (and so cannot be spied upon).
|
|
21
|
-
jest.spyOn(os, "homedir").mockReturnValue(homedir);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
afterEach(() => {
|
|
26
|
-
process.chdir(originalCwd);
|
|
27
|
-
fs.rmSync(tmpDir, { recursive: true });
|
|
28
|
-
});
|
|
29
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { main } from "../../index";
|
|
2
|
-
import { normalizeSlashes, stripTimings } from "./mock-console";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A helper to 'run' wrangler commands for tests.
|
|
6
|
-
*/
|
|
7
|
-
export async function runWrangler(cmd?: string) {
|
|
8
|
-
try {
|
|
9
|
-
await main(cmd?.split(" ") ?? []);
|
|
10
|
-
} catch (err) {
|
|
11
|
-
if (err instanceof Error) {
|
|
12
|
-
err.message = normalizeSlashes(stripTimings(err.message));
|
|
13
|
-
}
|
|
14
|
-
throw err;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import TOML from "@iarna/toml";
|
|
3
|
-
import type { RawConfig } from "../../config";
|
|
4
|
-
|
|
5
|
-
/** Write a mock wrangler.toml file to disk. */
|
|
6
|
-
export default function writeWranglerToml(config: RawConfig = {}) {
|
|
7
|
-
fs.writeFileSync(
|
|
8
|
-
"./wrangler.toml",
|
|
9
|
-
TOML.stringify({
|
|
10
|
-
compatibility_date: "2022-01-12",
|
|
11
|
-
name: "test-name",
|
|
12
|
-
...(config as TOML.JsonMap),
|
|
13
|
-
}),
|
|
14
|
-
|
|
15
|
-
"utf-8"
|
|
16
|
-
);
|
|
17
|
-
}
|