test(kit): add regression test for the posixied instrumentation file (#15023)
authorBasti Ortiz <ortiz@bastidood.dev>
Thu, 4 Dec 2025 21:22:48 +0000 (05:22 +0800)
committerGitHub <noreply@github.com>
Thu, 4 Dec 2025 21:22:48 +0000 (14:22 -0700)
* test(kit): add regression test for the posixied instrumentation file

Closes #15022.

* test(kit): prefer paths relative to `__dirname`

packages/kit/src/core/adapt/builder.spec.js
packages/kit/src/core/adapt/fixtures/instrument/index.js [new file with mode: 0644]
packages/kit/src/core/adapt/fixtures/instrument/server/instrumentation.server.js [new file with mode: 0644]

index d61fe4c708602afc35479ac1ee51656c77f31dd9..b69c7b8296bb2af71040d3f3c4a8b80e385d2447 100644 (file)
@@ -1,4 +1,4 @@
-import { existsSync, rmSync } from 'node:fs';
+import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
 import { join, dirname } from 'node:path';
 import { fileURLToPath } from 'node:url';
 import { assert, expect, test } from 'vitest';
@@ -72,3 +72,40 @@ test('compress files', async () => {
        assert.ok(existsSync(target + '.br'));
        assert.ok(existsSync(target + '.gz'));
 });
+
+test('instrument generates facade with posix paths', () => {
+       const fixtureDir = join(__dirname, 'fixtures/instrument');
+       const dest = join(__dirname, 'output');
+
+       rmSync(dest, { recursive: true, force: true });
+       mkdirSync(join(dest, 'server'), { recursive: true });
+       copyFileSync(join(fixtureDir, 'index.js'), join(dest, 'index.js'));
+       copyFileSync(
+               join(fixtureDir, 'server/instrumentation.server.js'),
+               join(dest, 'server/instrumentation.server.js')
+       );
+
+       const entrypoint = join(dest, 'index.js');
+       const instrumentation = join(dest, 'server', 'instrumentation.server.js');
+
+       // @ts-expect-error - we don't need the whole config for this test
+       const builder = create_builder({ route_data: [] });
+
+       builder.instrument({
+               entrypoint,
+               instrumentation,
+               module: { exports: ['default'] }
+       });
+
+       // Read the generated facade
+       const facade = readFileSync(entrypoint, 'utf-8');
+
+       // Verify it uses forward slashes (not backslashes)
+       // On Windows, path.relative() returns 'server\instrumentation.server.js'
+       // The fix ensures this becomes 'server/instrumentation.server.js'
+       expect(facade).toContain("import './server/instrumentation.server.js'");
+       expect(facade).not.toContain('\\');
+
+       // Cleanup
+       rmSync(dest, { recursive: true, force: true });
+});
diff --git a/packages/kit/src/core/adapt/fixtures/instrument/index.js b/packages/kit/src/core/adapt/fixtures/instrument/index.js
new file mode 100644 (file)
index 0000000..ff8b4c5
--- /dev/null
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/kit/src/core/adapt/fixtures/instrument/server/instrumentation.server.js b/packages/kit/src/core/adapt/fixtures/instrument/server/instrumentation.server.js
new file mode 100644 (file)
index 0000000..cb0ff5c
--- /dev/null
@@ -0,0 +1 @@
+export {};