From e24730516796eb41f657e6f17bf67c087e7eb0c2 Mon Sep 17 00:00:00 2001 From: ocavue Date: Mon, 20 Apr 2026 21:11:54 +1000 Subject: [PATCH] refactor(internal-helpers): migrate tests to typescript --- packages/internal-helpers/package.json | 3 ++- .../{create-filter.test.js => create-filter.test.ts} | 0 .../test/{path.test.js => path.test.ts} | 5 ++++- .../test/{request.test.js => request.test.ts} | 2 +- packages/internal-helpers/tsconfig.test.json | 12 ++++++++++++ 5 files changed, 19 insertions(+), 3 deletions(-) rename packages/internal-helpers/test/{create-filter.test.js => create-filter.test.ts} (100%) rename packages/internal-helpers/test/{path.test.js => path.test.ts} (99%) rename packages/internal-helpers/test/{request.test.js => request.test.ts} (99%) create mode 100644 packages/internal-helpers/tsconfig.test.json diff --git a/packages/internal-helpers/package.json b/packages/internal-helpers/package.json index 018b9d44cafc..feadc3dd8610 100644 --- a/packages/internal-helpers/package.json +++ b/packages/internal-helpers/package.json @@ -46,7 +46,8 @@ "build": "astro-scripts build \"src/**/*.ts\" && tsc -p tsconfig.json", "build:ci": "astro-scripts build \"src/**/*.ts\"", "dev": "astro-scripts dev \"src/**/*.ts\"", - "test": "astro-scripts test \"test/**/*.test.js\"" + "test": "astro-scripts test \"test/**/*.test.ts\"", + "typecheck:tests": "tsc -p tsconfig.test.json --noEmit" }, "dependencies": { "picomatch": "^4.0.3" diff --git a/packages/internal-helpers/test/create-filter.test.js b/packages/internal-helpers/test/create-filter.test.ts similarity index 100% rename from packages/internal-helpers/test/create-filter.test.js rename to packages/internal-helpers/test/create-filter.test.ts diff --git a/packages/internal-helpers/test/path.test.js b/packages/internal-helpers/test/path.test.ts similarity index 99% rename from packages/internal-helpers/test/path.test.js rename to packages/internal-helpers/test/path.test.ts index c4359f05a5fd..2981450c08b6 100644 --- a/packages/internal-helpers/test/path.test.js +++ b/packages/internal-helpers/test/path.test.ts @@ -652,7 +652,7 @@ describe('isParentDirectory', () => { }); it('should correctly reject non-parent relationships', () => { - const invalidCases = [ + const invalidCases: Array<[string, string]> = [ // Different directories ['/home', '/usr'], ['/home/user', '/home/otheruser'], @@ -681,8 +681,11 @@ describe('isParentDirectory', () => { ['', '/home'], ['/home', ''], ['', ''], + // @ts-expect-error: expected to handle null/undefined gracefully [null, '/home'], + // @ts-expect-error: expected to handle null/undefined gracefully ['/home', null], + // @ts-expect-error: expected to handle null/undefined gracefully [undefined, '/home'], // Same path (not parent-child) diff --git a/packages/internal-helpers/test/request.test.js b/packages/internal-helpers/test/request.test.ts similarity index 99% rename from packages/internal-helpers/test/request.test.js rename to packages/internal-helpers/test/request.test.ts index 8741dbdddb62..2029367af9b9 100644 --- a/packages/internal-helpers/test/request.test.js +++ b/packages/internal-helpers/test/request.test.ts @@ -137,7 +137,7 @@ describe('getClientIpAddress', () => { /** * Helper to create a minimal Request with given headers. */ - function makeRequest(headers = {}) { + function makeRequest(headers: HeadersInit = {}) { return new Request('https://example.com', { headers }); } diff --git a/packages/internal-helpers/tsconfig.test.json b/packages/internal-helpers/tsconfig.test.json new file mode 100644 index 000000000000..7d6bc4428b35 --- /dev/null +++ b/packages/internal-helpers/tsconfig.test.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["test/**/*.ts"], + "exclude": ["test/fixtures/**"], + "compilerOptions": { + "allowJs": true, + "noUnusedLocals": false, + "noUnusedParameters": false, + "rewriteRelativeImportExtensions": true + }, + "references": [{ "path": "../astro/tsconfig.test.json" }] +}