Unverified Commit dff6a71e authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix config import on Windows and disable test in failing envs (#29971)

Follow-up to https://github.com/vercel/next.js/pull/29935 this fixes the failing tests on Azure as it seems the `import()` needs to be prefixed with `file://` on Windows or an error is thrown. It also disables the config unit tests since a dynamic import inside of `jest` on either an m1 on macOS or Windows using node 14 causes a segfault from being used inside of `vm`. 

<details>

<summary>segfault error in jest</summary>

<img width="962" alt="Screen Shot 2021-10-15 at 16 45 04" src="https://user-images.githubusercontent.com/22380829/137596819-072233e3-1a45-445f-a3dd-c03ec62fb4ce.png">

</details>


<details>

<summary>Windows absolute import error</summary>


<img width="1114" alt="Screen Shot 2021-10-16 at 12 45 59" src="https://user-images.githubusercontent.com/22380829/137597185-200f3164-7f79-488f-acc9-6c812ce5bc4a.png">

</details>
parent 701fa999
...@@ -530,7 +530,8 @@ export default async function loadConfig( ...@@ -530,7 +530,8 @@ export default async function loadConfig(
let userConfigModule: any let userConfigModule: any
try { try {
userConfigModule = await import(path) // we must use file for absolute dynamic imports on Windows
userConfigModule = await import(`file://${path}`)
} catch (err) { } catch (err) {
console.error( console.error(
chalk.red('Error:') + chalk.red('Error:') +
......
...@@ -4,14 +4,14 @@ import cheerio from 'cheerio' ...@@ -4,14 +4,14 @@ import cheerio from 'cheerio'
import fs, { existsSync } from 'fs-extra' import fs, { existsSync } from 'fs-extra'
import globOriginal from 'glob' import globOriginal from 'glob'
import { import {
nextServer,
renderViaHTTP, renderViaHTTP,
runNextCommand,
startApp,
stopApp,
waitFor, waitFor,
getPageFileFromPagesManifest, getPageFileFromPagesManifest,
check, check,
nextBuild,
nextStart,
findPort,
killApp,
} from 'next-test-utils' } from 'next-test-utils'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { import {
...@@ -31,7 +31,6 @@ const glob = promisify(globOriginal) ...@@ -31,7 +31,6 @@ const glob = promisify(globOriginal)
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
let appPort let appPort
let server
let app let app
const context = {} const context = {}
...@@ -39,28 +38,23 @@ const context = {} ...@@ -39,28 +38,23 @@ const context = {}
describe('Production Usage', () => { describe('Production Usage', () => {
let output = '' let output = ''
beforeAll(async () => { beforeAll(async () => {
const result = await runNextCommand(['build', appDir], { const result = await nextBuild(appDir, undefined, {
stderr: true, stderr: true,
stdout: true, stdout: true,
}) })
app = nextServer({ appPort = await findPort()
dir: join(__dirname, '../'), context.appPort = appPort
dev: false, app = await nextStart(appDir, appPort)
quiet: true,
})
output = (result.stderr || '') + (result.stdout || '') output = (result.stderr || '') + (result.stdout || '')
console.log(output) console.log(output)
if (result.code !== 0) { if (result.code !== 0) {
throw new Error(`Failed to build, exited with code ${result.code}`) throw new Error(`Failed to build, exited with code ${result.code}`)
} }
server = await startApp(app)
context.appPort = appPort = server.address().port
}) })
afterAll(async () => { afterAll(async () => {
await stopApp(server) await killApp(app)
}) })
it('should contain generated page count in output', async () => { it('should contain generated page count in output', async () => {
...@@ -645,19 +639,8 @@ describe('Production Usage', () => { ...@@ -645,19 +639,8 @@ describe('Production Usage', () => {
describe('Misc', () => { describe('Misc', () => {
it('should handle already finished responses', async () => { it('should handle already finished responses', async () => {
const res = { const html = await renderViaHTTP(appPort, '/finish-response')
finished: false, expect(html).toBe('hi')
end() {
this.finished = true
},
}
const html = await app.renderToHTML(
{ method: 'GET' },
res,
'/finish-response',
{}
)
expect(html).toBeFalsy()
}) })
it('should allow to access /static/ and /_next/', async () => { it('should allow to access /static/ and /_next/', async () => {
......
/* eslint-env jest */ /* eslint-env jest */
import os from 'os'
import { join } from 'path' import { join } from 'path'
import loadConfig from 'next/dist/server/config' import loadConfig from 'next/dist/server/config'
import { PHASE_DEVELOPMENT_SERVER } from 'next/constants' import { PHASE_DEVELOPMENT_SERVER } from 'next/constants'
...@@ -8,6 +8,7 @@ const pathToConfig = join(__dirname, '_resolvedata', 'without-function') ...@@ -8,6 +8,7 @@ const pathToConfig = join(__dirname, '_resolvedata', 'without-function')
const pathToConfigFn = join(__dirname, '_resolvedata', 'with-function') const pathToConfigFn = join(__dirname, '_resolvedata', 'with-function')
describe('config', () => { describe('config', () => {
if (os.platform() === 'linux') {
it('Should get the configuration', async () => { it('Should get the configuration', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, pathToConfig) const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, pathToConfig)
expect(config.customConfig).toBe(true) expect(config.customConfig).toBe(true)
...@@ -115,4 +116,13 @@ describe('config', () => { ...@@ -115,4 +116,13 @@ describe('config', () => {
}) })
expect(config.target).toBe('server') expect(config.target).toBe('server')
}) })
} else {
// TODO: remove this when segfault no longer occurs with dynamic
// import inside of jest due to vm usage
it('should skip on non-linux platforms', () => {
console.warn(
'Warning!! These tests can not currently run on non-linux systems'
)
})
}
}) })
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