Unverified Commit 446ddc76 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Turbopack build: Fix Sass test (#68936)

## What?

Updates the test to use the served page instead of readdir on the output
directory. Updates the snapshots for Turbopack. No behavior changes.

<!-- 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 9150f1b7
/* eslint-env jest */ /* eslint-env jest */
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { readdir, readFile } from 'fs-extra'
import { join } from 'path'
const nextConfig = { const nextConfig = {
productionBrowserSourceMaps: true, productionBrowserSourceMaps: true,
...@@ -33,55 +31,194 @@ describe.each([ ...@@ -33,55 +31,194 @@ describe.each([
;(isNextDev ? describe.skip : describe)('Production only', () => { ;(isNextDev ? describe.skip : describe)('Production only', () => {
describe('CSS Compilation and Prefixing', () => { describe('CSS Compilation and Prefixing', () => {
it(`should've compiled and prefixed`, async () => { it(`should've compiled and prefixed`, async () => {
const cssFolder = join(next.testDir, '.next/static/css') const $ = await next.render$('/')
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 stylesheetUrl = cssSheet.attr('href')
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8')
expect( const cssContent = await next
cssContent.replace(/\/\*.*?\*\//g, '').trim() .fetch(stylesheetUrl)
).toMatchInlineSnapshot( .then((res) => res.text())
`".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"` const cssContentWithoutSourceMap = cssContent
) .replace(/\/\*.*?\*\//g, '')
.trim()
if (process.env.TURBOPACK) {
if (dependencies.sass) {
expect(cssContentWithoutSourceMap).toMatchInlineSnapshot(`
".redText ::placeholder {
color: red;
}
.flex-parsing {
flex: 0 0 calc(50% - var(--vertical-gutter));
}"
`)
} else {
expect(cssContentWithoutSourceMap).toMatchInlineSnapshot(`
".redText ::placeholder {
color: red;
}
.flex-parsing {
flex: 0 0 calc(50% - var(--vertical-gutter));
}"
`)
}
} else {
if (dependencies.sass) {
expect(cssContentWithoutSourceMap).toMatchInlineSnapshot(
`".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"`
)
} else {
expect(cssContentWithoutSourceMap).toMatchInlineSnapshot(
`".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"`
)
}
}
// Contains a source map // Contains a source map
console.log({ cssContent })
expect(cssContent).toMatch(/\/\*#\s*sourceMappingURL=(.+\.map)\s*\*\//) expect(cssContent).toMatch(/\/\*#\s*sourceMappingURL=(.+\.map)\s*\*\//)
})
it(`should've emitted a source map`, async () => { // Check sourcemap
const cssFolder = join(next.testDir, '.next/static/css') const sourceMapUrl = /\/\*#\s*sourceMappingURL=(.+\.map)\s*\*\//.exec(
cssContent
)[1]
const files = await readdir(cssFolder) const actualSourceMapUrl = stylesheetUrl.replace(/[^/]+$/, sourceMapUrl)
const cssMapFiles = files.filter((f) => /\.css\.map$/.test(f)) const sourceMapContent = await next
.fetch(actualSourceMapUrl)
.then((res) => res.text())
const sourceMapContentParsed = JSON.parse(sourceMapContent)
// Ensure it doesn't have a specific path in the snapshot.
delete sourceMapContentParsed.file
delete sourceMapContentParsed.sources
expect(cssMapFiles.length).toBe(1) if (process.env.TURBOPACK) {
const cssMapContent = ( if (dependencies.sass) {
await readFile(join(cssFolder, cssMapFiles[0]), 'utf8') expect(sourceMapContentParsed).toMatchInlineSnapshot(`
).trim() {
"sections": [
{
"map": {
"mappings": "AAAA;;;;AAAiC",
"names": [],
"sources": [
"turbopack://[project]/styles/global.scss.css",
],
"sourcesContent": [
".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}",
],
"version": 3,
},
"offset": {
"column": 0,
"line": 1,
},
},
{
"map": {
"mappings": "A",
"names": [],
"sources": [],
"version": 3,
},
"offset": {
"column": 0,
"line": 8,
},
},
],
"version": 3,
}
`)
} else {
expect(sourceMapContentParsed).toMatchInlineSnapshot(`
{
"sections": [
{
"map": {
"mappings": "AAAA;;;;AAAiC",
"names": [],
"sources": [
"turbopack://[project]/styles/global.scss.css",
],
"sourcesContent": [
".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}",
],
"version": 3,
},
"offset": {
"column": 0,
"line": 1,
},
},
{
"map": {
"mappings": "A",
"names": [],
"sources": [],
"version": 3,
},
"offset": {
"column": 0,
"line": 8,
},
},
],
"version": 3,
}
`)
}
} else {
if (dependencies.sass) {
expect(sourceMapContentParsed).toMatchInlineSnapshot(`
{
"mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA",
"names": [],
"sourceRoot": "",
"sourcesContent": [
"$var: red;
.redText {
::placeholder {
color: $var;
}
}
const { version, mappings, sourcesContent } = JSON.parse(cssMapContent) .flex-parsing {
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(` flex: 0 0 calc(50% - var(--vertical-gutter));
{ }
"mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA", ",
"sourcesContent": [ ],
"$var: red; "version": 3,
.redText { }
::placeholder { `)
color: $var; } else {
} expect(sourceMapContentParsed).toMatchInlineSnapshot(`
} {
"mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA",
.flex-parsing { "names": [],
flex: 0 0 calc(50% - var(--vertical-gutter)); "sourceRoot": "",
} "sourcesContent": [
", "$var: red;
], .redText {
"version": 3, ::placeholder {
} color: $var;
`) }
}
.flex-parsing {
flex: 0 0 calc(50% - var(--vertical-gutter));
}
",
],
"version": 3,
}
`)
}
}
}) })
}) })
}) })
......
...@@ -3623,13 +3623,11 @@ ...@@ -3623,13 +3623,11 @@
"runtimeError": false "runtimeError": false
}, },
"test/e2e/app-dir/scss/compilation-and-prefixing/compilation-and-prefixing.test.ts": { "test/e2e/app-dir/scss/compilation-and-prefixing/compilation-and-prefixing.test.ts": {
"passed": [], "passed": [
"failed": [
"SCSS Support ({\"sass\": \"1.54.0\"}) Production only CSS Compilation and Prefixing should've compiled and prefixed", "SCSS Support ({\"sass\": \"1.54.0\"}) Production only CSS Compilation and Prefixing should've compiled and prefixed",
"SCSS Support ({\"sass\": \"1.54.0\"}) Production only CSS Compilation and Prefixing should've emitted a source map", "SCSS Support ({\"sass-embedded\": \"1.75.0\"}) Production only CSS Compilation and Prefixing should've compiled and prefixed"
"SCSS Support ({\"sass-embedded\": \"1.75.0\"}) Production only CSS Compilation and Prefixing should've compiled and prefixed",
"SCSS Support ({\"sass-embedded\": \"1.75.0\"}) Production only CSS Compilation and Prefixing should've emitted a source map"
], ],
"failed": [],
"pending": [], "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