avyvar's picture
Add files using upload-large-folder tool
b2cad4f verified
Raw
History Blame Contribute Delete
5.35 kB
diff --git a/test/production/standalone-mode/server-action-externals/app/actions.ts b/test/production/standalone-mode/server-action-externals/app/actions.ts
new file mode 100644
index 0000000000..d7e81ac580
--- /dev/null
+++ b/test/production/standalone-mode/server-action-externals/app/actions.ts
@@ -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() ?? ''
+}
diff --git a/test/production/standalone-mode/server-action-externals/app/button.tsx b/test/production/standalone-mode/server-action-externals/app/button.tsx
new file mode 100644
index 0000000000..c45a38d655
--- /dev/null
+++ b/test/production/standalone-mode/server-action-externals/app/button.tsx
@@ -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>
+ </>
+ )
+}
diff --git a/test/production/standalone-mode/server-action-externals/app/layout.tsx b/test/production/standalone-mode/server-action-externals/app/layout.tsx
new file mode 100644
index 0000000000..888614deda
--- /dev/null
+++ b/test/production/standalone-mode/server-action-externals/app/layout.tsx
@@ -0,0 +1,8 @@
+import { ReactNode } from 'react'
+export default function Root({ children }: { children: ReactNode }) {
+ return (
+ <html>
+ <body>{children}</body>
+ </html>
+ )
+}
diff --git a/test/production/standalone-mode/server-action-externals/app/page.tsx b/test/production/standalone-mode/server-action-externals/app/page.tsx
new file mode 100644
index 0000000000..24c9d8de35
--- /dev/null
+++ b/test/production/standalone-mode/server-action-externals/app/page.tsx
@@ -0,0 +1,5 @@
+import { Button } from './button'
+
+export default function Page() {
+ return <Button />
+}
diff --git a/test/production/standalone-mode/server-action-externals/next.config.js b/test/production/standalone-mode/server-action-externals/next.config.js
new file mode 100644
index 0000000000..e362786ab0
--- /dev/null
+++ b/test/production/standalone-mode/server-action-externals/next.config.js
@@ -0,0 +1,9 @@
+/**
+ * @type {import('next').NextConfig}
+ */
+const nextConfig = {
+ output: 'standalone',
+ serverExternalPackages: ['lodash', 'yocto-queue'],
+}
+
+module.exports = nextConfig
diff --git a/test/production/standalone-mode/server-action-externals/package.json b/test/production/standalone-mode/server-action-externals/package.json
new file mode 100644
index 0000000000..6f0860051d
--- /dev/null
+++ b/test/production/standalone-mode/server-action-externals/package.json
@@ -0,0 +1,7 @@
+{
+ "dependencies": {
+ "@types/lodash": "4.17.13",
+ "lodash": "4.17.21",
+ "yocto-queue": "1.2.1"
+ }
+}
diff --git a/test/production/standalone-mode/server-action-externals/standalone-mode-server-action-externals.test.ts b/test/production/standalone-mode/server-action-externals/standalone-mode-server-action-externals.test.ts
new file mode 100644
index 0000000000..c146365258
--- /dev/null
+++ b/test/production/standalone-mode/server-action-externals/standalone-mode-server-action-externals.test.ts
@@ -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')
+ })
+ })
+})