|
| 1 | +import { describe, expect, it, vi } from 'vitest'; |
| 2 | +import { angularVitestPlugin } from './angular-vitest-plugin'; |
| 3 | + |
| 4 | +// Exercise the Vite 6/7 fallback while the workspace itself uses Vite 8. |
| 5 | +vi.mock(import('./utils/rolldown.js'), () => ({ |
| 6 | + getJsTransformConfigKey: () => 'esbuild', |
| 7 | + isRolldown: () => false, |
| 8 | +})); |
| 9 | + |
| 10 | +const transform = (code: string, id: string) => { |
| 11 | + const hook = angularVitestPlugin().transform as { |
| 12 | + handler: (code: string, id: string) => Promise<{ code: string }>; |
| 13 | + }; |
| 14 | + return hook.handler(code, id); |
| 15 | +}; |
| 16 | + |
| 17 | +describe('angularVitestPlugin esbuild downleveling', () => { |
| 18 | + it('preserves HMR access in generated CDK CSS modules', async () => { |
| 19 | + const { code } = await transform( |
| 20 | + 'export const id = "/node_modules/@angular/cdk/overlay-prebuilt.css"; import.meta.hot.accept();', |
| 21 | + '/node_modules/@angular/cdk/overlay-prebuilt.css', |
| 22 | + ); |
| 23 | + |
| 24 | + expect(code).toContain('import.meta.hot.accept()'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('preserves module metadata while downleveling async functions', async () => { |
| 28 | + const { code } = await transform( |
| 29 | + 'export const url = import.meta.url; export async function example() { return await Promise.resolve(42); }', |
| 30 | + '/node_modules/@angular/core/fesm2022/core.mjs', |
| 31 | + ); |
| 32 | + const moduleUrl = `data:text/javascript;base64,${Buffer.from(code).toString('base64')}`; |
| 33 | + const result = await import(moduleUrl); |
| 34 | + |
| 35 | + expect(result.url).toBe(moduleUrl); |
| 36 | + expect(await result.example()).toBe(42); |
| 37 | + expect(code).not.toMatch(/\basync\s+function\b/); |
| 38 | + }); |
| 39 | +}); |
0 commit comments