Test That Custom Properties Are Not Compiled (#9984)

* Fix Browserslist Loading

* Fix Browserslist Integration for CSS

* Add missing file

* Test That Custom Properties Are Not Compiled

* Disable custom properties transform
This commit is contained in:
Joe Haddad 2020-01-08 06:06:16 -05:00 committed by Tim Neutkens
parent 18d8c90c3f
commit 1c6f0874ce
10 changed files with 103 additions and 0 deletions

View file

@ -95,6 +95,9 @@ function getDefaultPlugins(
// Enable CSS features that have shipped to the
// web platform, i.e. in 2+ browsers unflagged.
stage: 3,
features: {
'custom-properties': false,
},
},
],
]

View file

@ -0,0 +1,5 @@
{
"browserslist": [
"ie 11"
]
}

View file

@ -0,0 +1,12 @@
import App from 'next/app'
import React from 'react'
import './styles.css'
class MyApp extends App {
render() {
const { Component, pageProps } = this.props
return <Component {...pageProps} />
}
}
export default MyApp

View file

@ -0,0 +1,3 @@
export default function() {
return <div />
}

View file

@ -0,0 +1,7 @@
:root {
--color: red;
}
h1 {
color: var(--color);
}

View file

@ -0,0 +1,5 @@
{
"browserslist": [
"chrome 78"
]
}

View file

@ -0,0 +1,12 @@
import App from 'next/app'
import React from 'react'
import './styles.css'
class MyApp extends App {
render() {
const { Component, pageProps } = this.props
return <Component {...pageProps} />
}
}
export default MyApp

View file

@ -0,0 +1,3 @@
export default function() {
return <div />
}

View file

@ -0,0 +1,7 @@
:root {
--color: red;
}
h1 {
color: var(--color);
}

View file

@ -53,3 +53,49 @@ describe('Browserslist: New', () => {
)
})
})
describe('Custom Properties: Pass-Through IE11', () => {
const appDir = join(fixturesDir, 'cp-ie-11')
beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
})
it(`should've emitted a single CSS file`, async () => {
const cssFolder = join(appDir, '.next/static/css')
const files = await readdir(cssFolder)
const cssFiles = files.filter(f => /\.css$/.test(f))
expect(cssFiles.length).toBe(1)
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8')
expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatchInlineSnapshot(
`":root{--color:red}h1{color:var(--color)}"`
)
})
})
describe('Custom Properties: Pass-Through Modern', () => {
const appDir = join(fixturesDir, 'cp-modern')
beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
})
it(`should've emitted a single CSS file`, async () => {
const cssFolder = join(appDir, '.next/static/css')
const files = await readdir(cssFolder)
const cssFiles = files.filter(f => /\.css$/.test(f))
expect(cssFiles.length).toBe(1)
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8')
expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatchInlineSnapshot(
`":root{--color:red}h1{color:var(--color)}"`
)
})
})