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

Fix export worker threads options (#25063)

Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent 7f73b658
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
"image-size": "0.9.3", "image-size": "0.9.3",
"is-animated": "2.0.0", "is-animated": "2.0.0",
"isomorphic-unfetch": "3.0.0", "isomorphic-unfetch": "3.0.0",
"jest": "27.0.0-next.8",
"ky": "0.19.1", "ky": "0.19.1",
"ky-universal": "0.6.0", "ky-universal": "0.6.0",
"lerna": "4.0.0", "lerna": "4.0.0",
...@@ -119,6 +120,8 @@ ...@@ -119,6 +120,8 @@
"selenium-standalone": "6.18.0", "selenium-standalone": "6.18.0",
"selenium-webdriver": "4.0.0-alpha.7", "selenium-webdriver": "4.0.0-alpha.7",
"shell-quote": "1.7.2", "shell-quote": "1.7.2",
"sqlite": "4.0.22",
"sqlite3": "5.0.2",
"styled-components": "5.1.0", "styled-components": "5.1.0",
"styled-jsx-plugin-postcss": "3.0.2", "styled-jsx-plugin-postcss": "3.0.2",
"tailwindcss": "1.1.3", "tailwindcss": "1.1.3",
...@@ -128,8 +131,7 @@ ...@@ -128,8 +131,7 @@
"wait-port": "0.2.2", "wait-port": "0.2.2",
"web-streams-polyfill": "2.1.1", "web-streams-polyfill": "2.1.1",
"webpack-bundle-analyzer": "4.3.0", "webpack-bundle-analyzer": "4.3.0",
"worker-loader": "3.0.7", "worker-loader": "3.0.7"
"jest": "27.0.0-next.8"
}, },
"resolutions": { "resolutions": {
"browserslist": "4.16.1", "browserslist": "4.16.1",
......
...@@ -512,7 +512,7 @@ export default async function exportApp( ...@@ -512,7 +512,7 @@ export default async function exportApp(
const worker = new Worker(require.resolve('./worker'), { const worker = new Worker(require.resolve('./worker'), {
maxRetries: 0, maxRetries: 0,
numWorkers: threads, numWorkers: threads,
enableWorkerThreads: true, enableWorkerThreads: nextConfig.experimental.workerThreads,
exposedMethods: ['default'], exposedMethods: ['default'],
}) as Worker & { default: typeof exportPage } }) as Worker & { default: typeof exportPage }
......
import path from 'path'
import { open } from 'sqlite'
import sqlite3 from 'sqlite3'
import { useRouter } from 'next/router'
export const getStaticProps = async ({ params }) => {
const dbPath = path.join(process.cwd(), 'data.sqlite')
console.log('using db', dbPath)
const db = await open({
filename: dbPath,
driver: sqlite3.Database,
})
const users = await db.all(`SELECT * FROM users`)
return {
props: {
users,
blog: true,
params: params || null,
},
}
}
export const getStaticPaths = () => {
return {
paths: ['/blog/first'],
fallback: true,
}
}
export default function Page(props) {
const router = useRouter()
if (router.isFallback) {
return 'Loading...'
}
return (
<>
<p id="blog">blog page</p>
<p id="props">{JSON.stringify(props)}</p>
</>
)
}
export const getStaticProps = () => {
return {
props: {
index: true,
},
}
}
export default function Page(props) {
return (
<>
<p id="index">index page</p>
<p id="props">{JSON.stringify(props)}</p>
</>
)
}
/* eslint-env jest */
import { join } from 'path'
import webdriver from 'next-webdriver'
import {
findPort,
killApp,
launchApp,
nextBuild,
nextStart,
} from 'next-test-utils'
jest.setTimeout(1000 * 60 * 2)
let app
let appPort
const appDir = join(__dirname, '..')
const runTests = () => {
it('should render index correctly', async () => {
const browser = await webdriver(appPort, '/')
expect(await browser.elementByCss('#index').text()).toBe('index page')
expect(JSON.parse(await browser.elementByCss('#props').text())).toEqual({
index: true,
})
})
it('should render /blog/first correctly', async () => {
const browser = await webdriver(appPort, '/blog/first')
expect(await browser.elementByCss('#blog').text()).toBe('blog page')
expect(JSON.parse(await browser.elementByCss('#props').text())).toEqual({
params: { slug: 'first' },
blog: true,
users: [
{ id: 1, first_name: 'john', last_name: 'deux' },
{ id: 2, first_name: 'zeit', last_name: 'geist' },
],
})
})
it('should render /blog/second correctly', async () => {
const browser = await webdriver(appPort, '/blog/second')
await browser.waitForElementByCss('#blog')
expect(await browser.elementByCss('#blog').text()).toBe('blog page')
expect(JSON.parse(await browser.elementByCss('#props').text())).toEqual({
params: { slug: 'second' },
blog: true,
users: [
{ id: 1, first_name: 'john', last_name: 'deux' },
{ id: 2, first_name: 'zeit', last_name: 'geist' },
],
})
})
}
describe('Prerender native module', () => {
describe('production', () => {
beforeAll(async () => {
const result = await nextBuild(appDir, undefined, {
cwd: appDir,
stderr: true,
stdout: true,
})
if (result.code !== 0) {
console.error(result)
throw new Error(`Failed to build, exited with code ${result.code}`)
}
appPort = await findPort()
app = await nextStart(appDir, appPort, { cwd: appDir })
})
afterAll(() => killApp(app))
runTests()
})
describe('dev', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, { cwd: appDir })
})
afterAll(() => killApp(app))
runTests()
})
})
...@@ -166,7 +166,9 @@ export function runNextCommand(argv, options = {}) { ...@@ -166,7 +166,9 @@ export function runNextCommand(argv, options = {}) {
} }
export function runNextCommandDev(argv, stdOut, opts = {}) { export function runNextCommandDev(argv, stdOut, opts = {}) {
const cwd = path.dirname(require.resolve('next/package')) const nextDir = path.dirname(require.resolve('next/package'))
const nextBin = path.join(nextDir, 'dist/bin/next')
const cwd = opts.cwd || nextDir
const env = { const env = {
...process.env, ...process.env,
NODE_ENV: undefined, NODE_ENV: undefined,
...@@ -175,11 +177,10 @@ export function runNextCommandDev(argv, stdOut, opts = {}) { ...@@ -175,11 +177,10 @@ export function runNextCommandDev(argv, stdOut, opts = {}) {
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const instance = spawn( const instance = spawn('node', ['--no-deprecation', nextBin, ...argv], {
'node', cwd,
['--no-deprecation', 'dist/bin/next', ...argv], env,
{ cwd, env } })
)
let didResolve = false let didResolve = false
function handleStdout(data) { function handleStdout(data) {
......
This diff is collapsed.
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