rsnext/test/production/app-dir-edge-runtime-with-wasm/index.test.ts
Bryce Kalow d159fb08a1
fix: usage of wasm in an appDir page file using the edge runtime (#41689)
Fixes #41673

Updates the wasm `AssetBinding` filePath to be the fully qualified path during build so the files can get loaded.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-11-03 01:18:03 +00:00

63 lines
1.4 KiB
TypeScript

import path from 'path'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
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 = "experimental-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,
dependencies: {
react: 'experimental',
'react-dom': 'experimental',
},
nextConfig: {
experimental: {
appDir: true,
},
},
})
})
afterAll(() => next.destroy())
it('should have built', async () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('1 + 1 is: 2')
})
})