403Webshell
Server IP : 159.203.156.69  /  Your IP : 216.73.217.172
Web Server : nginx/1.24.0
System : Linux main-ubuntu 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/tanviranik.com/node_modules/wrangler/templates/__tests__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/tanviranik.com/node_modules/wrangler/templates/__tests__/pages-dev-util.test.ts
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."
		);
	});
});

Youez - 2016 - github.com/yon3zu
LinuXploit