diff --git a/packages/next/bin/next.ts b/packages/next/bin/next.ts index 515d04ba..2f193124 100755 --- a/packages/next/bin/next.ts +++ b/packages/next/bin/next.ts @@ -42,7 +42,7 @@ if (args['--version']) { } // Check if we are running `next ` or `next` -const foundCommand = args._.find((cmd) => commands.includes(cmd)) +const foundCommand = commands.includes(args._[0]) // Makes sure the `next --help` case is covered // This help message is only showed for `next --help` @@ -73,8 +73,8 @@ if (args['--inspect']) { nodeArguments.push('--inspect') } -const command = foundCommand || defaultCommand -const forwardedArgs = args._.filter((arg) => arg !== command) +const command = foundCommand ? args._[0] : defaultCommand +const forwardedArgs = foundCommand ? args._.slice(1) : args._ // Make sure the `next --help` case is covered if (args['--help']) { diff --git a/test/integration/production-build-dir/build/pages/index.js b/test/integration/production-build-dir/build/pages/index.js new file mode 100644 index 00000000..02d90896 --- /dev/null +++ b/test/integration/production-build-dir/build/pages/index.js @@ -0,0 +1 @@ +export default () =>
Hello World
diff --git a/test/integration/production-build-dir/test/index.test.js b/test/integration/production-build-dir/test/index.test.js new file mode 100644 index 00000000..65cd5a0d --- /dev/null +++ b/test/integration/production-build-dir/test/index.test.js @@ -0,0 +1,69 @@ +/* eslint-env jest */ +/* global jasmine */ +import { dirname, join } from 'path' +import { + nextServer, + startApp, + stopApp, + renderViaHTTP +} from 'next-test-utils' +import spawn from 'cross-spawn' + +jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 + +function runNextCommand (argv, options = {}) { + return new Promise((resolve, reject) => { + console.log(`Running command "next ${argv.join(' ')}"`) + const instance = spawn('node', [join(dirname(require.resolve('next/package')), 'dist/bin/next'), ...argv], { ...options.spawnOptions, cwd: join(__dirname, '..'), stdio: ['ignore', 'pipe', 'pipe'] }) + + let stderrOutput = '' + if (options.stderr) { + instance.stderr.on('data', function (chunk) { + stderrOutput += chunk + }) + } + + let stdoutOutput = '' + if (options.stdout) { + instance.stdout.on('data', function (chunk) { + stdoutOutput += chunk + }) + } + + instance.on('close', () => { + resolve({ + stdout: stdoutOutput, + stderr: stderrOutput + }) + }) + + instance.on('error', (err) => { + err.stdout = stdoutOutput + err.stderr = stderrOutput + reject(err) + }) + }) +} + +describe('Production Custom Build Directory', () => { + describe('With basic usage', () => { + it('should render the page', async () => { + const result = await runNextCommand(['build', 'build'], {stdout: true, stderr: true}) + expect(result.stderr).toBe('') + + const app = nextServer({ + dir: join(__dirname, '../build'), + dev: false, + quiet: true + }) + + const server = await startApp(app) + const appPort = server.address().port + + const html = await renderViaHTTP(appPort, '/') + expect(html).toMatch(/Hello World/) + + await stopApp(server) + }) + }) +})