Unverified Commit 01b6ec52 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Turbopack build: Fix CSS tests (#68841)

## What?

Further fixes for CSS related tests with Turbopack build, skipped a few
that are checking for a particular warning that is not really relevant
for Turbopack, documented that the warning is missing currently.

Also fixed another test that was reading from disk instead of loading
the page.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
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 7d952edc
...@@ -53,6 +53,9 @@ These features are currently not supported: ...@@ -53,6 +53,9 @@ These features are currently not supported:
- We are planning to implement this in the future. - We are planning to implement this in the future.
- [Relay transforms](/docs/architecture/nextjs-compiler#relay) - [Relay transforms](/docs/architecture/nextjs-compiler#relay)
- We are planning to implement this in the future. - We are planning to implement this in the future.
- Blocking `.css` imports in `pages/_document.tsx`
- Currently with webpack Next.js blocks importing `.css` files in `pages/_document.tsx`
- We are planning to implement this warning in the future.
- [`experimental.typedRoutes](https://nextjs.org/docs/app/api-reference/next-config-js/typedRoutes) - [`experimental.typedRoutes](https://nextjs.org/docs/app/api-reference/next-config-js/typedRoutes)
- We are planning to implement this in the future. - We are planning to implement this in the future.
- `experimental.nextScriptWorkers` - `experimental.nextScriptWorkers`
......
...@@ -6,7 +6,10 @@ import { join } from 'path' ...@@ -6,7 +6,10 @@ import { join } from 'path'
// In order for the global isNextStart to be set // In order for the global isNextStart to be set
import 'e2e-utils' import 'e2e-utils'
describe('Invalid SCSS in _document', () => { // TODO: Implement warning for Turbopack
;(process.env.TURBOPACK ? describe.skip : describe)(
'Invalid SCSS in _document',
() => {
;(Boolean((global as any).isNextStart) ? describe : describe.skip)( ;(Boolean((global as any).isNextStart) ? describe : describe.skip)(
'production only', 'production only',
() => { () => {
...@@ -30,4 +33,5 @@ describe('Invalid SCSS in _document', () => { ...@@ -30,4 +33,5 @@ describe('Invalid SCSS in _document', () => {
}) })
} }
) )
}) }
)
/* eslint-env jest */ /* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra' import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils' import {
findPort,
killApp,
nextBuild,
nextStart,
renderViaHTTP,
fetchViaHTTP,
} from 'next-test-utils'
import cheerio from 'cheerio'
import { join } from 'path' import { join } from 'path'
const fixturesDir = join(__dirname, '../..', 'css-fixtures') const fixturesDir = join(__dirname, '../..', 'css-fixtures')
describe('Invalid CSS in _document', () => { // TODO: Implement warning for Turbopack
;(process.env.TURBOPACK ? describe.skip : describe)(
'Invalid CSS in _document',
() => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)( ;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode', 'production mode',
() => { () => {
...@@ -29,9 +40,11 @@ describe('Invalid CSS in _document', () => { ...@@ -29,9 +40,11 @@ describe('Invalid CSS in _document', () => {
}) })
} }
) )
}) }
)
describe('Invalid Global CSS', () => { ;(process.env.TURBOPACK ? describe.skip : describe)(
'Invalid Global CSS',
() => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)( ;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode', 'production mode',
() => { () => {
...@@ -41,6 +54,7 @@ describe('Invalid Global CSS', () => { ...@@ -41,6 +54,7 @@ describe('Invalid Global CSS', () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
// eslint-disable-next-line jest/no-identical-title
it('should fail to build', async () => { it('should fail to build', async () => {
const { code, stderr } = await nextBuild(appDir, [], { const { code, stderr } = await nextBuild(appDir, [], {
stderr: true, stderr: true,
...@@ -55,7 +69,8 @@ describe('Invalid Global CSS', () => { ...@@ -55,7 +69,8 @@ describe('Invalid Global CSS', () => {
}) })
} }
) )
}) }
)
describe('Valid Global CSS from npm', () => { describe('Valid Global CSS from npm', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)( ;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
...@@ -63,35 +78,54 @@ describe('Valid Global CSS from npm', () => { ...@@ -63,35 +78,54 @@ describe('Valid Global CSS from npm', () => {
() => { () => {
const appDir = join(fixturesDir, 'import-global-from-module') const appDir = join(fixturesDir, 'import-global-from-module')
let appPort
let app
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
const { code } = await nextBuild(appDir)
if (code !== 0) {
throw new Error('failed to build')
}
appPort = await findPort()
app = await nextStart(appDir, appPort)
}) })
afterAll(async () => {
it('should compile successfully', async () => { await killApp(app)
const { code, stdout } = await nextBuild(appDir, [], {
stdout: true,
})
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
}) })
it(`should've emitted a single CSS file`, async () => { it(`should've emitted a single CSS file`, async () => {
const cssFolder = join(appDir, '.next/static/css') const content = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(content)
const files = await readdir(cssFolder) const cssSheet = $('link[rel="stylesheet"]')
const cssFiles = files.filter((f) => /\.css$/.test(f)) expect(cssSheet.length).toBe(1)
expect(cssFiles.length).toBe(1) const stylesheet = cssSheet.attr('href')
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8')
expect( const cssContent = (
cssContent.replace(/\/\*.*?\*\//g, '').trim() await fetchViaHTTP(appPort, stylesheet).then((res) => res.text())
).toMatchInlineSnapshot(`".red-text{color:"red"}"`) )
.replace(/\/\*.*?\*\//g, '')
.trim()
if (process.env.TURBOPACK) {
expect(cssContent).toMatchInlineSnapshot(`
".red-text {
color: "red";
}"
`)
} else {
expect(cssContent).toMatchInlineSnapshot(`".red-text{color:"red"}"`)
}
}) })
} }
) )
}) })
describe('Invalid Global CSS with Custom App', () => { // TODO: Implement warning for Turbopack
;(process.env.TURBOPACK ? describe.skip : describe)(
'Invalid Global CSS with Custom App',
() => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)( ;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode', 'production mode',
() => { () => {
...@@ -101,6 +135,7 @@ describe('Invalid Global CSS with Custom App', () => { ...@@ -101,6 +135,7 @@ describe('Invalid Global CSS with Custom App', () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
// eslint-disable-next-line jest/no-identical-title
it('should fail to build', async () => { it('should fail to build', async () => {
const { code, stderr } = await nextBuild(appDir, [], { const { code, stderr } = await nextBuild(appDir, [], {
stderr: true, stderr: true,
...@@ -115,9 +150,13 @@ describe('Invalid Global CSS with Custom App', () => { ...@@ -115,9 +150,13 @@ describe('Invalid Global CSS with Custom App', () => {
}) })
} }
) )
}) }
)
describe('Valid and Invalid Global CSS with Custom App', () => { // TODO: Implement warning for Turbopack
;(process.env.TURBOPACK ? describe.skip : describe)(
'Valid and Invalid Global CSS with Custom App',
() => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)( ;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode', 'production mode',
() => { () => {
...@@ -127,6 +166,7 @@ describe('Valid and Invalid Global CSS with Custom App', () => { ...@@ -127,6 +166,7 @@ describe('Valid and Invalid Global CSS with Custom App', () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
// eslint-disable-next-line jest/no-identical-title
it('should fail to build', async () => { it('should fail to build', async () => {
const { code, stderr } = await nextBuild(appDir, [], { const { code, stderr } = await nextBuild(appDir, [], {
stderr: true, stderr: true,
...@@ -141,4 +181,5 @@ describe('Valid and Invalid Global CSS with Custom App', () => { ...@@ -141,4 +181,5 @@ describe('Valid and Invalid Global CSS with Custom App', () => {
}) })
} }
) )
}) }
)
...@@ -3704,10 +3704,10 @@ ...@@ -3704,10 +3704,10 @@
}, },
"test/e2e/app-dir/scss/invalid-module-document/invalid-module-document.test.ts": { "test/e2e/app-dir/scss/invalid-module-document/invalid-module-document.test.ts": {
"passed": [], "passed": [],
"failed": [ "failed": [],
"pending": [
"Invalid SCSS in _document production only should fail to build" "Invalid SCSS in _document production only should fail to build"
], ],
"pending": [],
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
}, },
...@@ -7911,16 +7911,15 @@ ...@@ -7911,16 +7911,15 @@
}, },
"test/integration/css/test/valid-invalid-css.test.js": { "test/integration/css/test/valid-invalid-css.test.js": {
"passed": [ "passed": [
"Valid Global CSS from npm production mode should compile successfully" "Valid Global CSS from npm production mode should've emitted a single CSS file"
], ],
"failed": [ "failed": [],
"pending": [
"Invalid CSS in _document production mode should fail to build", "Invalid CSS in _document production mode should fail to build",
"Invalid Global CSS production mode should fail to build", "Invalid Global CSS production mode should fail to build",
"Invalid Global CSS with Custom App production mode should fail to build", "Invalid Global CSS with Custom App production mode should fail to build",
"Valid Global CSS from npm production mode should've emitted a single CSS file",
"Valid and Invalid Global CSS with Custom App production mode should fail to build" "Valid and Invalid Global CSS with Custom App production mode should fail to build"
], ],
"pending": [],
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
}, },
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