Skip to content

Commit

Permalink
update concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed May 16, 2023
1 parent 38679e2 commit 2961ca9
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 304 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_initial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:
PNPM_VERSION: 7.24.3
NODE_MAINTENANCE_VERSION: 16
NODE_LTS_VERSION: 18
TEST_CONCURRENCY: 6
TEST_CONCURRENCY: 10
# TODO: remove after testing
NEXT_TEST_CONTINUE_ON_ERROR: 'true'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:
PNPM_VERSION: 7.24.3
NODE_MAINTENANCE_VERSION: 16
NODE_LTS_VERSION: 18
TEST_CONCURRENCY: 8
TEST_CONCURRENCY: 10
# TODO: remove after testing
NEXT_TEST_CONTINUE_ON_ERROR: 'true'

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
"tree-kill": "1.2.2",
"ts-node": "10.9.1",
"tsec": "0.2.1",
"turbo": "1.9.4",
"turbo": "1.6.3",
"typescript": "4.8.2",
"unfetch": "4.2.0",
"wait-port": "0.2.2",
Expand Down
361 changes: 159 additions & 202 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const externalTestsFilterLists = process.env.NEXT_EXTERNAL_TESTS_FILTERS
? require(process.env.NEXT_EXTERNAL_TESTS_FILTERS)
: []
const timings = []
const DEFAULT_NUM_RETRIES = os.platform() === 'win32' ? 2 : 1
const DEFAULT_NUM_RETRIES = os.platform() === 'win32' ? 2 : 0
const DEFAULT_CONCURRENCY = 2
const RESULTS_EXT = `.results.json`
const isTestJob = !!process.env.NEXT_TEST_JOB
Expand Down Expand Up @@ -360,7 +360,7 @@ async function main() {
}
)
const handleOutput = (type) => (chunk) => {
if (hideOutput && !isFinalRun) {
if (hideOutput) {
outputChunks.push({ type, chunk })
} else {
process.stderr.write(chunk)
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/404-page-router/app/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
_basePath: '/docs',
_i18n: { defaultLocale: 'en-ca', locales: ['en-ca', 'en-fr'] },
}
209 changes: 114 additions & 95 deletions test/e2e/404-page-router/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createNext, FileRef } from 'e2e-utils'
import path from 'path'
import { type NextInstance } from 'test/lib/next-modes/base'
import fs from 'fs-extra'
import webdriver from 'next-webdriver'
import { type NextConfig } from 'next'
import { check, waitFor } from 'next-test-utils'
import { createNext, FileRef } from 'e2e-utils'
import { check } from 'next-test-utils'
import { type NextInstance } from 'test/lib/next-modes/base'

const pathnames = {
'/404': ['/not/a/real/page?with=query', '/not/a/real/page'],
Expand All @@ -14,7 +14,6 @@ const pathnames = {
}

const basePath = '/docs'
const i18n = { defaultLocale: 'en-ca', locales: ['en-ca', 'en-fr'] }

const table = [
{ basePath: false, i18n: true, middleware: false },
Expand All @@ -30,104 +29,124 @@ const table = [
]),
]

describe.each(table)(
'404-page-router with basePath of $basePath and i18n of $i18n and middleware $middleware',
(options) => {
const isDev = (global as any).isNextDev
describe('404-page-router', () => {
let next: NextInstance

if ((global as any).isNextDeploy) {
// TODO: investigate condensing these tests to avoid
// 5 separate deploys for this one test
it('should skip for deploy', () => {})
return
beforeAll(async () => {
const files = {
pages: new FileRef(path.join(__dirname, 'app/pages')),
components: new FileRef(path.join(__dirname, 'app/components')),
}

let next: NextInstance
let nextConfig: NextConfig

beforeAll(async () => {
const files = {
pages: new FileRef(path.join(__dirname, 'app/pages')),
components: new FileRef(path.join(__dirname, 'app/components')),
next = await createNext({ files, skipStart: true })
})
afterAll(() => next.destroy())

describe.each(table)(
'404-page-router with basePath of $basePath and i18n of $i18n and middleware $middleware',
(options) => {
const isDev = (global as any).isNextDev

if ((global as any).isNextDeploy) {
// TODO: investigate condensing these tests to avoid
// 5 separate deploys for this one test
it('should skip for deploy', () => {})
return
}

// Only add in the middleware if we're testing with middleware enabled.
if (options.middleware) {
files['middleware.js'] = new FileRef(
path.join(__dirname, 'app/middleware.js')
beforeAll(async () => {
// Only add in the middleware if we're testing with middleware enabled.
if (options.middleware) {
await next.patchFile(
'middleware.js',
await fs.readFile(
path.join(__dirname, 'app', 'middleware.js'),
'utf8'
)
)
}
let curNextConfig = await fs.readFile(
path.join(__dirname, 'app', 'next.config.js'),
'utf8'
)
}

nextConfig = {}
if (options.basePath) nextConfig.basePath = basePath
if (options.i18n) nextConfig.i18n = i18n

next = await createNext({ files, nextConfig })
})

afterAll(() => next.destroy())

/**
* translate will iterate over the pathnames and generate the test cases
* used in the following table test.
*
* @param pathname key for the pathname to iterate over
* @param shouldPrefixPathname true if the url's should be prefixed with the basePath
* @returns test cases
*/
function translate(
pathname: keyof typeof pathnames,
shouldPrefixPathname: boolean = false
): { url: string; pathname: keyof typeof pathnames; asPath: string }[] {
return pathnames[pathname].map((asPath) => ({
// Prefix the request URL with the basePath if enabled.
url: shouldPrefixPathname ? basePath + asPath : asPath,
// The pathname is not prefixed with the basePath.
pathname,
// The asPath is not prefixed with the basePath.
asPath,
}))
}
if (options.basePath) {
curNextConfig = curNextConfig.replace('_basePath', 'basePath')
}

if (options.i18n) {
curNextConfig = curNextConfig.replace('_i18n', 'i18n')
}
await next.patchFile('next.config.js', curNextConfig)
await next.start()
})
afterAll(async () => {
await next.stop()
await next.deleteFile('middleware.js')
})

// Always include the /404 tests, they'll run the same in development and
// production environments.
const urls = translate('/404')
/**
* translate will iterate over the pathnames and generate the test cases
* used in the following table test.
*
* @param pathname key for the pathname to iterate over
* @param shouldPrefixPathname true if the url's should be prefixed with the basePath
* @returns test cases
*/
function translate(
pathname: keyof typeof pathnames,
shouldPrefixPathname: boolean = false
): { url: string; pathname: keyof typeof pathnames; asPath: string }[] {
return pathnames[pathname].map((asPath) => ({
// Prefix the request URL with the basePath if enabled.
url: shouldPrefixPathname ? basePath + asPath : asPath,
// The pathname is not prefixed with the basePath.
pathname,
// The asPath is not prefixed with the basePath.
asPath,
}))
}

// Only include the /_error tests in production because in development we
// have the error overlay.
if (!isDev) {
urls.push(...translate('/_error', options.basePath))
}
// Always include the /404 tests, they'll run the same in development and
// production environments.
const urls = translate('/404')

// Only include the /_error tests in production because in development we
// have the error overlay.
if (!isDev) {
urls.push(...translate('/_error', options.basePath))
}

describe.each(urls)('for $url', ({ url, pathname, asPath }) => {
it('should have the correct router parameters after it is ready', async () => {
const query = url.split('?')[1] ?? ''
const browser = await webdriver(next.url, url)
describe.each(urls)('for $url', ({ url, pathname, asPath }) => {
it('should have the correct router parameters after it is ready', async () => {
const query = url.split('?')[1] ?? ''
const browser = await webdriver(next.url, url)

try {
await check(
() => browser.eval('next.router.isReady ? "yes" : "no"'),
'yes'
)
expect(await browser.elementById('pathname').text()).toEqual(
pathname
)
expect(await browser.elementById('asPath').text()).toEqual(asPath)
expect(await browser.elementById('query').text()).toEqual(query)
} finally {
await browser.close()
}
})
})

try {
await check(
() => browser.eval('next.router.isReady ? "yes" : "no"'),
'yes'
)
await waitFor(30 * 1000)
expect(await browser.elementById('pathname').text()).toEqual(pathname)
expect(await browser.elementById('asPath').text()).toEqual(asPath)
expect(await browser.elementById('query').text()).toEqual(query)
} finally {
await browser.close()
}
// It should not throw any errors when re-fetching the route info:
// https://github.com/vercel/next.js/issues/44293
it('should not throw any errors when re-fetching the route info', async () => {
const browser = await webdriver(next.url, '/?test=1')
await check(
() => browser.eval('next.router.isReady ? "yes" : "no"'),
'yes'
)
expect(await browser.elementById('query').text()).toEqual('test=1')
})
})

// It should not throw any errors when re-fetching the route info:
// https://github.com/vercel/next.js/issues/44293
it('should not throw any errors when re-fetching the route info', async () => {
const browser = await webdriver(next.url, '/?test=1')
await check(
() => browser.eval('next.router.isReady ? "yes" : "no"'),
'yes'
)
expect(await browser.elementById('query').text()).toEqual('test=1')
})
}
)
}
)
})
2 changes: 1 addition & 1 deletion test/e2e/app-dir/asset-prefix/asset-prefix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ createNextDescribe(
redirect: 'manual',
})
expect(res.status).toBe(308)
expect(res.headers.get('location')).toBe(next.url + '/a')
expect(new URL(res.headers.get('location'), next.url).pathname).toBe('/a')
})

it('should render link', async () => {
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/app-dir/trailingslash/trailingslash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ createNextDescribe(
redirect: 'manual',
})
expect(res.status).toBe(308)
expect(res.headers.get('location')).toBe(next.url + '/a/')
expect(new URL(res.headers.get('location'), next.url).pathname).toBe(
'/a/'
)
})

it('should render link with trailing slash', async () => {
Expand Down

0 comments on commit 2961ca9

Please sign in to comment.