| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,10 @@ |
| +'use server' |
| + |
| +import _ from 'lodash' |
| +import Queue from 'yocto-queue' |
| + |
| +export async function doStuff() { |
| + const queue = new Queue<string>() |
| + queue.enqueue(_.camelCase('hello world')) |
| + return queue.dequeue() ?? '' |
| +} |
| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,14 @@ |
| +'use client' |
| + |
| +import { useState } from 'react' |
| +import { doStuff } from './actions' |
| + |
| +export function Button() { |
| + const [result, setResult] = useState('') |
| + return ( |
| + <> |
| + <button onClick={async () => setResult(await doStuff())}>go</button> |
| + <p id="result">{result}</p> |
| + </> |
| + ) |
| +} |
| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,8 @@ |
| +import { ReactNode } from 'react' |
| +export default function Root({ children }: { children: ReactNode }) { |
| + return ( |
| + <html> |
| + <body>{children}</body> |
| + </html> |
| + ) |
| +} |
| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,5 @@ |
| +import { Button } from './button' |
| + |
| +export default function Page() { |
| + return <Button /> |
| +} |
| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,9 @@ |
| +/** |
| + * @type {import('next').NextConfig} |
| + */ |
| +const nextConfig = { |
| + output: 'standalone', |
| + serverExternalPackages: ['lodash', 'yocto-queue'], |
| +} |
| + |
| +module.exports = nextConfig |
| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,7 @@ |
| +{ |
| + "dependencies": { |
| + "@types/lodash": "4.17.13", |
| + "lodash": "4.17.21", |
| + "yocto-queue": "1.2.1" |
| + } |
| +} |
| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,64 @@ |
| +import { ChildProcess } from 'child_process' |
| +import { nextTestSetup } from 'e2e-utils' |
| +import fs from 'fs-extra' |
| +import { findPort, initNextServerScript, killApp, retry } from 'next-test-utils' |
| +import { join } from 'path' |
| + |
| +// The external packages are only imported by a server action, so the |
| +// standalone output only contains them if the route's trace includes them. |
| +describe('standalone mode: server action externals', () => { |
| + let server: ChildProcess |
| + let appPort: number |
| + |
| + const { next } = nextTestSetup({ |
| + files: __dirname, |
| + dependencies: require('./package.json').dependencies, |
| + skipStart: true, |
| + }) |
| + |
| + beforeAll(async () => { |
| + await next.build() |
| + |
| + await fs.move( |
| + join(next.testDir, '.next/standalone'), |
| + join(next.testDir, 'standalone') |
| + ) |
| + |
| + await fs.copy( |
| + join(next.testDir, '.next/static'), |
| + join(next.testDir, 'standalone/.next/static') |
| + ) |
| + |
| + // Remove everything else (including node_modules) so that the server can |
| + // only load what the file traces brought into the standalone output. |
| + for (const file of await fs.readdir(next.testDir)) { |
| + if (file !== 'standalone') { |
| + await fs.remove(join(next.testDir, file)) |
| + } |
| + } |
| + |
| + const testServer = join(next.testDir, 'standalone/server.js') |
| + appPort = await findPort() |
| + server = await initNextServerScript(testServer, /- Local:/, { |
| + ...process.env, |
| + ...next.env, |
| + HOSTNAME: '::', |
| + PORT: '' + appPort, |
| + }) |
| + }) |
| + |
| + afterAll(async () => { |
| + if (server) { |
| + await killApp(server) |
| + } |
| + }) |
| + |
| + it('should execute a server action that uses external packages', async () => { |
| + const browser = await next.browser('/', { baseUrl: appPort }) |
| + await browser.elementByCss('button').click() |
| + |
| + await retry(async () => { |
| + expect(await browser.elementByCss('#result').text()).toBe('helloWorld') |
| + }) |
| + }) |
| +}) |
|
|