Unverified Commit a967202d authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Fix CSS Data URL test on Turbopack (#77970)

parent 0c7610b7
/* eslint-env jest */ /* eslint-env jest */
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { readdir, readFile, remove } from 'fs-extra' import { readFile, remove } from 'fs-extra'
import { import {
check, check,
File, File,
...@@ -14,6 +14,7 @@ import { ...@@ -14,6 +14,7 @@ import {
} from 'next-test-utils' } from 'next-test-utils'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { join } from 'path' import { join } from 'path'
import nodeFs from 'fs'
const fixturesDir = join(__dirname, '../..', 'css-fixtures') const fixturesDir = join(__dirname, '../..', 'css-fixtures')
...@@ -145,16 +146,18 @@ describe('should handle unresolved files gracefully', () => { ...@@ -145,16 +146,18 @@ describe('should handle unresolved files gracefully', () => {
}) })
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 cssFolder = join(workDir, '.next', 'static')
const cssFiles = nodeFs
.readdirSync(cssFolder, {
recursive: true,
encoding: 'utf8',
})
.filter((f) => f.endsWith('.css'))
for (const file of cssFiles) { expect(cssFiles).not.toBeEmpty()
if (file.endsWith('.css.map')) continue
const content = await readFile( for (const file of cssFiles) {
join(workDir, '.next/static/css', file), const content = await readFile(join(cssFolder, file), 'utf8')
'utf8'
)
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
...@@ -162,7 +165,6 @@ describe('should handle unresolved files gracefully', () => { ...@@ -162,7 +165,6 @@ describe('should handle unresolved files gracefully', () => {
content.includes('p{') || content.includes('p,') ? 2 : 1 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(/\(\/_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)
} }
...@@ -184,14 +186,18 @@ describe('Data URLs', () => { ...@@ -184,14 +186,18 @@ describe('Data URLs', () => {
}) })
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')
const files = await readdir(cssFolder) const cssFiles = nodeFs
const cssFiles = files.filter((f) => /\.css$/.test(f)) .readdirSync(cssFolder, {
recursive: true,
encoding: 'utf8',
})
.filter((f) => f.endsWith('.css'))
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(/\/\*.*?\*\/n/g, '').trim()).toMatch(
/background:url\("data:[^"]+"\)/ /background:url\("?data:[^"]+"?\)/
) )
}) })
} }
......
...@@ -9713,6 +9713,7 @@ ...@@ -9713,6 +9713,7 @@
"test/integration/css/test/css-modules.test.js": { "test/integration/css/test/css-modules.test.js": {
"passed": [ "passed": [
"Data URLs production mode should compile successfully", "Data URLs production mode should compile successfully",
"Data URLs production mode should have emitted expected files",
"Ordering with Global CSS and Modules (dev) useLightnincsss(false) should have the correct color (css ordering)", "Ordering with Global CSS and Modules (dev) useLightnincsss(false) should have the correct color (css ordering)",
"Ordering with Global CSS and Modules (dev) useLightnincsss(false) should have the correct color (css ordering) during hot reloads", "Ordering with Global CSS and Modules (dev) useLightnincsss(false) should have the correct color (css ordering) during hot reloads",
"Ordering with Global CSS and Modules (dev) useLightnincsss(false) should not execute scripts in any order", "Ordering with Global CSS and Modules (dev) useLightnincsss(false) should not execute scripts in any order",
...@@ -9726,7 +9727,6 @@ ...@@ -9726,7 +9727,6 @@
"should handle unresolved files gracefully production mode should build correctly" "should handle unresolved files gracefully production mode should build correctly"
], ],
"failed": [ "failed": [
"Data URLs production mode should have emitted expected files",
"should handle unresolved files gracefully production mode should have correct file references in CSS output" "should handle unresolved files gracefully production mode should have correct file references in CSS output"
], ],
"pending": [ "pending": [
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