File size: 1,248 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import path from 'path'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'e2e-utils'
import { renderViaHTTP } from 'next-test-utils'

const files = {
  'app/layout.jsx': `
    export default function AppLayout({ children }) {
      return (
        <html>
          <head>
            <title>WASM Import</title>
          </head>
          <body>
            {children}
          </body>
        </html>
      )
    }
  `,
  'app/page.jsx': `
    import wasm from '../wasm/add.wasm?module'
    const instance$ = WebAssembly.instantiate(wasm);

    async function addOne(a) {
      const { exports } = await instance$;
      return exports.add_one(a);
    }

    export default async function Page() {
      const two = await addOne(1)
      return \`1 + 1 is: $\{two}\`
    }

    export const runtime = "edge"
  `,
  'wasm/add.wasm': new FileRef(path.join(__dirname, 'add.wasm')),
}

describe('app-dir edge runtime with wasm', () => {
  let next: NextInstance

  beforeAll(async () => {
    next = await createNext({
      files,
    })
  })
  afterAll(() => next?.destroy())

  it('should have built', async () => {
    const html = await renderViaHTTP(next.url, '/')
    expect(html).toContain('1 + 1 is: 2')
  })
})