summaryrefslogtreecommitdiff
path: root/node_modules/wrangler/templates/__tests__
diff options
context:
space:
mode:
authorakiyamn2023-09-24 23:22:21 +1000
committerakiyamn2023-09-24 23:22:21 +1000
commit4e87195739f2a5d9a05451b48773c8afdc680765 (patch)
tree9cba501844a4a11dcbdffc4050ed8189561c55ed /node_modules/wrangler/templates/__tests__
downloadprice-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.tar.gz
price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.zip
Initial commit (by create-cloudflare CLI)
Diffstat (limited to 'node_modules/wrangler/templates/__tests__')
-rw-r--r--node_modules/wrangler/templates/__tests__/pages-dev-util.test.ts128
-rw-r--r--node_modules/wrangler/templates/__tests__/tsconfig-sanity.ts12
-rw-r--r--node_modules/wrangler/templates/__tests__/tsconfig.json8
3 files changed, 148 insertions, 0 deletions
diff --git a/node_modules/wrangler/templates/__tests__/pages-dev-util.test.ts b/node_modules/wrangler/templates/__tests__/pages-dev-util.test.ts
new file mode 100644
index 0000000..3dea566
--- /dev/null
+++ b/node_modules/wrangler/templates/__tests__/pages-dev-util.test.ts
@@ -0,0 +1,128 @@
+import { isRoutingRuleMatch } from "../pages-dev-util";
+
+describe("isRoutingRuleMatch", () => {
+ it("should match rules referencing root level correctly", () => {
+ const routingRule = "/";
+
+ expect(isRoutingRuleMatch("/", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo", routingRule)).toBeFalsy();
+ expect(isRoutingRuleMatch("/foo/", routingRule)).toBeFalsy();
+ expect(isRoutingRuleMatch("/foo/bar", routingRule)).toBeFalsy();
+ });
+
+ it("should match include-all rules correctly", () => {
+ const routingRule = "/*";
+
+ expect(isRoutingRuleMatch("/", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/bar", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/bar/", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/bar/baz", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/bar/baz/", routingRule)).toBeTruthy();
+ });
+
+ it("should match `/*` suffix-ed rules correctly", () => {
+ let routingRule = "/foo/*";
+
+ expect(isRoutingRuleMatch("/foo", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foobar", routingRule)).toBeFalsy();
+ expect(isRoutingRuleMatch("/foo/bar", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/bar/baz", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/bar/foo", routingRule)).toBeFalsy();
+ expect(isRoutingRuleMatch("/bar/foo/baz", routingRule)).toBeFalsy();
+
+ routingRule = "/foo/bar/*";
+
+ expect(isRoutingRuleMatch("/foo", routingRule)).toBeFalsy();
+ expect(isRoutingRuleMatch("/foo/", routingRule)).toBeFalsy();
+ expect(isRoutingRuleMatch("/foo/bar", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/bar/baz", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/barfoo", routingRule)).toBeFalsy();
+ expect(isRoutingRuleMatch("baz/foo/bar", routingRule)).toBeFalsy();
+ expect(isRoutingRuleMatch("baz/foo/bar/", routingRule)).toBeFalsy();
+ });
+
+ it("should match `/` suffix-ed rules correctly", () => {
+ let routingRule = "/foo/";
+ expect(isRoutingRuleMatch("/foo/", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo", routingRule)).toBeTruthy();
+
+ routingRule = "/foo/bar/";
+ expect(isRoutingRuleMatch("/foo/bar/", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/bar", routingRule)).toBeTruthy();
+ });
+
+ it("should match `*` suffix-ed rules correctly", () => {
+ let routingRule = "/foo*";
+ expect(isRoutingRuleMatch("/foo", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foobar", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/barfoo", routingRule)).toBeFalsy();
+ expect(isRoutingRuleMatch("/foo/bar", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/bar/foo", routingRule)).toBeFalsy();
+ expect(isRoutingRuleMatch("/bar/foobar", routingRule)).toBeFalsy();
+ expect(isRoutingRuleMatch("/foo/bar/baz", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/bar/foo/baz", routingRule)).toBeFalsy();
+
+ routingRule = "/foo/bar*";
+ expect(isRoutingRuleMatch("/foo/bar", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/bar/", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/barfoo", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/bar/foo/barfoo", routingRule)).toBeFalsy();
+ expect(isRoutingRuleMatch("/foo/bar/baz", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/bar/foo/bar/baz", routingRule)).toBeFalsy();
+ });
+
+ it("should match rules without wildcards correctly", () => {
+ let routingRule = "/foo";
+
+ expect(isRoutingRuleMatch("/foo", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/bar", routingRule)).toBeFalsy();
+ expect(isRoutingRuleMatch("/bar/foo", routingRule)).toBeFalsy();
+
+ routingRule = "/foo/bar";
+ expect(isRoutingRuleMatch("/foo/bar", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/bar/", routingRule)).toBeTruthy();
+ expect(isRoutingRuleMatch("/foo/bar/baz", routingRule)).toBeFalsy();
+ expect(isRoutingRuleMatch("/baz/foo/bar", routingRule)).toBeFalsy();
+ });
+
+ it("should throw an error if pathname or routing rule params are missing", () => {
+ // MISSING PATHNAME
+ expect(() =>
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-ignore: sanity check
+ isRoutingRuleMatch(undefined, "/*")
+ ).toThrow("Pathname is undefined.");
+
+ expect(() =>
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-ignore: sanity check
+ isRoutingRuleMatch(null, "/*")
+ ).toThrow("Pathname is undefined.");
+
+ expect(() => isRoutingRuleMatch("", "/*")).toThrow(
+ "Pathname is undefined."
+ );
+
+ // MISSING ROUTING RULE
+ expect(() =>
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-ignore: sanity check
+ isRoutingRuleMatch("/foo", undefined)
+ ).toThrow("Routing rule is undefined.");
+
+ expect(() =>
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-ignore: sanity check
+ isRoutingRuleMatch("/foo", null)
+ ).toThrow("Routing rule is undefined.");
+
+ expect(() => isRoutingRuleMatch("/foo", "")).toThrow(
+ "Routing rule is undefined."
+ );
+ });
+});
diff --git a/node_modules/wrangler/templates/__tests__/tsconfig-sanity.ts b/node_modules/wrangler/templates/__tests__/tsconfig-sanity.ts
new file mode 100644
index 0000000..c9f2bcd
--- /dev/null
+++ b/node_modules/wrangler/templates/__tests__/tsconfig-sanity.ts
@@ -0,0 +1,12 @@
+// `@types/node` should be included
+Buffer.from("test");
+
+// `@types/jest` should be included
+test("test");
+
+// @ts-expect-error `@cloudflare/workers-types` should NOT be included
+const _handler: ExportedHandler = {};
+// @ts-expect-error `@cloudflare/workers-types` should NOT be included
+new HTMLRewriter();
+
+export {};
diff --git a/node_modules/wrangler/templates/__tests__/tsconfig.json b/node_modules/wrangler/templates/__tests__/tsconfig.json
new file mode 100644
index 0000000..683b6d2
--- /dev/null
+++ b/node_modules/wrangler/templates/__tests__/tsconfig.json
@@ -0,0 +1,8 @@
+{
+ "extends": "@cloudflare/workers-tsconfig/tsconfig.json",
+ "compilerOptions": {
+ "types": ["node", "jest"]
+ },
+ "include": ["**/*.ts"],
+ "exclude": []
+}