Unverified Commit 711fa213 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

More test updates (#56146)

Follow-up to #56089

<!-- Thanks for opening a PR! Your contribution is much appreciated.i
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
parent 3e32378c
...@@ -111,57 +111,61 @@ describe('Basic CSS Modules Ordering', () => { ...@@ -111,57 +111,61 @@ describe('Basic CSS Modules Ordering', () => {
}) })
describe('should handle unresolved files gracefully', () => { describe('should handle unresolved files gracefully', () => {
const workDir = join(fixturesDir, 'unresolved-css-url') ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const workDir = join(fixturesDir, 'unresolved-css-url')
it('should build correctly', async () => { it('should build correctly', async () => {
await remove(join(workDir, '.next')) await remove(join(workDir, '.next'))
const { code } = await nextBuild(workDir) const { code } = await nextBuild(workDir)
expect(code).toBe(0) expect(code).toBe(0)
}) })
it('should have correct file references in CSS output', async () => { it('should have correct file references in CSS output', async () => {
const cssFiles = await readdir(join(workDir, '.next/static/css')) const cssFiles = await readdir(join(workDir, '.next/static/css'))
for (const file of cssFiles) { for (const file of cssFiles) {
if (file.endsWith('.css.map')) continue if (file.endsWith('.css.map')) continue
const content = await readFile( const content = await readFile(
join(workDir, '.next/static/css', file), join(workDir, '.next/static/css', file),
'utf8' 'utf8'
) )
console.log(file, content) console.log(file, content)
// if it is the combined global CSS file there are double the expected // if it is the combined global CSS file there are double the expected
// results // results
const howMany = content.includes('p{') || content.includes('p,') ? 2 : 1 const howMany = content.includes('p{') || content.includes('p,') ? 2 : 1
expect(content.match(/\(\/vercel\.svg/g).length).toBe(howMany) expect(content.match(/\(\/vercel\.svg/g).length).toBe(howMany)
// expect(content.match(/\(vercel\.svg/g).length).toBe(howMany) // expect(content.match(/\(vercel\.svg/g).length).toBe(howMany)
expect(content.match(/\(\/_next\/static\/media/g).length).toBe(1) expect(content.match(/\(\/_next\/static\/media/g).length).toBe(1)
expect(content.match(/\(https:\/\//g).length).toBe(howMany) expect(content.match(/\(https:\/\//g).length).toBe(howMany)
} }
})
}) })
}) })
describe('Data URLs', () => { describe('Data URLs', () => {
const workDir = join(fixturesDir, 'data-url') ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const workDir = join(fixturesDir, 'data-url')
it('should compile successfully', async () => { it('should compile successfully', async () => {
await remove(join(workDir, '.next')) await remove(join(workDir, '.next'))
const { code } = await nextBuild(workDir) const { code } = await nextBuild(workDir)
expect(code).toBe(0) expect(code).toBe(0)
}) })
it('should have emitted expected files', async () => { it('should have emitted expected files', async () => {
const cssFolder = join(workDir, '.next/static/css') const cssFolder = join(workDir, '.next/static/css')
const files = await readdir(cssFolder) const files = await readdir(cssFolder)
const cssFiles = files.filter((f) => /\.css$/.test(f)) const cssFiles = files.filter((f) => /\.css$/.test(f))
expect(cssFiles.length).toBe(1) expect(cssFiles.length).toBe(1)
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8')
expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatch( expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatch(
/background:url\("data:[^"]+"\)/ /background:url\("data:[^"]+"\)/
) )
})
}) })
}) })
...@@ -249,36 +253,38 @@ describe('Ordering with Global CSS and Modules (dev)', () => { ...@@ -249,36 +253,38 @@ describe('Ordering with Global CSS and Modules (dev)', () => {
}) })
describe('Ordering with Global CSS and Modules (prod)', () => { describe('Ordering with Global CSS and Modules (prod)', () => {
const appDir = join(fixturesDir, 'global-and-module-ordering') ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = join(fixturesDir, 'global-and-module-ordering')
let appPort let appPort
let app let app
let stdout let stdout
let code let code
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
;({ code, stdout } = await nextBuild(appDir, [], { ;({ code, stdout } = await nextBuild(appDir, [], {
stdout: true, stdout: true,
})) }))
appPort = await findPort() appPort = await findPort()
app = await nextStart(appDir, appPort) app = await nextStart(appDir, appPort)
}) })
afterAll(async () => { afterAll(async () => {
await killApp(app) await killApp(app)
}) })
it('should have compiled successfully', () => { it('should have compiled successfully', () => {
expect(code).toBe(0) expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/) expect(stdout).toMatch(/Compiled successfully/)
}) })
it('should have the correct color (css ordering)', async () => { it('should have the correct color (css ordering)', async () => {
const browser = await webdriver(appPort, '/') const browser = await webdriver(appPort, '/')
const currentColor = await browser.eval( const currentColor = await browser.eval(
`window.getComputedStyle(document.querySelector('#blueText')).color` `window.getComputedStyle(document.querySelector('#blueText')).color`
) )
expect(currentColor).toMatchInlineSnapshot(`"rgb(0, 0, 255)"`) expect(currentColor).toMatchInlineSnapshot(`"rgb(0, 0, 255)"`)
})
}) })
}) })
......
...@@ -37,7 +37,7 @@ function runTests(url: string) { ...@@ -37,7 +37,7 @@ function runTests(url: string) {
}) })
} }
describe('Image Loader Config', () => { describe('Image Loader Config new', () => {
describe('dev mode - component', () => { describe('dev mode - component', () => {
beforeAll(async () => { beforeAll(async () => {
appPort = await findPort() appPort = await findPort()
......
import {
check,
findPort,
killApp,
launchApp,
renderViaHTTP,
} from 'next-test-utils'
import { join } from 'path'
import fs from 'fs-extra'
import stripAnsi from 'strip-ansi'
describe.skip('Project Directory Delete Handling', () => {
it('should gracefully exit on project dir delete', async () => {
const appDir = join(__dirname, 'app')
const appPort = await findPort()
await fs.ensureDir(join(appDir, 'pages'))
await fs.writeFile(
join(appDir, 'pages', 'index.js'),
`
export default function Page() {
return <p>hello world</p>
}
`
)
let output = ''
const app = await launchApp(appDir, appPort, {
onStdout(msg) {
output += msg
},
onStderr(msg) {
output += msg
},
})
expect(await renderViaHTTP(appPort, '/')).toContain('hello world')
await fs.remove(appDir)
await check(
() => stripAnsi(output),
/Project directory could not be found, restart Next\.js in your new directory/
)
try {
await killApp(app)
} catch (_) {}
})
})
...@@ -28,26 +28,33 @@ describe('SCSS Support', () => { ...@@ -28,26 +28,33 @@ describe('SCSS Support', () => {
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
;(process.env.TURBOPACK ? it.skip : it)(
it('should be a friendly error successfully', async () => { 'should be a friendly error successfully',
const { code, stderr } = await nextBuild(appDir, [], { async () => {
env: { NODE_OPTIONS: shellQuote([`--require`, mockFile]) }, const { code, stderr } = await nextBuild(appDir, [], {
stderr: true, env: { NODE_OPTIONS: shellQuote([`--require`, mockFile]) },
}) stderr: true,
let cleanScssErrMsg = })
'\n\n' + let cleanScssErrMsg =
'./styles/global.scss\n' + '\n\n' +
"To use Next.js' built-in Sass support, you first need to install `sass`.\n" + './styles/global.scss\n' +
'Run `npm i sass` or `yarn add sass` inside your workspace.\n' + "To use Next.js' built-in Sass support, you first need to install `sass`.\n" +
'\n' + 'Run `npm i sass` or `yarn add sass` inside your workspace.\n' +
'Learn more: https://nextjs.org/docs/messages/install-sass\n' '\n' +
'Learn more: https://nextjs.org/docs/messages/install-sass\n'
expect(code).toBe(1)
expect(stderr).toContain('Failed to compile.') // eslint-disable-next-line
expect(stderr).toContain(cleanScssErrMsg) expect(code).toBe(1)
expect(stderr).not.toContain('css-loader') // eslint-disable-next-line
expect(stderr).not.toContain('sass-loader') expect(stderr).toContain('Failed to compile.')
}) // eslint-disable-next-line
expect(stderr).toContain(cleanScssErrMsg)
// eslint-disable-next-line
expect(stderr).not.toContain('css-loader')
// eslint-disable-next-line
expect(stderr).not.toContain('sass-loader')
}
)
}) })
describe('CSS Compilation and Prefixing', () => { describe('CSS Compilation and Prefixing', () => {
......
...@@ -7,21 +7,25 @@ import { join } from 'path' ...@@ -7,21 +7,25 @@ import { join } from 'path'
const fixturesDir = join(__dirname, '../..', 'scss-fixtures') const fixturesDir = join(__dirname, '../..', 'scss-fixtures')
describe('SCSS Support', () => { describe('SCSS Support loader handling', () => {
describe('CSS URL via `file-loader`', () => { describe('CSS URL via `file-loader`', () => {
const appDir = join(fixturesDir, 'url-global') const appDir = join(fixturesDir, 'url-global')
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
;(process.env.TURBOPACK ? it.skip : it)(
it('should compile successfully', async () => { 'should compile successfully',
const { code, stdout } = await nextBuild(appDir, [], { async () => {
stdout: true, const { code, stdout } = await nextBuild(appDir, [], {
}) stdout: true,
expect(code).toBe(0) })
expect(stdout).toMatch(/Compiled successfully/) // eslint-disable-next-line
}) expect(code).toBe(0)
// eslint-disable-next-line
expect(stdout).toMatch(/Compiled successfully/)
}
)
it(`should've emitted expected files`, async () => { it(`should've emitted expected files`, async () => {
const cssFolder = join(appDir, '.next/static/css') const cssFolder = join(appDir, '.next/static/css')
...@@ -60,14 +64,18 @@ describe('SCSS Support', () => { ...@@ -60,14 +64,18 @@ describe('SCSS Support', () => {
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
;(process.env.TURBOPACK ? it.skip : it)(
it('should compile successfully', async () => { 'should compile successfully',
const { code, stdout } = await nextBuild(appDir, [], { async () => {
stdout: true, const { code, stdout } = await nextBuild(appDir, [], {
}) stdout: true,
expect(code).toBe(0) })
expect(stdout).toMatch(/Compiled successfully/) // eslint-disable-next-line
}) expect(code).toBe(0)
// eslint-disable-next-line
expect(stdout).toMatch(/Compiled successfully/)
}
)
it(`should've emitted expected files`, async () => { it(`should've emitted expected files`, async () => {
const cssFolder = join(appDir, '.next/static/css') const cssFolder = join(appDir, '.next/static/css')
...@@ -108,14 +116,18 @@ describe('SCSS Support', () => { ...@@ -108,14 +116,18 @@ describe('SCSS Support', () => {
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
;(process.env.TURBOPACK ? it.skip : it)(
it('should compile successfully', async () => { 'should compile successfully',
const { code, stdout } = await nextBuild(appDir, [], { async () => {
stdout: true, const { code, stdout } = await nextBuild(appDir, [], {
}) stdout: true,
expect(code).toBe(0) })
expect(stdout).toMatch(/Compiled successfully/) // eslint-disable-next-line
}) expect(code).toBe(0)
// eslint-disable-next-line
expect(stdout).toMatch(/Compiled successfully/)
}
)
it(`should've emitted expected files`, async () => { it(`should've emitted expected files`, async () => {
const cssFolder = join(appDir, '.next/static/css') const cssFolder = join(appDir, '.next/static/css')
...@@ -154,14 +166,18 @@ describe('SCSS Support', () => { ...@@ -154,14 +166,18 @@ describe('SCSS Support', () => {
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
;(process.env.TURBOPACK ? it.skip : it)(
it('should compile successfully', async () => { 'should compile successfully',
const { code, stdout } = await nextBuild(appDir, [], { async () => {
stdout: true, const { code, stdout } = await nextBuild(appDir, [], {
}) stdout: true,
expect(code).toBe(0) })
expect(stdout).toMatch(/Compiled successfully/) // eslint-disable-next-line
}) expect(code).toBe(0)
// eslint-disable-next-line
expect(stdout).toMatch(/Compiled successfully/)
}
)
it(`should've emitted expected files`, async () => { it(`should've emitted expected files`, async () => {
const cssFolder = join(appDir, '.next/static/css') const cssFolder = join(appDir, '.next/static/css')
...@@ -200,14 +216,18 @@ describe('SCSS Support', () => { ...@@ -200,14 +216,18 @@ describe('SCSS Support', () => {
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
;(process.env.TURBOPACK ? it.skip : it)(
it('should compile successfully', async () => { 'should compile successfully',
const { code, stdout } = await nextBuild(appDir, [], { async () => {
stdout: true, const { code, stdout } = await nextBuild(appDir, [], {
}) stdout: true,
expect(code).toBe(0) })
expect(stdout).toMatch(/Compiled successfully/) // eslint-disable-next-line
}) expect(code).toBe(0)
// eslint-disable-next-line
expect(stdout).toMatch(/Compiled successfully/)
}
)
it(`should've emitted expected files`, async () => { it(`should've emitted expected files`, async () => {
const cssFolder = join(appDir, '.next/static/css') const cssFolder = join(appDir, '.next/static/css')
...@@ -229,14 +249,18 @@ describe('SCSS Support', () => { ...@@ -229,14 +249,18 @@ describe('SCSS Support', () => {
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
;(process.env.TURBOPACK ? it.skip : it)(
it('should compile successfully', async () => { 'should compile successfully',
const { code, stdout } = await nextBuild(appDir, [], { async () => {
stdout: true, const { code, stdout } = await nextBuild(appDir, [], {
}) stdout: true,
expect(code).toBe(0) })
expect(stdout).toMatch(/Compiled successfully/) // eslint-disable-next-line
}) expect(code).toBe(0)
// eslint-disable-next-line
expect(stdout).toMatch(/Compiled successfully/)
}
)
it(`should've emitted expected files`, async () => { it(`should've emitted expected files`, async () => {
const cssFolder = join(appDir, '.next/static/css') const cssFolder = join(appDir, '.next/static/css')
...@@ -258,12 +282,15 @@ describe('SCSS Support', () => { ...@@ -258,12 +282,15 @@ describe('SCSS Support', () => {
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
;(process.env.TURBOPACK ? it.skip : it)(
it('should compile successfully', async () => { 'should compile successfully',
const { stdout } = await nextBuild(appDir, [], { async () => {
stdout: true, const { stdout } = await nextBuild(appDir, [], {
}) stdout: true,
expect(stdout).toMatch(/Compiled successfully/) })
}) // eslint-disable-next-line
expect(stdout).toMatch(/Compiled successfully/)
}
)
}) })
}) })
...@@ -20,63 +20,64 @@ jest.setTimeout(1000 * 60 * 2) ...@@ -20,63 +20,64 @@ jest.setTimeout(1000 * 60 * 2)
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
for (const dev of [false, true]) { for (const dev of [false, true]) {
describe(`Handle new URL asset references in next ${ ;(process.env.TURBOPACK && !dev ? describe.skip : describe)(
dev ? 'dev' : 'build' `Handle new URL asset references in next ${dev ? 'dev' : 'build'}`,
}`, () => { () => {
let appPort let appPort
let app let app
beforeAll(async () => { beforeAll(async () => {
await fs.remove(join(appDir, '.next')) await fs.remove(join(appDir, '.next'))
if (dev) { if (dev) {
appPort = await findPort() appPort = await findPort()
app = await launchApp(appDir, appPort) app = await launchApp(appDir, appPort)
} else { } else {
await nextBuild(appDir) await nextBuild(appDir)
appPort = await findPort() appPort = await findPort()
app = await nextStart(appDir, appPort) app = await nextStart(appDir, appPort)
}
})
afterAll(() => killApp(app))
const expectedServer =
/Hello <!-- -->\/_next\/static\/media\/vercel\.[0-9a-f]{8}\.png<!-- -->\+<!-- -->\/_next\/static\/media\/vercel\.[0-9a-f]{8}\.png/
const expectedClient = new RegExp(
expectedServer.source.replace(/<!-- -->/g, '')
)
for (const page of ['/static', '/ssr', '/ssg']) {
it(`should render the ${page} page`, async () => {
const html = await renderViaHTTP(appPort, page)
expect(html).toMatch(expectedServer)
})
it(`should client-render the ${page} page`, async () => {
let browser
try {
browser = await webdriver(appPort, page)
await check(() => getBrowserBodyText(browser), expectedClient)
} finally {
await browser.close()
} }
}) })
} afterAll(() => killApp(app))
it('should respond on size api', async () => { const expectedServer =
const data = await fetchViaHTTP(appPort, '/api/size').then( /Hello <!-- -->\/_next\/static\/media\/vercel\.[0-9a-f]{8}\.png<!-- -->\+<!-- -->\/_next\/static\/media\/vercel\.[0-9a-f]{8}\.png/
(res) => res.ok && res.json() const expectedClient = new RegExp(
expectedServer.source.replace(/<!-- -->/g, '')
) )
expect(data).toEqual({ size: 30079 }) for (const page of ['/static', '/ssr', '/ssg']) {
}) it(`should render the ${page} page`, async () => {
const html = await renderViaHTTP(appPort, page)
expect(html).toMatch(expectedServer)
})
it('should respond on basename api', async () => { it(`should client-render the ${page} page`, async () => {
const data = await fetchViaHTTP(appPort, '/api/basename').then( let browser
(res) => res.ok && res.json() try {
) browser = await webdriver(appPort, page)
await check(() => getBrowserBodyText(browser), expectedClient)
} finally {
await browser.close()
}
})
}
it('should respond on size api', async () => {
const data = await fetchViaHTTP(appPort, '/api/size').then(
(res) => res.ok && res.json()
)
expect(data).toEqual({ size: 30079 })
})
it('should respond on basename api', async () => {
const data = await fetchViaHTTP(appPort, '/api/basename').then(
(res) => res.ok && res.json()
)
expect(data).toEqual({ expect(data).toEqual({
basename: expect.stringMatching(/^vercel\.[0-9a-f]{8}\.png$/), basename: expect.stringMatching(/^vercel\.[0-9a-f]{8}\.png$/),
})
}) })
}) }
}) )
} }
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