Skip to content

Commit b2f636d

Browse files
committed
test: verify unresolved loader roots preserve returned values
1 parent 819e157 commit b2f636d

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

‎packages/rspack-plugin-octane/tests/loader.integration.test.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @vitest-environment jsdom
2+
13
import { mkdtempSync, mkdirSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
24
import { tmpdir } from 'node:os';
35
import { dirname, join } from 'node:path';
@@ -416,12 +418,29 @@ describe('loader with the neutral compiler', () => {
416418
const source =
417419
"import { createRoot } from 'octane';\n" +
418420
"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';
420426
const resourcePath = write(root, 'src/main.js', source);
421427
const result = transform({ root, resourcePath, source, mode: 'production' });
422428

423-
expect(result.content).toBe(source);
424429
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);
425444
});
426445

427446
it('keeps production watch builds syntax-only and out of the persistent module cache', () => {

0 commit comments

Comments
 (0)