From 782baab92c4eb4996c3b5e821874a37d60f60dd9 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Fri, 29 May 2020 03:57:51 -0400 Subject: [PATCH] Speedup tests (#13461) This PR checks if our tests can be ran faster by disabling source maps unless they're used for the purpose of testing. --- packages/next/build/webpack-config.ts | 7 ++++++- packages/next/build/webpack/config/blocks/base.ts | 4 +++- test/acceptance/helpers.js | 4 +++- test/integration/basic/test/index.test.js | 4 +++- test/integration/client-navigation/test/index.test.js | 4 +++- test/integration/getserversideprops/test/index.test.js | 1 + test/integration/invalid-href/test/index.test.js | 4 +++- test/integration/prerender/test/index.test.js | 5 ++++- test/integration/typescript-hmr/test/index.test.js | 1 + test/integration/with-router/test/index.test.js | 4 +++- 10 files changed, 30 insertions(+), 8 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 33fb8fccb75965..e70eff4e4127c3 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -331,7 +331,12 @@ export default async function getBaseWebpackConfig( }, } - const devtool = dev ? 'cheap-module-source-map' : false + const devtool = + process.env.__NEXT_TEST_MODE && !process.env.__NEXT_TEST_WITH_DEVTOOL + ? false + : dev + ? 'cheap-module-source-map' + : false const isModuleCSS = (module: { type: string }): boolean => { return ( diff --git a/packages/next/build/webpack/config/blocks/base.ts b/packages/next/build/webpack/config/blocks/base.ts index 4c18de950f02b2..b55b901c677103 100644 --- a/packages/next/build/webpack/config/blocks/base.ts +++ b/packages/next/build/webpack/config/blocks/base.ts @@ -17,7 +17,9 @@ export const base = curry(function base( // https://webpack.js.org/configuration/devtool/#development if (ctx.isDevelopment) { - if (process.platform === 'win32') { + if (process.env.__NEXT_TEST_MODE && !process.env.__NEXT_TEST_WITH_DEVTOOL) { + config.devtool = false + } else if (process.platform === 'win32') { // Non-eval based source maps are slow to rebuild, so we only enable // them for Windows. Unfortunately, eval source maps are flagged as // suspicious by Windows Defender and block HMR. diff --git a/test/acceptance/helpers.js b/test/acceptance/helpers.js index b6bbb3a268f866..d4e56047c41a44 100644 --- a/test/acceptance/helpers.js +++ b/test/acceptance/helpers.js @@ -26,7 +26,9 @@ export async function sandbox(id = nanoid(), initialFiles = new Map()) { } const appPort = await findPort() - const app = await launchApp(sandboxDirectory, appPort) + const app = await launchApp(sandboxDirectory, appPort, { + env: { __NEXT_TEST_WITH_DEVTOOL: 1 }, + }) const browser = await webdriver(appPort, '/') return [ diff --git a/test/integration/basic/test/index.test.js b/test/integration/basic/test/index.test.js index ff8e8b1cbc73b4..e94c48e373f697 100644 --- a/test/integration/basic/test/index.test.js +++ b/test/integration/basic/test/index.test.js @@ -17,7 +17,9 @@ jest.setTimeout(1000 * 60 * 5) describe('Basic Features', () => { beforeAll(async () => { context.appPort = await findPort() - context.server = await launchApp(join(__dirname, '../'), context.appPort) + context.server = await launchApp(join(__dirname, '../'), context.appPort, { + env: { __NEXT_TEST_WITH_DEVTOOL: 1 }, + }) // pre-build all pages at the start await Promise.all([ diff --git a/test/integration/client-navigation/test/index.test.js b/test/integration/client-navigation/test/index.test.js index fce002f50759ac..3e7471b60ec7d7 100644 --- a/test/integration/client-navigation/test/index.test.js +++ b/test/integration/client-navigation/test/index.test.js @@ -21,7 +21,9 @@ jest.setTimeout(1000 * 60 * 5) describe('Client Navigation', () => { beforeAll(async () => { context.appPort = await findPort() - context.server = await launchApp(join(__dirname, '../'), context.appPort) + context.server = await launchApp(join(__dirname, '../'), context.appPort, { + env: { __NEXT_TEST_WITH_DEVTOOL: 1 }, + }) const prerender = [ '/async-props', diff --git a/test/integration/getserversideprops/test/index.test.js b/test/integration/getserversideprops/test/index.test.js index 6b452b2dad3573..52fdbae52e5d12 100644 --- a/test/integration/getserversideprops/test/index.test.js +++ b/test/integration/getserversideprops/test/index.test.js @@ -564,6 +564,7 @@ describe('getServerSideProps', () => { stderr = '' appPort = await findPort() app = await launchApp(appDir, appPort, { + env: { __NEXT_TEST_WITH_DEVTOOL: 1 }, onStderr(msg) { stderr += msg }, diff --git a/test/integration/invalid-href/test/index.test.js b/test/integration/invalid-href/test/index.test.js index 35e8589f8db3a3..8aa1b65e481756 100644 --- a/test/integration/invalid-href/test/index.test.js +++ b/test/integration/invalid-href/test/index.test.js @@ -90,7 +90,9 @@ describe('Invalid hrefs', () => { describe('dev mode', () => { beforeAll(async () => { appPort = await findPort() - app = await launchApp(appDir, appPort) + app = await launchApp(appDir, appPort, { + env: { __NEXT_TEST_WITH_DEVTOOL: 1 }, + }) }) afterAll(() => killApp(app)) diff --git a/test/integration/prerender/test/index.test.js b/test/integration/prerender/test/index.test.js index 847a488c418591..819bae4aadeaea 100644 --- a/test/integration/prerender/test/index.test.js +++ b/test/integration/prerender/test/index.test.js @@ -1062,6 +1062,7 @@ describe('SSG Prerender', () => { ) appPort = await findPort() app = await launchApp(appDir, appPort, { + env: { __NEXT_TEST_WITH_DEVTOOL: 1 }, onStderr: (msg) => { stderr += msg }, @@ -1084,7 +1085,9 @@ describe('SSG Prerender', () => { ) await fs.remove(join(appDir, '.next')) appPort = await findPort() - app = await launchApp(appDir, appPort) + app = await launchApp(appDir, appPort, { + env: { __NEXT_TEST_WITH_DEVTOOL: 1 }, + }) }) afterAll(async () => { await fs.remove(nextConfig) diff --git a/test/integration/typescript-hmr/test/index.test.js b/test/integration/typescript-hmr/test/index.test.js index 488a103fbe10e0..953d5a606b73af 100644 --- a/test/integration/typescript-hmr/test/index.test.js +++ b/test/integration/typescript-hmr/test/index.test.js @@ -22,6 +22,7 @@ describe('TypeScript HMR', () => { appPort = await findPort() app = await launchApp(appDir, appPort, { env: { + __NEXT_TEST_WITH_DEVTOOL: 1, // Events can be finicky in CI. This switches to a more reliable // polling method. CHOKIDAR_USEPOLLING: 'true', diff --git a/test/integration/with-router/test/index.test.js b/test/integration/with-router/test/index.test.js index e23e37f3f2cd82..ebd4375a42c328 100644 --- a/test/integration/with-router/test/index.test.js +++ b/test/integration/with-router/test/index.test.js @@ -97,7 +97,9 @@ describe('withRouter SSR', () => { beforeAll(async () => { port = await findPort() - server = await launchApp(join(__dirname, '..'), port) + server = await launchApp(join(__dirname, '..'), port, { + env: { __NEXT_TEST_WITH_DEVTOOL: 1 }, + }) }) afterAll(async () => { await killApp(server)