Skip to content

Commit

Permalink
Merge branch 'canary' into group-callstack-by-framework
Browse files Browse the repository at this point in the history
  • Loading branch information
hanneslund authored Jan 3, 2023
2 parents fd4dabd + 4a9dc11 commit 15a5e00
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .github/actions/next-stats-action/src/prepare/repo-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module.exports = (actionInfo) => {
pkgs = await fs.readdir(path.join(repoDir, 'packages'))
} catch (err) {
if (err.code === 'ENOENT') {
console.log('no packages to link')
require('console').log('no packages to link')
return pkgPaths
}
throw err
Expand All @@ -105,7 +105,7 @@ module.exports = (actionInfo) => {

const pkgDataPath = path.join(pkgPath, 'package.json')
if (!fs.existsSync(pkgDataPath)) {
console.log(`Skipping ${pkgDataPath}`)
require('console').log(`Skipping ${pkgDataPath}`)
continue
}
const pkgData = require(pkgDataPath)
Expand Down Expand Up @@ -137,7 +137,7 @@ module.exports = (actionInfo) => {
pkgData.files = []
}
pkgData.files.push('native')
console.log(
require('console').log(
'using swc binaries: ',
await exec(
`ls ${path.join(path.dirname(pkgDataPath), 'native')}`
Expand Down
82 changes: 82 additions & 0 deletions test/development/acceptance-app/ReactRefreshLogBox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,88 @@ describe('ReactRefreshLogBox app', () => {
await cleanup()
})

test('server component can recover from syntax error', async () => {
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
`
export default function Page() {
return <p>Hello world</p>
}
`,
],
])
)

// Add syntax error
await session.patch(
'app/page.js',
`
export default function Page() {
return <p>Hello world</p>
`
)
expect(await session.hasRedbox(true)).toBe(true)

// Fix syntax error
await session.patch(
'app/page.js',
`
export default function Page() {
return <p>Hello world 2</p>
}
`
)

expect(await browser.waitForElementByCss('p').text()).toBe('Hello world 2')

await cleanup()
})

test('server component can recover from component error', async () => {
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
`
export default function Page() {
return <p>Hello world</p>
}
`,
],
])
)

// Add component error
await session.patch(
'app/page.js',
`
export default function Page() {
throw new Error("boom")
return <p>Hello world</p>
}
`
)
expect(await session.hasRedbox(true)).toBe(true)

// Fix component error
await session.patch(
'app/page.js',
`
export default function Page() {
return <p>Hello world 2</p>
}
`
)

expect(await browser.waitForElementByCss('p').text()).toBe('Hello world 2')

await cleanup()
})

// https://github.com/pmmmwh/react-refresh-webpack-plugin/pull/3#issuecomment-554137262
test('render error not shown right after syntax error', async () => {
const { session, cleanup } = await sandbox(next)
Expand Down
29 changes: 12 additions & 17 deletions test/e2e/test-utils-tests/basic/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { createNext } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { fetchViaHTTP } from 'next-test-utils'
import { createNextDescribe } from 'e2e-utils'

describe('createNext', () => {
let next: NextInstance

beforeAll(async () => {
next = await createNext({
files: __dirname,
createNextDescribe(
'createNextDescribe',
{
files: __dirname,
},
({ next }) => {
it('should work', async () => {
const res = await next.fetch('/')
expect(await res.text()).toContain('Hello World')
})
})
afterAll(() => next.destroy())

it('should work', async () => {
const res = await fetchViaHTTP(next.url, '/')
expect(await res.text()).toContain('Hello World')
})
})
}
)
80 changes: 72 additions & 8 deletions test/lib/create-next-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ const { randomBytes } = require('crypto')
const { linkPackages } =
require('../../.github/actions/next-stats-action/src/prepare/repo-setup')()

/**
* These are simple dependencies provided by default. We want to optimize this special case.
*/
const areGenericDependencies = (dependencies) =>
Object.keys(dependencies).length === 6 &&
Object.entries(dependencies).every(([dep, version]) => {
if (dep === 'next') return true
return (
[
'react',
'react-dom',
'typescript',
'@types/react',
'@types/node',
].includes(dep) && version === 'latest'
)
})

async function createNextInstall({
parentSpan,
dependencies,
Expand All @@ -29,6 +47,10 @@ async function createNextInstall({
`next-repo-${randomBytes(32).toString('hex')}${dirSuffix}`
)

require('console').log('Using following temporary directories:')
require('console').log(installDir)
require('console').log(tmpRepoDir)

await rootSpan.traceChild(' enruse swc binary').traceAsyncFn(async () => {
// ensure swc binary is present in the native folder if
// not already built
Expand Down Expand Up @@ -137,15 +159,57 @@ async function createNextInstall({
await rootSpan
.traceChild('run generic install command')
.traceAsyncFn(async () => {
await execa(
'pnpm',
['install', '--strict-peer-dependencies=false'],
{
cwd: installDir,
stdio: ['ignore', 'inherit', 'inherit'],
env: process.env,
const runInstall = async () =>
await execa(
'pnpm',
['install', '--strict-peer-dependencies=false'],
{
cwd: installDir,
stdio: ['ignore', 'inherit', 'inherit'],
env: process.env,
}
)

if (!areGenericDependencies(combinedDependencies)) {
await runInstall()
} else {
const cacheDir = path.join(
origRepoDir,
'test',
'tmp',
'genericInstallCache'
)

const cachedFiles = [
// We can't cache node-modules because .pnpm store must be on the same mount - we can't move it between mountpoints
// 'node_modules',
'pnpm-lock.yaml',
]

if (
await fs
.access(cacheDir)
.then(() => true)
.catch(() => false)
) {
require('console').log(
'We are able to prepopulate pnpm install from cache'
)
cachedFiles.forEach((file) => {
fs.copy(
path.join(cacheDir, file),
path.join(installDir, file)
)
})
}
)

await runInstall()

await fs.ensureDir(cacheDir)
cachedFiles.forEach((file) => {
fs.copy(path.join(installDir, file), path.join(cacheDir, file))
})
}
})
}

Expand Down

0 comments on commit 15a5e00

Please sign in to comment.