From 5dda1f1c0ca1f3e8b6eb60d5224cb2f6bc550689 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 6 Mar 2020 12:15:53 -0600 Subject: [PATCH] Test child_process with API route --- test/integration/api-support/pages/api/child-process.js | 8 ++++++++ test/integration/api-support/test/index.test.js | 5 +++++ 2 files changed, 13 insertions(+) create mode 100644 test/integration/api-support/pages/api/child-process.js diff --git a/test/integration/api-support/pages/api/child-process.js b/test/integration/api-support/pages/api/child-process.js new file mode 100644 index 000000000000..864a16a19956 --- /dev/null +++ b/test/integration/api-support/pages/api/child-process.js @@ -0,0 +1,8 @@ +import { execSync } from 'child_process' + +export default (req, res) => { + const output = execSync('echo "hi"') + .toString() + .trim() + res.end(output) +} diff --git a/test/integration/api-support/test/index.test.js b/test/integration/api-support/test/index.test.js index c4e5c7d389b3..669728eee616 100644 --- a/test/integration/api-support/test/index.test.js +++ b/test/integration/api-support/test/index.test.js @@ -322,6 +322,11 @@ function runTests(dev = false) { expect(data).toEqual({ post: 'post-1', id: '1' }) }) + it('should work with child_process correctly', async () => { + const data = await renderViaHTTP(appPort, '/api/child-process') + expect(data).toBe('hi') + }) + if (dev) { it('should compile only server code in development', async () => { await fetchViaHTTP(appPort, '/')