Unverified Commit 50857dad authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix isolated tests on windows and update azure config (#44457)

Fixes handling in isolated tests for windows and adds initial setup to run the main `app-dir` test suite. Also adds retrying when fetching test timings fails due to rate limiting. 

Closes: https://github.com/vercel/next.js/pull/44331
parent 448c9c82
...@@ -109,7 +109,7 @@ stages: ...@@ -109,7 +109,7 @@ stages:
condition: eq(variables['isDocsOnly'], 'No') condition: eq(variables['isDocsOnly'], 'No')
displayName: 'Run tests' displayName: 'Run tests'
- job: test_integration_app_dir - job: test_e2e_dev
pool: pool:
vmImage: 'windows-2019' vmImage: 'windows-2019'
steps: steps:
...@@ -139,6 +139,44 @@ stages: ...@@ -139,6 +139,44 @@ stages:
condition: eq(variables['isDocsOnly'], 'No') condition: eq(variables['isDocsOnly'], 'No')
- script: | - script: |
node run-tests.js -c 1 test/integration/app-dir-basic/test/index.test.js node run-tests.js -c 1 --debug test/e2e/app-dir/app/index.test.ts
condition: eq(variables['isDocsOnly'], 'No') condition: eq(variables['isDocsOnly'], 'No')
displayName: 'Run tests' displayName: 'Run tests (E2E Development)'
env:
NEXT_TEST_MODE: 'dev'
- job: test_e2e_prod
pool:
vmImage: 'windows-2019'
steps:
- task: NodeTool@0
inputs:
versionSpec: $(node_16_version)
displayName: 'Install Node.js'
- bash: |
node scripts/run-for-change.js --not --type docs --exec echo "##vso[task.setvariable variable=isDocsOnly]No"
displayName: 'Check Docs Only Change'
- script: npm i -g pnpm@$(PNPM_VERSION)
condition: eq(variables['isDocsOnly'], 'No')
- script: pnpm config set store-dir $(PNPM_CACHE_FOLDER)
condition: eq(variables['isDocsOnly'], 'No')
- script: pnpm store path
condition: eq(variables['isDocsOnly'], 'No')
- script: pnpm install && pnpm run build
condition: eq(variables['isDocsOnly'], 'No')
displayName: 'Install and build'
- script: npx playwright install chromium
condition: eq(variables['isDocsOnly'], 'No')
- script: |
node run-tests.js -c 1 --debug test/e2e/app-dir/app/index.test.ts
condition: eq(variables['isDocsOnly'], 'No')
displayName: 'Run tests (E2E Production)'
env:
NEXT_TEST_MODE: 'start'
...@@ -49,11 +49,22 @@ const cleanUpAndExit = async (code) => { ...@@ -49,11 +49,22 @@ const cleanUpAndExit = async (code) => {
} }
async function getTestTimings() { async function getTestTimings() {
const timingsRes = await fetch(TIMINGS_API, { let timingsRes
const doFetch = () =>
fetch(TIMINGS_API, {
headers: { headers: {
...TIMINGS_API_HEADERS, ...TIMINGS_API_HEADERS,
}, },
}) })
timingsRes = await doFetch()
if (timingsRes.status === 403) {
const delay = 15
console.log(`Got 403 response waiting ${delay} seconds before retry`)
await new Promise((resolve) => setTimeout(resolve, delay * 1000))
timingsRes = await doFetch()
}
if (!timingsRes.ok) { if (!timingsRes.ok) {
throw new Error(`request status: ${timingsRes.status}`) throw new Error(`request status: ${timingsRes.status}`)
...@@ -219,6 +230,7 @@ async function main() { ...@@ -219,6 +230,7 @@ async function main() {
}) })
if ( if (
process.platform !== 'win32' &&
process.env.NEXT_TEST_MODE !== 'deploy' && process.env.NEXT_TEST_MODE !== 'deploy' &&
((testType && testType !== 'unit') || hasIsolatedTests) ((testType && testType !== 'unit') || hasIsolatedTests)
) { ) {
......
export default function page() {
return <div id="blog">this is blog</div>
}
export default function RootLayout({ children }) {
return (
<html>
<head></head>
<body>{children}</body>
</html>
)
}
export default function page() {
return <div id="home">this is home</div>
}
module.exports = {
experimental: {
appDir: true,
},
}
/* eslint-env jest */
import { join } from 'path'
import cheerio from 'cheerio'
import { runDevSuite, runProdSuite, renderViaHTTP } from 'next-test-utils'
import webdriver from 'next-webdriver'
const appDir = join(__dirname, '..')
function runTests(context, env) {
describe('App Dir Basic', () => {
it('should render html properly', async () => {
const $index = cheerio.load(await renderViaHTTP(context.appPort, '/'))
const $blog = cheerio.load(await renderViaHTTP(context.appPort, '/blog'))
expect($index('#home').text()).toBe('this is home')
expect($blog('#blog').text()).toBe('this is blog')
})
it('should hydrate pages properly', async () => {
const browser = await webdriver(context.appPort, '/')
const indexHtml = await browser.waitForElementByCss('#home').text()
const url = await browser.url()
await browser.loadPage(url + 'blog')
const blogHtml = await browser.waitForElementByCss('#blog').text()
expect(indexHtml).toBe('this is home')
expect(blogHtml).toBe('this is blog')
})
})
}
runDevSuite('App Dir Basic', appDir, { runTests })
runProdSuite('App Dir Basic', appDir, { runTests })
import { spawn } from 'child_process' import { spawn } from 'cross-spawn'
import { Span } from 'next/trace' import { Span } from 'next/trace'
import { NextInstance } from './base' import { NextInstance } from './base'
...@@ -36,6 +36,7 @@ export class NextDevInstance extends NextInstance { ...@@ -36,6 +36,7 @@ export class NextDevInstance extends NextInstance {
} }
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {
try {
this.childProcess = spawn(startArgs[0], startArgs.slice(1), { this.childProcess = spawn(startArgs[0], startArgs.slice(1), {
cwd: useDirArg ? process.cwd() : this.testDir, cwd: useDirArg ? process.cwd() : this.testDir,
stdio: ['ignore', 'pipe', 'pipe'], stdio: ['ignore', 'pipe', 'pipe'],
...@@ -95,6 +96,10 @@ export class NextDevInstance extends NextInstance { ...@@ -95,6 +96,10 @@ export class NextDevInstance extends NextInstance {
} }
} }
this.on('stdout', readyCb) this.on('stdout', readyCb)
} catch (err) {
require('console').error(`Failed to run ${startArgs.join(' ')}`, err)
setTimeout(() => process.exit(1), 0)
}
}) })
} }
} }
import path from 'path' import path from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
import { NextInstance } from './base' import { NextInstance } from './base'
import { spawn, SpawnOptions } from 'child_process' import { spawn, SpawnOptions } from 'cross-spawn'
import { Span } from 'next/trace' import { Span } from 'next/trace'
export class NextStartInstance extends NextInstance { export class NextStartInstance extends NextInstance {
...@@ -65,6 +65,8 @@ export class NextStartInstance extends NextInstance { ...@@ -65,6 +65,8 @@ export class NextStartInstance extends NextInstance {
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {
console.log('running', buildArgs.join(' ')) console.log('running', buildArgs.join(' '))
try {
this.childProcess = spawn( this.childProcess = spawn(
buildArgs[0], buildArgs[0],
buildArgs.slice(1), buildArgs.slice(1),
...@@ -79,6 +81,10 @@ export class NextStartInstance extends NextInstance { ...@@ -79,6 +81,10 @@ export class NextStartInstance extends NextInstance {
) )
else resolve() else resolve()
}) })
} catch (err) {
require('console').error(`Failed to run ${buildArgs.join(' ')}`, err)
setTimeout(() => process.exit(1), 0)
}
}) })
this._buildId = ( this._buildId = (
...@@ -95,6 +101,7 @@ export class NextStartInstance extends NextInstance { ...@@ -95,6 +101,7 @@ export class NextStartInstance extends NextInstance {
console.log('running', startArgs.join(' ')) console.log('running', startArgs.join(' '))
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
try {
this.childProcess = spawn( this.childProcess = spawn(
startArgs[0], startArgs[0],
startArgs.slice(1), startArgs.slice(1),
...@@ -106,7 +113,9 @@ export class NextStartInstance extends NextInstance { ...@@ -106,7 +113,9 @@ export class NextStartInstance extends NextInstance {
if (this.isStopping) return if (this.isStopping) return
if (code || signal) { if (code || signal) {
throw new Error( throw new Error(
`next start exited unexpectedly with code/signal ${code || signal}` `next start exited unexpectedly with code/signal ${
code || signal
}`
) )
} }
}) })
...@@ -120,6 +129,10 @@ export class NextStartInstance extends NextInstance { ...@@ -120,6 +129,10 @@ export class NextStartInstance extends NextInstance {
} }
} }
this.on('stdout', readyCb) this.on('stdout', readyCb)
} catch (err) {
require('console').error(`Failed to run ${startArgs.join(' ')}`, err)
setTimeout(() => process.exit(1), 0)
}
}) })
} }
......
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