Files
next.js/test/production/css-url-deployment-id/css-url-deployment-id.test.ts
Arian Tron 61f56f997c
Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
first commit
2026-03-10 19:37:31 +03:30

118 lines
3.4 KiB
TypeScript

import { isNextStart, nextTestSetup } from 'e2e-utils'
describe('css-url-deployment-id', () => {
const { next } = nextTestSetup({
files: __dirname,
skipDeployment: true,
dependencies: { sass: '1.54.0' },
env: {
NEXT_DEPLOYMENT_ID: isNextStart ? 'test-deployment-id' : undefined,
__NEXT_IMMUTABLE_ASSET_TOKEN: isNextStart
? 'imm-deployment-id'
: undefined,
},
disableAutoSkewProtection: true,
})
it('should include dpl query in CSS url() references for images and fonts', async () => {
const $ = await next.render$('/')
// Collect all CSS file URLs from link tags
const cssUrls: string[] = []
const links = Array.from($('link'))
for (const link of links) {
const href = link.attribs.href
if (href && href.includes('.css')) {
cssUrls.push(href)
}
}
// Also check for inline styles that may contain CSS
const styles = Array.from($('style'))
// Fetch all CSS files and collect their contents
let allCssContent = ''
for (const cssUrl of cssUrls) {
const res = await next.fetch(cssUrl)
const cssText = await res.text()
allCssContent += cssText + '\n'
}
// Also collect inline style content
for (const style of styles) {
const children = style.children
if (children && children.length > 0) {
for (const child of children) {
if ('data' in child) {
allCssContent += child.data + '\n'
}
}
}
}
// Extract all url() references from the CSS
const urlMatches = allCssContent.match(/url\([^)]+\)/g) || []
// Filter to only asset URLs (images and fonts), excluding data URIs
const assetUrls = urlMatches.filter(
(u) =>
!u.includes('data:') && (u.includes('.png') || u.includes('.woff2'))
)
expect(assetUrls.length).toBeGreaterThanOrEqual(1)
for (const assetUrl of assetUrls) {
expect(assetUrl).toContain('dpl=' + next.assetToken)
}
})
it('should include dpl query in CSS module url() references', async () => {
const $ = await next.render$('/')
const cssUrls: string[] = []
const links = Array.from($('link'))
for (const link of links) {
const href = link.attribs.href
if (href && href.includes('.css')) {
cssUrls.push(href)
}
}
const styles = Array.from($('style'))
let allCssContent = ''
for (const cssUrl of cssUrls) {
const res = await next.fetch(cssUrl)
const cssText = await res.text()
allCssContent += cssText + '\n'
}
for (const style of styles) {
const children = style.children
if (children && children.length > 0) {
for (const child of children) {
if ('data' in child) {
allCssContent += child.data + '\n'
}
}
}
}
// Find image references from CSS modules (page.module.css)
const imageUrls = allCssContent.match(/url\([^)]+\.png[^)]*\)/g) || []
expect(imageUrls.length).toBeGreaterThanOrEqual(1)
for (const imageUrl of imageUrls) {
expect(imageUrl).toContain('dpl=' + next.assetToken)
}
// Find font references from CSS modules
const fontUrls = allCssContent.match(/url\([^)]+\.woff2[^)]*\)/g) || []
expect(fontUrls.length).toBeGreaterThanOrEqual(1)
for (const fontUrl of fontUrls) {
expect(fontUrl).toContain('dpl=' + next.assetToken)
}
})
})