Unverified Commit 30fbd9ad authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

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.
parent a62aaddd
...@@ -331,7 +331,12 @@ export default async function getBaseWebpackConfig( ...@@ -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 => { const isModuleCSS = (module: { type: string }): boolean => {
return ( return (
......
...@@ -17,7 +17,9 @@ export const base = curry(function base( ...@@ -17,7 +17,9 @@ export const base = curry(function base(
// https://webpack.js.org/configuration/devtool/#development // https://webpack.js.org/configuration/devtool/#development
if (ctx.isDevelopment) { 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 // Non-eval based source maps are slow to rebuild, so we only enable
// them for Windows. Unfortunately, eval source maps are flagged as // them for Windows. Unfortunately, eval source maps are flagged as
// suspicious by Windows Defender and block HMR. // suspicious by Windows Defender and block HMR.
......
...@@ -26,7 +26,9 @@ export async function sandbox(id = nanoid(), initialFiles = new Map()) { ...@@ -26,7 +26,9 @@ export async function sandbox(id = nanoid(), initialFiles = new Map()) {
} }
const appPort = await findPort() 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, '/') const browser = await webdriver(appPort, '/')
return [ return [
......
...@@ -17,7 +17,9 @@ jest.setTimeout(1000 * 60 * 5) ...@@ -17,7 +17,9 @@ jest.setTimeout(1000 * 60 * 5)
describe('Basic Features', () => { describe('Basic Features', () => {
beforeAll(async () => { beforeAll(async () => {
context.appPort = await findPort() 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 // pre-build all pages at the start
await Promise.all([ await Promise.all([
......
...@@ -21,7 +21,9 @@ jest.setTimeout(1000 * 60 * 5) ...@@ -21,7 +21,9 @@ jest.setTimeout(1000 * 60 * 5)
describe('Client Navigation', () => { describe('Client Navigation', () => {
beforeAll(async () => { beforeAll(async () => {
context.appPort = await findPort() 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 = [ const prerender = [
'/async-props', '/async-props',
......
...@@ -564,6 +564,7 @@ describe('getServerSideProps', () => { ...@@ -564,6 +564,7 @@ describe('getServerSideProps', () => {
stderr = '' stderr = ''
appPort = await findPort() appPort = await findPort()
app = await launchApp(appDir, appPort, { app = await launchApp(appDir, appPort, {
env: { __NEXT_TEST_WITH_DEVTOOL: 1 },
onStderr(msg) { onStderr(msg) {
stderr += msg stderr += msg
}, },
......
...@@ -90,7 +90,9 @@ describe('Invalid hrefs', () => { ...@@ -90,7 +90,9 @@ describe('Invalid hrefs', () => {
describe('dev mode', () => { describe('dev mode', () => {
beforeAll(async () => { beforeAll(async () => {
appPort = await findPort() appPort = await findPort()
app = await launchApp(appDir, appPort) app = await launchApp(appDir, appPort, {
env: { __NEXT_TEST_WITH_DEVTOOL: 1 },
})
}) })
afterAll(() => killApp(app)) afterAll(() => killApp(app))
......
...@@ -1062,6 +1062,7 @@ describe('SSG Prerender', () => { ...@@ -1062,6 +1062,7 @@ describe('SSG Prerender', () => {
) )
appPort = await findPort() appPort = await findPort()
app = await launchApp(appDir, appPort, { app = await launchApp(appDir, appPort, {
env: { __NEXT_TEST_WITH_DEVTOOL: 1 },
onStderr: (msg) => { onStderr: (msg) => {
stderr += msg stderr += msg
}, },
...@@ -1084,7 +1085,9 @@ describe('SSG Prerender', () => { ...@@ -1084,7 +1085,9 @@ describe('SSG Prerender', () => {
) )
await fs.remove(join(appDir, '.next')) await fs.remove(join(appDir, '.next'))
appPort = await findPort() appPort = await findPort()
app = await launchApp(appDir, appPort) app = await launchApp(appDir, appPort, {
env: { __NEXT_TEST_WITH_DEVTOOL: 1 },
})
}) })
afterAll(async () => { afterAll(async () => {
await fs.remove(nextConfig) await fs.remove(nextConfig)
......
...@@ -22,6 +22,7 @@ describe('TypeScript HMR', () => { ...@@ -22,6 +22,7 @@ describe('TypeScript HMR', () => {
appPort = await findPort() appPort = await findPort()
app = await launchApp(appDir, appPort, { app = await launchApp(appDir, appPort, {
env: { env: {
__NEXT_TEST_WITH_DEVTOOL: 1,
// Events can be finicky in CI. This switches to a more reliable // Events can be finicky in CI. This switches to a more reliable
// polling method. // polling method.
CHOKIDAR_USEPOLLING: 'true', CHOKIDAR_USEPOLLING: 'true',
......
...@@ -97,7 +97,9 @@ describe('withRouter SSR', () => { ...@@ -97,7 +97,9 @@ describe('withRouter SSR', () => {
beforeAll(async () => { beforeAll(async () => {
port = await findPort() port = await findPort()
server = await launchApp(join(__dirname, '..'), port) server = await launchApp(join(__dirname, '..'), port, {
env: { __NEXT_TEST_WITH_DEVTOOL: 1 },
})
}) })
afterAll(async () => { afterAll(async () => {
await killApp(server) await killApp(server)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment