Unverified Commit 92eecbfd authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: sass support (#62717)

### What?

* upgrades turbopack for `getResolve` in webpack loaders
* add missing resolve-url-loader to turbopack for full sass support

Closes PACK-2634
parent e9862a80
This diff is collapsed.
......@@ -37,11 +37,11 @@ swc_core = { version = "0.90.12", features = [
testing = { version = "0.35.19" }
# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240304.1" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240304.2" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240304.1" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240304.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240304.1" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240304.2" }
# General Deps
......
use std::mem::take;
use anyhow::{bail, Result};
use serde_json::Value as JsonValue;
use turbo_tasks::Vc;
......@@ -32,17 +34,28 @@ pub async fn maybe_add_sass_loader(
.get("prependData")
.or(sass_options.get("additionalData"));
let rule = rules.get_mut(pattern);
let loader = WebpackLoaderItem {
let sass_loader = WebpackLoaderItem {
loader: "next/dist/compiled/sass-loader".to_string(),
options: serde_json::json!({
//https://github.com/vercel/turbo/blob/d527eb54be384a4658243304cecd547d09c05c6b/crates/turbopack-node/src/transforms/webpack.rs#L191
"sourceMap": false,
"sassOptions": sass_options,
"additionalData": additional_data
})
.as_object()
.unwrap()
.clone(),
options: take(
serde_json::json!({
"sourceMap": true,
"sassOptions": sass_options,
"additionalData": additional_data
})
.as_object_mut()
.unwrap(),
),
};
let resolve_url_loader = WebpackLoaderItem {
loader: "next/dist/build/webpack/loaders/resolve-url-loader/index".to_string(),
options: take(
serde_json::json!({
//https://github.com/vercel/turbo/blob/d527eb54be384a4658243304cecd547d09c05c6b/crates/turbopack-node/src/transforms/webpack.rs#L191
"sourceMap": false
})
.as_object_mut()
.unwrap(),
),
};
if let Some(rule) = rule {
......@@ -57,13 +70,14 @@ pub async fn maybe_add_sass_loader(
continue;
}
let mut loaders = rule.loaders.await?.clone_value();
loaders.push(loader);
loaders.push(resolve_url_loader);
loaders.push(sass_loader);
rule.loaders = Vc::cell(loaders);
} else {
rules.insert(
pattern.to_string(),
LoaderRuleItem {
loaders: Vc::cell(vec![loader]),
loaders: Vc::cell(vec![resolve_url_loader, sass_loader]),
rename_as: Some(format!("*{rename}")),
},
);
......
......@@ -192,7 +192,7 @@
"@types/ws": "8.2.0",
"@vercel/ncc": "0.34.0",
"@vercel/nft": "0.26.4",
"@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240304.1",
"@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240304.2",
"acorn": "8.5.0",
"amphtml-validator": "1.0.35",
"anser": "1.4.9",
......
......@@ -56,7 +56,9 @@ export default async function resolveUrlLoader(
}
const callback = this.async()
const { postcss } = await options.postcss()
const { postcss } = options.postcss
? await options.postcss()
: { postcss: require('postcss') }
process(postcss, this.resourcePath, content, {
outputSourceMap: Boolean(options.sourceMap),
transformDeclaration: valueProcessor(this.resourcePath, options),
......
......@@ -35,9 +35,11 @@ export default function process(
) {
// #107 libsass emits orphan CR not considered newline, postcss does consider newline (content vs source-map mismatch)
postcssPlugin.postcss = true
// prepend file protocol to all sources to avoid problems with source map
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return postcss([postcss.plugin('postcss-resolve-url', postcssPlugin)])
return postcss([postcssPlugin])
.process(sourceContent, {
from: prepend(sourceFile),
map: params.outputSourceMap && {
......@@ -56,9 +58,12 @@ export default function process(
* Plugin for postcss that follows SASS transpilation.
*/
function postcssPlugin() {
return function (styles: any) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
styles.walkDecls(eachDeclaration)
return {
postcssPlugin: 'postcss-resolve-url',
Once: function (root: any) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
root.walkDecls(eachDeclaration)
},
}
/**
......
......@@ -1074,8 +1074,8 @@ importers:
specifier: 0.26.4
version: 0.26.4
'@vercel/turbopack-ecmascript-runtime':
specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240304.1
version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240304.1'
specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240304.2
version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240304.2'
acorn:
specifier: 8.5.0
version: 8.5.0
......@@ -25728,8 +25728,8 @@ packages:
/zwitch@2.0.4:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
'@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240304.1':
resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240304.1}
'@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240304.2':
resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240304.2}
name: '@vercel/turbopack-ecmascript-runtime'
version: 0.0.0
dependencies:
......
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('3rd Party CSS Module Support', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it('should render the module', async () => {
const browser = await next.browser('/')
// Bar
expect(
await browser
.elementByCss('#verify-div .bar')
.getComputedCss('background-color')
).toBe(colorToRgb('blue'))
// Baz
expect(
await browser
.elementByCss('#verify-div .baz')
.getComputedCss('background-color')
).toBe(colorToRgb('blue'))
// Lol
expect(
await browser
.elementByCss('#verify-div .lol')
.getComputedCss('background-color')
).toBe(colorToRgb('red'))
// Lel
expect(
await browser
.elementByCss('#verify-div .lel')
.getComputedCss('background-color')
).toBe(colorToRgb('green'))
})
})
import { foo } from './index.module.scss'
export default function Home() {
return (
<div id="verify-div" className={foo}>
<div className="bar">Bar</div>
<div className="baz">Baz</div>
<div className="lol">Lol</div>
<div className="lel">Lel</div>
</div>
)
}
......@@ -4,14 +4,13 @@
.foo :global(.bar),
.foo :global(.baz) {
height: 100%;
overflow: hidden;
background-color: blue;
}
.foo :global(.lol) {
width: 80%;
background-color: red;
}
.foo > :global(.lel) {
width: 80%;
background-color: green;
}
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Basic Module Additional Data Support', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it('should render the module', async () => {
const browser = await next.browser('/')
expect(
await browser.elementByCss('#verify-red').getComputedCss('color')
).toBe(colorToRgb('red'))
})
})
module.exports = {
sassOptions: {
additionalData: `
$var: red;
`,
},
}
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Basic Module Include Paths Support', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it('should render the module', async () => {
const browser = await next.browser('/')
expect(
await browser.elementByCss('#verify-red').getComputedCss('color')
).toBe(colorToRgb('red'))
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Basic Module Prepend Data Support', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it('should render the module', async () => {
const browser = await next.browser('/')
expect(
await browser.elementByCss('#verify-red').getComputedCss('color')
).toBe(colorToRgb('red'))
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Basic SCSS Module Support', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it('should render the module', async () => {
const browser = await next.browser('/')
expect(
await browser.elementByCss('#verify-red').getComputedCss('color')
).toBe(colorToRgb('red'))
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Catch-all Route CSS Module Usage', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it('should render the module', async () => {
const browser = await next.browser('/post')
expect(
await browser.elementByCss('#my-div').getComputedCss('background-color')
).toBe(colorToRgb('red'))
})
})
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { nextTestSetup } from 'e2e-utils'
import { readdir, readFile } from 'fs-extra'
import { join } from 'path'
describe('SCSS Support', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('CSS Compilation and Prefixing', () => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should compile successfully', async () => {
const { code, stdout } = await nextBuild(appDir, [], {
stdout: true,
})
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
})
const { next, isNextDev } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
// TODO: Figure out this test for dev and Turbopack
;(isNextDev ? describe.skip : describe)('Production only', () => {
describe('CSS Compilation and Prefixing', () => {
it(`should've compiled and prefixed`, async () => {
const cssFolder = join(appDir, '.next/static/css')
const cssFolder = join(next.testDir, '.next/static/css')
const files = await readdir(cssFolder)
const cssFiles = files.filter((f) => /\.css$/.test(f))
......@@ -36,11 +30,12 @@ describe('SCSS Support', () => {
)
// Contains a source map
console.log({ cssContent })
expect(cssContent).toMatch(/\/\*#\s*sourceMappingURL=(.+\.map)\s*\*\//)
})
it(`should've emitted a source map`, async () => {
const cssFolder = join(appDir, '.next/static/css')
const cssFolder = join(next.testDir, '.next/static/css')
const files = await readdir(cssFolder)
const cssMapFiles = files.filter((f) => /\.css\.map$/.test(f))
......@@ -52,24 +47,24 @@ describe('SCSS Support', () => {
const { version, mappings, sourcesContent } = JSON.parse(cssMapContent)
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(`
{
"mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA",
"sourcesContent": [
"$var: red;
.redText {
::placeholder {
color: $var;
{
"mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA",
"sourcesContent": [
"$var: red;
.redText {
::placeholder {
color: $var;
}
}
}
.flex-parsing {
flex: 0 0 calc(50% - var(--vertical-gutter));
}
",
],
"version": 3,
}
`)
.flex-parsing {
flex: 0 0 calc(50% - var(--vertical-gutter));
}
",
],
"version": 3,
}
`)
})
})
})
......
module.exports = {
productionBrowserSourceMaps: true,
}
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('CSS Module Composes Usage (Basic)', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it('should render the module', async () => {
const browser = await next.browser('/')
expect(
await browser.elementByCss('#verify-yellow').getComputedCss('color')
).toBe(colorToRgb('yellow'))
expect(
await browser
.elementByCss('#verify-yellow')
.getComputedCss('background-color')
).toBe(colorToRgb('blue'))
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('CSS Module Composes Usage (External)', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it('should render the module', async () => {
const browser = await next.browser('/')
expect(
await browser.elementByCss('#verify-yellow').getComputedCss('color')
).toBe(colorToRgb('yellow'))
expect(
await browser
.elementByCss('#verify-yellow')
.getComputedCss('background-color')
).toBe(colorToRgb('blue'))
})
})
$var: blue;
.subClass {
composes: className from './other.scss';
composes: className from './other.module.scss';
background: $var;
}
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('SCSS Support loader handling Data Urls', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it('should render the module', async () => {
const browser = await next.browser('/')
const redText = await browser.elementByCss('.red-text')
expect(await redText.getComputedCss('color')).toBe(colorToRgb('red'))
expect(await redText.getComputedCss('background-image')).toMatch(
/url\("data:[^"]+"\)$/
)
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Has CSS Module in computed styles in Development', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it('should have CSS for page', async () => {
const browser = await next.browser('/')
expect(
await browser.elementByCss('#verify-red').getComputedCss('color')
).toBe(colorToRgb('red'))
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Dynamic Route CSS Module Usage', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
it('should apply styles correctly', async () => {
const browser = await next.browser('/post-1')
const background = await browser
.elementByCss('#my-div')
.getComputedCss('background-color')
expect(background).toMatch(colorToRgb('red'))
})
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
describe('SCSS Support loader handling External imports', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it(`should include font on the page`, async () => {
const browser = await next.browser('/')
const result = await browser.eval(async function () {
return document.fonts.ready.then((fonts) => {
const includedFonts = []
for (const font of fonts.values()) {
includedFonts.push(font.family)
}
return includedFonts
})
})
expect(result).toInclude('Poppins')
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb, retry } from 'next-test-utils'
describe('Can hot reload CSS Module without losing state', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
;(isNextDev ? describe : describe.skip)('development only', () => {
it('should update CSS color without remounting <input>', async () => {
const browser = await next.browser('/')
const desiredText = 'hello world'
await browser.elementById('text-input').type(desiredText)
expect(await browser.elementById('text-input').getValue()).toBe(
desiredText
)
expect(
await browser.elementByCss('#verify-red').getComputedCss('color')
).toBe(colorToRgb('red'))
await next.patchFile('pages/index.module.scss', (content) => {
return content.replace('$var: red', '$var: purple')
})
await retry(async () => {
expect(
await browser.elementByCss('#verify-red').getComputedCss('color')
).toBe(colorToRgb('purple'))
})
// ensure text remained
expect(await browser.elementById('text-input').getValue()).toBe(
desiredText
)
})
})
})
/* eslint-env jest */
import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
// In order for the global isNextStart to be set
import 'e2e-utils'
describe.skip('Invalid CSS Global Module Usage in node_modules', () => {
;(Boolean((global as any).isNextStart) ? describe : describe.skip)(
'production only',
() => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should fail to build', async () => {
const { code, stderr } = await nextBuild(appDir, [], {
stderr: true,
})
expect(code).not.toBe(0)
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('node_modules/example/index.scss')
expect(stderr).toMatch(
/Global CSS.*cannot.*be imported from within.*node_modules/
)
expect(stderr).toMatch(
/Location:.*node_modules[\\/]example[\\/]index\.mjs/
)
})
}
)
})
/* eslint-env jest */
import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
// In order for the global isNextStart to be set
import 'e2e-utils'
describe('Invalid Global CSS with Custom App', () => {
;(Boolean((global as any).isNextStart) ? describe : describe.skip)(
'production only',
() => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should fail to build', async () => {
const { code, stderr } = await nextBuild(appDir, [], {
stderr: true,
})
expect(code).not.toBe(0)
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('styles/global.scss')
expect(stderr).toMatch(
/Please move all first-party global CSS imports.*?pages(\/|\\)_app/
)
expect(stderr).toMatch(/Location:.*pages[\\/]index\.js/)
})
}
)
})
/* eslint-env jest */
import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
// In order for the global isNextStart to be set
import 'e2e-utils'
describe('Invalid Global CSS', () => {
;(Boolean((global as any).isNextStart) ? describe : describe.skip)(
'production only',
() => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should fail to build', async () => {
const { code, stderr } = await nextBuild(appDir, [], {
stderr: true,
})
expect(code).not.toBe(0)
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('styles/global.scss')
expect(stderr).toMatch(
/Please move all first-party global CSS imports.*?pages(\/|\\)_app/
)
expect(stderr).toMatch(/Location:.*pages[\\/]index\.js/)
})
}
)
})
/* eslint-env jest */
import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
// In order for the global isNextStart to be set
import 'e2e-utils'
describe('Invalid SCSS in _document', () => {
;(Boolean((global as any).isNextStart) ? describe : describe.skip)(
'production only',
() => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should fail to build', async () => {
const { code, stderr } = await nextBuild(appDir, [], {
stderr: true,
})
expect(code).not.toBe(0)
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('styles.module.scss')
expect(stderr).toMatch(
/CSS.*cannot.*be imported within.*pages[\\/]_document\.js/
)
expect(stderr).toMatch(/Location:.*pages[\\/]_document\.js/)
})
}
)
})
/* eslint-env jest */
import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
// In order for the global isNextStart to be set
import 'e2e-utils'
describe.skip('Invalid CSS Module Usage in node_modules', () => {
;(Boolean((global as any).isNextStart) ? describe : describe.skip)(
'production only',
() => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should fail to build', async () => {
const { code, stderr } = await nextBuild(appDir, [], {
stderr: true,
})
expect(code).not.toBe(0)
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('node_modules/example/index.module.scss')
expect(stderr).toMatch(
/CSS Modules.*cannot.*be imported from within.*node_modules/
)
expect(stderr).toMatch(
/Location:.*node_modules[\\/]example[\\/]index\.mjs/
)
})
}
)
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('SCSS Support loader handling Preprocessor loader order', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it('should render the module', async () => {
const browser = await next.browser('/')
expect(
await browser.elementByCss('.red-text').getComputedCss('color')
).toBe(colorToRgb('red'))
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Multi Global Support (reversed)', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it('should render the page', async () => {
const browser = await next.browser('/')
expect(
await browser.elementByCss('#verify-blue').getComputedCss('color')
).toBe(colorToRgb('blue'))
})
})
export default function Home() {
return (
<div className="red-text blue-text" id="verify-blue">
This text should be blue.
</div>
)
}
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Multi Global Support', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it('should render the page', async () => {
const browser = await next.browser('/')
expect(
await browser.elementByCss('#verify-red').getComputedCss('color')
).toBe(colorToRgb('red'))
})
})
export default function Home() {
return (
<>
<div className="red-text blue-text" id="verify-red">
This text should be red.
</div>
</>
)
}
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb, retry } from 'next-test-utils'
describe('SCSS Support', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
describe('Has CSS in computed styles in Production', () => {
it('should have CSS for page', async () => {
const browser = await next.browser('/page2')
expect(
await browser.elementByCss('.blue-text').getComputedCss('color')
).toBe(colorToRgb('blue'))
})
})
if (isNextDev) {
describe('Can hot reload CSS without losing state', () => {
it('should update CSS color without remounting <input>', async () => {
const browser = await next.browser('/page1')
const desiredText = 'hello world'
await browser.elementById('text-input').type(desiredText)
expect(await browser.elementById('text-input').getValue()).toBe(
desiredText
)
expect(
await browser.elementByCss('.red-text').getComputedCss('color')
).toBe(colorToRgb('red'))
await next.patchFile('styles/global1.scss', (contents) => {
return contents.replace('$var: red', '$var: purple')
})
await retry(async () => {
expect(
await browser.elementByCss('.red-text').getComputedCss('color')
).toBe(colorToRgb('purple'))
})
// ensure text remained
expect(await browser.elementById('text-input').getValue()).toBe(
desiredText
)
})
})
}
describe('Has CSS in computed styles in Development', () => {
it('should have CSS for page', async () => {
const browser = await next.browser('/page2')
expect(
await browser.elementByCss('.blue-text').getComputedCss('color')
).toBe(colorToRgb('blue'))
})
})
})
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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