From 28fe233f2f7321c6213c5c18a3e425f29205b4d8 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Tue, 11 Feb 2020 16:50:06 -0500 Subject: [PATCH] Builds with Warnings Still Complete --- packages/next/build/index.ts | 13 +++++++----- test/integration/telemetry/pages/warning.skip | 8 ++++++++ test/integration/telemetry/test/index.test.js | 20 +++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 test/integration/telemetry/pages/warning.skip diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index 94ce85aed4ac79d..ad776ecfd2562ef 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -388,17 +388,20 @@ export default async function build(dir: string, conf = null): Promise { ) } throw new Error('> Build failed because of webpack errors') - } else if (result.warnings.length > 0) { - console.warn(chalk.yellow('Compiled with warnings.\n')) - console.warn(result.warnings.join('\n\n')) - console.warn() } else { - console.log(chalk.green('Compiled successfully.\n')) telemetry.record( eventBuildCompleted(pagePaths, { durationInSeconds: webpackBuildEnd[0], }) ) + + if (result.warnings.length > 0) { + console.warn(chalk.yellow('Compiled with warnings.\n')) + console.warn(result.warnings.join('\n\n')) + console.warn() + } else { + console.log(chalk.green('Compiled successfully.\n')) + } } const postBuildSpinner = createSpinner({ prefixText: 'Automatically optimizing pages', diff --git a/test/integration/telemetry/pages/warning.skip b/test/integration/telemetry/pages/warning.skip new file mode 100644 index 000000000000000..a6635f17304391b --- /dev/null +++ b/test/integration/telemetry/pages/warning.skip @@ -0,0 +1,8 @@ +function a(v) { + return v +} +;['index.js'].forEach(f => { + require(a('./' + f)) +}) + +export default () => 'Warn' diff --git a/test/integration/telemetry/test/index.test.js b/test/integration/telemetry/test/index.test.js index 51ccb25fa1c0578..7b2a9e4c7b42a7c 100644 --- a/test/integration/telemetry/test/index.test.js +++ b/test/integration/telemetry/test/index.test.js @@ -93,6 +93,26 @@ describe('Telemetry CLI', () => { expect(stderr2).toMatch(/isSrcDir.*?true/) }) + it('logs completed `next build` with warnings', async () => { + await fs.rename( + path.join(appDir, 'pages', 'warning.skip'), + path.join(appDir, 'pages', 'warning.js') + ) + const { stderr } = await runNextCommand(['build', appDir], { + stderr: true, + env: { + NEXT_TELEMETRY_DEBUG: 1, + }, + }) + await fs.rename( + path.join(appDir, 'pages', 'warning.js'), + path.join(appDir, 'pages', 'warning.skip') + ) + + expect(stderr).toMatch(/Compiled with warnings/) + expect(stderr).toMatch(/NEXT_BUILD_COMPLETED/) + }) + it('detects tests correctly for `next build`', async () => { await fs.rename( path.join(appDir, 'pages', 'hello.test.skip'),