Skip to content

Commit cd6837c

Browse files
authored
test(kit): add regression test for the posixied instrumentation file (#15023)
* test(kit): add regression test for the posixied instrumentation file Closes #15022. * test(kit): prefer paths relative to `__dirname`
1 parent 08a153b commit cd6837c

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

packages/kit/src/core/adapt/builder.spec.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync, rmSync } from 'node:fs';
1+
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
22
import { join, dirname } from 'node:path';
33
import { fileURLToPath } from 'node:url';
44
import { assert, expect, test } from 'vitest';
@@ -72,3 +72,40 @@ test('compress files', async () => {
7272
assert.ok(existsSync(target + '.br'));
7373
assert.ok(existsSync(target + '.gz'));
7474
});
75+
76+
test('instrument generates facade with posix paths', () => {
77+
const fixtureDir = join(__dirname, 'fixtures/instrument');
78+
const dest = join(__dirname, 'output');
79+
80+
rmSync(dest, { recursive: true, force: true });
81+
mkdirSync(join(dest, 'server'), { recursive: true });
82+
copyFileSync(join(fixtureDir, 'index.js'), join(dest, 'index.js'));
83+
copyFileSync(
84+
join(fixtureDir, 'server/instrumentation.server.js'),
85+
join(dest, 'server/instrumentation.server.js')
86+
);
87+
88+
const entrypoint = join(dest, 'index.js');
89+
const instrumentation = join(dest, 'server', 'instrumentation.server.js');
90+
91+
// @ts-expect-error - we don't need the whole config for this test
92+
const builder = create_builder({ route_data: [] });
93+
94+
builder.instrument({
95+
entrypoint,
96+
instrumentation,
97+
module: { exports: ['default'] }
98+
});
99+
100+
// Read the generated facade
101+
const facade = readFileSync(entrypoint, 'utf-8');
102+
103+
// Verify it uses forward slashes (not backslashes)
104+
// On Windows, path.relative() returns 'server\instrumentation.server.js'
105+
// The fix ensures this becomes 'server/instrumentation.server.js'
106+
expect(facade).toContain("import './server/instrumentation.server.js'");
107+
expect(facade).not.toContain('\\');
108+
109+
// Cleanup
110+
rmSync(dest, { recursive: true, force: true });
111+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

0 commit comments

Comments
 (0)