|
| 1 | +// @vitest-environment jsdom |
| 2 | + |
1 | 3 | import { mkdtempSync, mkdirSync, realpathSync, rmSync, writeFileSync } from 'node:fs'; |
2 | 4 | import { tmpdir } from 'node:os'; |
3 | 5 | import { dirname, join } from 'node:path'; |
@@ -416,12 +418,29 @@ describe('loader with the neutral compiler', () => { |
416 | 418 | const source = |
417 | 419 | "import { createRoot } from 'octane';\n" + |
418 | 420 | "import Main from './Main.tsrx';\n" + |
419 | | - 'createRoot(document.body).render(Main);\n'; |
| 421 | + 'export function mount(container) {\n' + |
| 422 | + '\tconst root = createRoot(container);\n' + |
| 423 | + '\troot.render(Main);\n' + |
| 424 | + '\treturn () => root.unmount();\n' + |
| 425 | + '}\n'; |
420 | 426 | const resourcePath = write(root, 'src/main.js', source); |
421 | 427 | const result = transform({ root, resourcePath, source, mode: 'production' }); |
422 | 428 |
|
423 | | - expect(result.content).toBe(source); |
424 | 429 | expect(result.dependencies).not.toContain(join(root, 'src/Main.tsrx')); |
| 430 | + // A later loader can replace the disk component with one that returns a value. |
| 431 | + const generated = evaluateCompiledFixtureCode<{ |
| 432 | + mount(container: HTMLElement): () => void; |
| 433 | + }>(String(result.content), resourcePath, 'client', { |
| 434 | + './Main.tsrx': { default: () => 'replacement value' }, |
| 435 | + }); |
| 436 | + const container = document.createElement('div'); |
| 437 | + const unmount = generated.mount(container); |
| 438 | + try { |
| 439 | + expect(container.textContent).toBe('replacement value'); |
| 440 | + } finally { |
| 441 | + unmount(); |
| 442 | + } |
| 443 | + expect(container.childNodes).toHaveLength(0); |
425 | 444 | }); |
426 | 445 |
|
427 | 446 | it('keeps production watch builds syntax-only and out of the persistent module cache', () => { |
|
0 commit comments