Skip to content

Commit

Permalink
Speedup tests (vercel#13461)
Browse files Browse the repository at this point in the history
This PR checks if our tests can be ran faster by disabling source maps unless they're used for the purpose of testing.
  • Loading branch information
Timer authored and rokinsky committed Jul 11, 2020
1 parent d3011da commit 782baab
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 8 deletions.
7 changes: 6 additions & 1 deletion packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 3 additions & 1 deletion packages/next/build/webpack/config/blocks/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion test/acceptance/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
4 changes: 3 additions & 1 deletion test/integration/basic/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
4 changes: 3 additions & 1 deletion test/integration/client-navigation/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions test/integration/getserversideprops/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
4 changes: 3 additions & 1 deletion test/integration/invalid-href/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
5 changes: 4 additions & 1 deletion test/integration/prerender/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/integration/typescript-hmr/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion test/integration/with-router/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 782baab

Please sign in to comment.