Open History to see the last commit
1import { afterAll, beforeAll, expect, test, vi } from 'vitest'
2import { analyzeModule, cloneModuleAst, generateModule } from '../src'
3β
4vi.mock('yuku-core', async (importOriginal) => ({
5 ...(await importOriginal<typeof import('yuku-core')>()),
6 load: () => {
7 throw new Error('WebContainers cannot load native addons')
8 },
9}))
10β
11beforeAll(() => {
12 process.versions.webcontainer = '1.0.0'
13})
14β
15afterAll(() => {
16 delete process.versions.webcontainer
17})
18β
19test('analyzes and prints modules with the WebAssembly core in WebContainers', () => {
20 const code = `import { lazy } from 'react'
21const Page = lazy(() => import('./page'))
22export const render = (props: { id: string }) => <Page id={props.id} />
23`
24 const module = analyzeModule({ code, filename: 'route.tsx' })
25 expect(module.rootScope.find('Page')!.references).toHaveLength(1)
26 expect(module.rootScope.find('lazy')!.references).toHaveLength(1)
27 expect(generateModule(cloneModuleAst(module).program).code)
28 .toMatchInlineSnapshot(`
29 "import { lazy } from 'react';
30 const Page = lazy(() => import('./page'));
31 export const render = (props: {
32 id: string;
33 }) => <Page id={props.id} />;"
34 `)
35})