|
1 | | -import { existsSync, rmSync } from 'node:fs'; |
| 1 | +import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs'; |
2 | 2 | import { join, dirname } from 'node:path'; |
3 | 3 | import { fileURLToPath } from 'node:url'; |
4 | 4 | import { assert, expect, test } from 'vitest'; |
@@ -72,3 +72,40 @@ test('compress files', async () => { |
72 | 72 | assert.ok(existsSync(target + '.br')); |
73 | 73 | assert.ok(existsSync(target + '.gz')); |
74 | 74 | }); |
| 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 | +}); |
0 commit comments