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
...@@ -321,7 +321,7 @@ dependencies = [ ...@@ -321,7 +321,7 @@ dependencies = [
[[package]] [[package]]
name = "auto-hash-map" name = "auto-hash-map"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"serde", "serde",
"smallvec", "smallvec",
...@@ -3396,7 +3396,7 @@ dependencies = [ ...@@ -3396,7 +3396,7 @@ dependencies = [
[[package]] [[package]]
name = "node-file-trace" name = "node-file-trace"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"serde", "serde",
...@@ -7374,7 +7374,7 @@ dependencies = [ ...@@ -7374,7 +7374,7 @@ dependencies = [
[[package]] [[package]]
name = "turbo-tasks" name = "turbo-tasks"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
...@@ -7406,7 +7406,7 @@ dependencies = [ ...@@ -7406,7 +7406,7 @@ dependencies = [
[[package]] [[package]]
name = "turbo-tasks-build" name = "turbo-tasks-build"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"cargo-lock", "cargo-lock",
...@@ -7418,7 +7418,7 @@ dependencies = [ ...@@ -7418,7 +7418,7 @@ dependencies = [
[[package]] [[package]]
name = "turbo-tasks-bytes" name = "turbo-tasks-bytes"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
...@@ -7433,7 +7433,7 @@ dependencies = [ ...@@ -7433,7 +7433,7 @@ dependencies = [
[[package]] [[package]]
name = "turbo-tasks-env" name = "turbo-tasks-env"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"dotenvs", "dotenvs",
...@@ -7447,7 +7447,7 @@ dependencies = [ ...@@ -7447,7 +7447,7 @@ dependencies = [
[[package]] [[package]]
name = "turbo-tasks-fetch" name = "turbo-tasks-fetch"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"indexmap 1.9.3", "indexmap 1.9.3",
...@@ -7464,7 +7464,7 @@ dependencies = [ ...@@ -7464,7 +7464,7 @@ dependencies = [
[[package]] [[package]]
name = "turbo-tasks-fs" name = "turbo-tasks-fs"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"auto-hash-map", "auto-hash-map",
...@@ -7496,7 +7496,7 @@ dependencies = [ ...@@ -7496,7 +7496,7 @@ dependencies = [
[[package]] [[package]]
name = "turbo-tasks-hash" name = "turbo-tasks-hash"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"base16", "base16",
"hex", "hex",
...@@ -7508,7 +7508,7 @@ dependencies = [ ...@@ -7508,7 +7508,7 @@ dependencies = [
[[package]] [[package]]
name = "turbo-tasks-macros" name = "turbo-tasks-macros"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"convert_case 0.6.0", "convert_case 0.6.0",
...@@ -7522,7 +7522,7 @@ dependencies = [ ...@@ -7522,7 +7522,7 @@ dependencies = [
[[package]] [[package]]
name = "turbo-tasks-macros-shared" name = "turbo-tasks-macros-shared"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
...@@ -7532,7 +7532,7 @@ dependencies = [ ...@@ -7532,7 +7532,7 @@ dependencies = [
[[package]] [[package]]
name = "turbo-tasks-malloc" name = "turbo-tasks-malloc"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"mimalloc", "mimalloc",
] ]
...@@ -7540,7 +7540,7 @@ dependencies = [ ...@@ -7540,7 +7540,7 @@ dependencies = [
[[package]] [[package]]
name = "turbo-tasks-memory" name = "turbo-tasks-memory"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"auto-hash-map", "auto-hash-map",
...@@ -7565,7 +7565,7 @@ dependencies = [ ...@@ -7565,7 +7565,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack" name = "turbopack"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-recursion", "async-recursion",
...@@ -7598,7 +7598,7 @@ dependencies = [ ...@@ -7598,7 +7598,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-binding" name = "turbopack-binding"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"auto-hash-map", "auto-hash-map",
"mdxjs", "mdxjs",
...@@ -7638,7 +7638,7 @@ dependencies = [ ...@@ -7638,7 +7638,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-build" name = "turbopack-build"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"indexmap 1.9.3", "indexmap 1.9.3",
...@@ -7663,7 +7663,7 @@ dependencies = [ ...@@ -7663,7 +7663,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-cli-utils" name = "turbopack-cli-utils"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap 4.4.2", "clap 4.4.2",
...@@ -7682,7 +7682,7 @@ dependencies = [ ...@@ -7682,7 +7682,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-core" name = "turbopack-core"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-recursion", "async-recursion",
...@@ -7713,7 +7713,7 @@ dependencies = [ ...@@ -7713,7 +7713,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-css" name = "turbopack-css"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
...@@ -7741,7 +7741,7 @@ dependencies = [ ...@@ -7741,7 +7741,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-dev" name = "turbopack-dev"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"indexmap 1.9.3", "indexmap 1.9.3",
...@@ -7767,7 +7767,7 @@ dependencies = [ ...@@ -7767,7 +7767,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-dev-server" name = "turbopack-dev-server"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-compression", "async-compression",
...@@ -7804,7 +7804,7 @@ dependencies = [ ...@@ -7804,7 +7804,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-ecmascript" name = "turbopack-ecmascript"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
...@@ -7841,7 +7841,7 @@ dependencies = [ ...@@ -7841,7 +7841,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-ecmascript-hmr-protocol" name = "turbopack-ecmascript-hmr-protocol"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
...@@ -7852,7 +7852,7 @@ dependencies = [ ...@@ -7852,7 +7852,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-ecmascript-plugins" name = "turbopack-ecmascript-plugins"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
...@@ -7877,7 +7877,7 @@ dependencies = [ ...@@ -7877,7 +7877,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-ecmascript-runtime" name = "turbopack-ecmascript-runtime"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"indoc", "indoc",
...@@ -7894,7 +7894,7 @@ dependencies = [ ...@@ -7894,7 +7894,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-env" name = "turbopack-env"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"indexmap 1.9.3", "indexmap 1.9.3",
...@@ -7910,7 +7910,7 @@ dependencies = [ ...@@ -7910,7 +7910,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-image" name = "turbopack-image"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64 0.21.4", "base64 0.21.4",
...@@ -7930,7 +7930,7 @@ dependencies = [ ...@@ -7930,7 +7930,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-json" name = "turbopack-json"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"serde", "serde",
...@@ -7945,7 +7945,7 @@ dependencies = [ ...@@ -7945,7 +7945,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-mdx" name = "turbopack-mdx"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"mdxjs", "mdxjs",
...@@ -7960,10 +7960,11 @@ dependencies = [ ...@@ -7960,10 +7960,11 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-node" name = "turbopack-node"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-stream", "async-stream",
"async-trait",
"bytes", "bytes",
"const_format", "const_format",
"futures", "futures",
...@@ -7989,6 +7990,7 @@ dependencies = [ ...@@ -7989,6 +7990,7 @@ dependencies = [
"turbopack-core", "turbopack-core",
"turbopack-dev-server", "turbopack-dev-server",
"turbopack-ecmascript", "turbopack-ecmascript",
"turbopack-resolve",
"url", "url",
"urlencoding", "urlencoding",
] ]
...@@ -7996,7 +7998,7 @@ dependencies = [ ...@@ -7996,7 +7998,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-resolve" name = "turbopack-resolve"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-recursion", "async-recursion",
...@@ -8018,7 +8020,7 @@ dependencies = [ ...@@ -8018,7 +8020,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-static" name = "turbopack-static"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"serde", "serde",
...@@ -8034,7 +8036,7 @@ dependencies = [ ...@@ -8034,7 +8036,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-swc-utils" name = "turbopack-swc-utils"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"swc_core", "swc_core",
"turbo-tasks", "turbo-tasks",
...@@ -8045,7 +8047,7 @@ dependencies = [ ...@@ -8045,7 +8047,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-trace-utils" name = "turbopack-trace-utils"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"crossbeam-channel", "crossbeam-channel",
...@@ -8061,7 +8063,7 @@ dependencies = [ ...@@ -8061,7 +8063,7 @@ dependencies = [
[[package]] [[package]]
name = "turbopack-wasm" name = "turbopack-wasm"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.1#b61c98e970cc7a39fbaf439997cc156afad17b08" source = "git+https://github.com/vercel/turbo.git?tag=turbopack-240304.2#42c4de5adeff568e9c372cdf553ecb5867b1a6a7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"indexmap 1.9.3", "indexmap 1.9.3",
......
...@@ -37,11 +37,11 @@ swc_core = { version = "0.90.12", features = [ ...@@ -37,11 +37,11 @@ swc_core = { version = "0.90.12", features = [
testing = { version = "0.35.19" } testing = { version = "0.35.19" }
# Turbo crates # 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.. # [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 # [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 # General Deps
......
use std::mem::take;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
use turbo_tasks::Vc; use turbo_tasks::Vc;
...@@ -32,17 +34,28 @@ pub async fn maybe_add_sass_loader( ...@@ -32,17 +34,28 @@ pub async fn maybe_add_sass_loader(
.get("prependData") .get("prependData")
.or(sass_options.get("additionalData")); .or(sass_options.get("additionalData"));
let rule = rules.get_mut(pattern); let rule = rules.get_mut(pattern);
let loader = WebpackLoaderItem { let sass_loader = WebpackLoaderItem {
loader: "next/dist/compiled/sass-loader".to_string(), loader: "next/dist/compiled/sass-loader".to_string(),
options: serde_json::json!({ options: take(
//https://github.com/vercel/turbo/blob/d527eb54be384a4658243304cecd547d09c05c6b/crates/turbopack-node/src/transforms/webpack.rs#L191 serde_json::json!({
"sourceMap": false, "sourceMap": true,
"sassOptions": sass_options, "sassOptions": sass_options,
"additionalData": additional_data "additionalData": additional_data
}) })
.as_object() .as_object_mut()
.unwrap() .unwrap(),
.clone(), ),
};
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 { if let Some(rule) = rule {
...@@ -57,13 +70,14 @@ pub async fn maybe_add_sass_loader( ...@@ -57,13 +70,14 @@ pub async fn maybe_add_sass_loader(
continue; continue;
} }
let mut loaders = rule.loaders.await?.clone_value(); 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); rule.loaders = Vc::cell(loaders);
} else { } else {
rules.insert( rules.insert(
pattern.to_string(), pattern.to_string(),
LoaderRuleItem { LoaderRuleItem {
loaders: Vc::cell(vec![loader]), loaders: Vc::cell(vec![resolve_url_loader, sass_loader]),
rename_as: Some(format!("*{rename}")), rename_as: Some(format!("*{rename}")),
}, },
); );
......
...@@ -192,7 +192,7 @@ ...@@ -192,7 +192,7 @@
"@types/ws": "8.2.0", "@types/ws": "8.2.0",
"@vercel/ncc": "0.34.0", "@vercel/ncc": "0.34.0",
"@vercel/nft": "0.26.4", "@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", "acorn": "8.5.0",
"amphtml-validator": "1.0.35", "amphtml-validator": "1.0.35",
"anser": "1.4.9", "anser": "1.4.9",
......
...@@ -56,7 +56,9 @@ export default async function resolveUrlLoader( ...@@ -56,7 +56,9 @@ export default async function resolveUrlLoader(
} }
const callback = this.async() const callback = this.async()
const { postcss } = await options.postcss() const { postcss } = options.postcss
? await options.postcss()
: { postcss: require('postcss') }
process(postcss, this.resourcePath, content, { process(postcss, this.resourcePath, content, {
outputSourceMap: Boolean(options.sourceMap), outputSourceMap: Boolean(options.sourceMap),
transformDeclaration: valueProcessor(this.resourcePath, options), transformDeclaration: valueProcessor(this.resourcePath, options),
......
...@@ -35,9 +35,11 @@ export default function process( ...@@ -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) // #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 // prepend file protocol to all sources to avoid problems with source map
// eslint-disable-next-line @typescript-eslint/no-use-before-define // eslint-disable-next-line @typescript-eslint/no-use-before-define
return postcss([postcss.plugin('postcss-resolve-url', postcssPlugin)]) return postcss([postcssPlugin])
.process(sourceContent, { .process(sourceContent, {
from: prepend(sourceFile), from: prepend(sourceFile),
map: params.outputSourceMap && { map: params.outputSourceMap && {
...@@ -56,9 +58,12 @@ export default function process( ...@@ -56,9 +58,12 @@ export default function process(
* Plugin for postcss that follows SASS transpilation. * Plugin for postcss that follows SASS transpilation.
*/ */
function postcssPlugin() { function postcssPlugin() {
return function (styles: any) { return {
// eslint-disable-next-line @typescript-eslint/no-use-before-define postcssPlugin: 'postcss-resolve-url',
styles.walkDecls(eachDeclaration) Once: function (root: any) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
root.walkDecls(eachDeclaration)
},
} }
/** /**
......
...@@ -1074,8 +1074,8 @@ importers: ...@@ -1074,8 +1074,8 @@ importers:
specifier: 0.26.4 specifier: 0.26.4
version: 0.26.4 version: 0.26.4
'@vercel/turbopack-ecmascript-runtime': '@vercel/turbopack-ecmascript-runtime':
specifier: https://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.1' version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240304.2'
acorn: acorn:
specifier: 8.5.0 specifier: 8.5.0
version: 8.5.0 version: 8.5.0
...@@ -25728,8 +25728,8 @@ packages: ...@@ -25728,8 +25728,8 @@ packages:
/zwitch@2.0.4: /zwitch@2.0.4:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
'@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.1} resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240304.2}
name: '@vercel/turbopack-ecmascript-runtime' name: '@vercel/turbopack-ecmascript-runtime'
version: 0.0.0 version: 0.0.0
dependencies: 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 @@ ...@@ -4,14 +4,13 @@
.foo :global(.bar), .foo :global(.bar),
.foo :global(.baz) { .foo :global(.baz) {
height: 100%; background-color: blue;
overflow: hidden;
} }
.foo :global(.lol) { .foo :global(.lol) {
width: 80%; background-color: red;
} }
.foo > :global(.lel) { .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 */ /* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra' import { nextTestSetup } from 'e2e-utils'
import { nextBuild } from 'next-test-utils' import { readdir, readFile } from 'fs-extra'
import { join } from 'path' import { join } from 'path'
describe('SCSS Support', () => { describe('SCSS Support', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => { const { next, isNextDev } = nextTestSetup({
describe('CSS Compilation and Prefixing', () => { files: __dirname,
const appDir = __dirname dependencies: {
sass: '1.54.0',
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/)
})
// 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 () => { 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 files = await readdir(cssFolder)
const cssFiles = files.filter((f) => /\.css$/.test(f)) const cssFiles = files.filter((f) => /\.css$/.test(f))
...@@ -36,11 +30,12 @@ describe('SCSS Support', () => { ...@@ -36,11 +30,12 @@ describe('SCSS Support', () => {
) )
// 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 () => { 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 files = await readdir(cssFolder)
const cssMapFiles = files.filter((f) => /\.css\.map$/.test(f)) const cssMapFiles = files.filter((f) => /\.css\.map$/.test(f))
...@@ -52,24 +47,24 @@ describe('SCSS Support', () => { ...@@ -52,24 +47,24 @@ describe('SCSS Support', () => {
const { version, mappings, sourcesContent } = JSON.parse(cssMapContent) const { version, mappings, sourcesContent } = JSON.parse(cssMapContent)
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(` expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(`
{ {
"mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA", "mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA",
"sourcesContent": [ "sourcesContent": [
"$var: red; "$var: red;
.redText { .redText {
::placeholder { ::placeholder {
color: $var; color: $var;
}
} }
}
.flex-parsing {
.flex-parsing { flex: 0 0 calc(50% - var(--vertical-gutter));
flex: 0 0 calc(50% - var(--vertical-gutter)); }
} ",
", ],
], "version": 3,
"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; $var: blue;
.subClass { .subClass {
composes: className from './other.scss'; composes: className from './other.module.scss';
background: $var; 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'))
})
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Nested @import() 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('.red-text').getComputedCss('color')
).toBe(colorToRgb('red'))
expect(
await browser.elementByCss('.blue-text').getComputedCss('color')
).toBe(colorToRgb('blue'))
})
})
export default function Home() {
return (
<>
<div className="red-text">This text should be red.</div>
<div className="blue-text">This text should be blue.</div>
</>
)
}
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Valid Nested CSS Module Usage from within node_modules', () => {
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('#other2').getComputedCss('color')).toBe(
colorToRgb('red')
)
expect(await browser.elementByCss('#other3').getComputedCss('color')).toBe(
colorToRgb('black')
)
expect(
await browser.elementByCss('#subclass').getComputedCss('color')
).toBe(colorToRgb('yellow'))
expect(
await browser.elementByCss('#subclass').getComputedCss('background-color')
).toBe(colorToRgb('blue'))
})
})
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
$var: blue; $var: blue;
.subClass { .subClass {
composes: className from './other.scss'; composes: className from './other.module.scss';
background: $var; background: $var;
} }
...@@ -4,6 +4,16 @@ import * as classes from 'example/index.module.scss' ...@@ -4,6 +4,16 @@ import * as classes from 'example/index.module.scss'
function Home() { function Home() {
return ( return (
<div id="nm-div"> <div id="nm-div">
<div className={classes.other2} id="other2">
Other 2
</div>
{/* Does not exist */}
<div className={classes.other3} id="other3">
Other 3
</div>
<div className={classes.subClass} id="subclass">
Sub class
</div>
{JSON.stringify(data)} {JSON.stringify(classes)} {JSON.stringify(data)} {JSON.stringify(classes)}
</div> </div>
) )
......
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Valid CSS Module Usage from within node_modules', () => {
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('#nm-div').getComputedCss('color')).toBe(
colorToRgb('red')
)
})
})
...@@ -3,7 +3,7 @@ import * as classes from 'example/index.module.scss' ...@@ -3,7 +3,7 @@ import * as classes from 'example/index.module.scss'
function Home() { function Home() {
return ( return (
<div id="nm-div"> <div id="nm-div" className={classes['red-text']}>
{JSON.stringify(data)} {JSON.stringify(classes)} {JSON.stringify(data)} {JSON.stringify(classes)}
</div> </div>
) )
......
...@@ -3,22 +3,28 @@ ...@@ -3,22 +3,28 @@
import { remove } from 'fs-extra' import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils' import { nextBuild } from 'next-test-utils'
import { join } from 'path' import { join } from 'path'
// In order for the global isNextStart to be set
import 'e2e-utils'
describe('SCSS Support loader handling', () => { console.log({ global })
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('Preprocessor loader order', () => { describe('CSS Import from node_modules', () => {
;(Boolean((global as any).isNextStart) ? describe : describe.skip)(
'production only',
() => {
const appDir = __dirname const appDir = __dirname
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
it('should compile successfully', async () => {
const { stdout } = await nextBuild(appDir, [], { it('should fail the build', async () => {
stdout: true, const { code, stderr } = await nextBuild(appDir, [], { stderr: true })
})
// eslint-disable-next-line expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/) expect(stderr).not.toMatch(/Can't resolve '[^']*?nprogress[^']*?'/)
expect(stderr).not.toMatch(/Build error occurred/)
}) })
}) }
}) )
}) })
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Good Nested CSS Import from node_modules', () => {
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('.red-text').getComputedCss('color')
).toBe(colorToRgb('red'))
expect(
await browser.elementByCss('.blue-text').getComputedCss('color')
).toBe(colorToRgb('blue'))
})
})
export default function Home() {
return (
<>
<div className="red-text">This text should be red.</div>
<div className="blue-text">This text should be blue.</div>
</>
)
}
@import 'example/test.scss';
.test {
background: red;
}
module.exports = {
experimental: {
turbo: {
resolveAlias: {
'~*': '*',
},
},
},
}
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
describe('Good CSS Import from node_modules with tilde', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
nprogress: '0.2.0',
},
})
it('should render the page', async () => {
const browser = await next.browser('/')
expect(
await browser
.elementByCss('#nprogress .bar')
.getComputedCss('background-color')
).toBe('rgb(34, 153, 221)')
})
})
export default function Home() {
return (
<div id="nprogress">
<div className="bar">The text.</div>
</div>
)
}
@import '~nprogress/nprogress.css'; @import '~nprogress/nprogress.css';
.test {
background: 'red';
}
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
describe('Good CSS Import from node_modules', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
nprogress: '0.2.0',
},
})
it('should render the page', async () => {
const browser = await next.browser('/')
expect(
await browser
.elementByCss('#nprogress .bar')
.getComputedCss('background-color')
).toBe('rgb(34, 153, 221)')
})
})
export default function Home() {
return (
<div id="nprogress">
<div className="bar">The text.</div>
</div>
)
}
@import 'nprogress/nprogress.css';
.test {
background: red;
}
import { redText } from './index.module.scss'
export default function Home() {
return (
<div id="verify-red" className={redText}>
This text should be red.
</div>
)
}
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Has CSS Module in computed styles in Production', () => {
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'))
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Basic Global Support with src/ dir', () => {
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('.red-text').getComputedCss('color')
).toBe(colorToRgb('red'))
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Basic Global Support scss', () => {
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('.red-text').getComputedCss('color')
).toBe(colorToRgb('red'))
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
describe('unused scss', () => {
describe('Body is not hidden when unused in Development', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
;(isNextDev ? describe : describe.skip)('development only', () => {
it('should have body visible', async () => {
const browser = await next.browser('/')
const currentDisplay = await browser.eval(
`window.getComputedStyle(document.querySelector('body')).display`
)
expect(currentDisplay).toBe('block')
})
})
})
describe('Body is not hidden when broken in Development', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
;(isNextDev ? describe : describe.skip)('development only', () => {
it('should have body visible', async () => {
await next.patchFile('pages/index.js', (contents) => {
return contents.replace('<div />', '<div>')
})
const browser = await next.browser('/')
const currentDisplay = await browser.eval(
`window.getComputedStyle(document.querySelector('body')).display`
)
expect(currentDisplay).toBe('block')
})
})
})
})
const config = require('../next.config.js')
module.exports = { module.exports = {
...config,
assetPrefix: '/foo/', assetPrefix: '/foo/',
} }
$var: red;
.red-text {
color: $var;
background-image: url('./dark.svg'), url(dark2.svg);
}
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb, getUrlFromBackgroundImage } from 'next-test-utils'
// TODO: Skipped as this test should set up the server to handle assetPrefix which it currently does not do.
describe.skip('SCSS Support loader handling', () => {
describe('CSS URL via `file-loader` and asset prefix (1)', () => {
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('.red-text').getComputedCss('color')
).toBe(colorToRgb('red'))
const background = await browser
.elementByCss('.red-text')
.getComputedCss('background-image')
expect(background).toMatch(
/url\(".*\/foo\/_next\/static\/media\/dark\..*\.svg"\), url\(".*\/foo\/_next\/static\/media\/dark2\..*\.svg"\)/
)
const urls = getUrlFromBackgroundImage(background)
for (const url of urls) {
const response = await next.fetch(url)
expect(response.status).toBe(200)
}
})
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb, getUrlFromBackgroundImage } from 'next-test-utils'
// TODO: Skipped as this test should set up the server to handle assetPrefix which it currently does not do.
describe.skip('SCSS Support loader handling', () => {
describe('CSS URL via `file-loader` and asset prefix (2)', () => {
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('.red-text').getComputedCss('color')
).toBe(colorToRgb('red'))
const background = await browser
.elementByCss('.red-text')
.getComputedCss('background-image')
expect(background).toMatch(
/url\(".*\/foo\/_next\/static\/media\/dark\..*\.svg"\), url\(".*\/foo\/_next\/static\/media\/dark2\..*\.svg"\)/
)
const urls = getUrlFromBackgroundImage(background)
for (const url of urls) {
const response = await next.fetch(url)
expect(response.status).toBe(200)
}
})
})
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb, getUrlFromBackgroundImage } from 'next-test-utils'
describe('SCSS Support loader handling', () => {
describe('CSS URL via file-loader sass partial', () => {
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('.red-text').getComputedCss('color')
).toBe(colorToRgb('red'))
const background = await browser
.elementByCss('.red-text')
.getComputedCss('background-image')
expect(background).toMatch(
/url\(".*\/_next\/static\/media\/darka\..*\.svg"\), url\(".*\/_next\/static\/media\/darkb\..*\.svg"\)/
)
const urls = getUrlFromBackgroundImage(background)
for (const url of urls) {
const response = await next.fetch(url)
expect(response.status).toBe(200)
}
})
})
})
$var: red;
.red-text {
color: $var;
background-image: url('./dark.svg'), url(dark2.svg);
}
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb, getUrlFromBackgroundImage } from 'next-test-utils'
describe('SCSS Support loader handling', () => {
describe('CSS URL via `file-loader`', () => {
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('.red-text').getComputedCss('color')
).toBe(colorToRgb('red'))
const background = await browser
.elementByCss('.red-text')
.getComputedCss('background-image')
expect(background).toMatch(
/url\(".*\/_next\/static\/media\/dark\..*\.svg"\), url\(".*\/_next\/static\/media\/dark2\..*\.svg"\)/
)
const urls = getUrlFromBackgroundImage(background)
for (const url of urls) {
const response = await next.fetch(url)
expect(response.status).toBe(200)
}
})
})
})
/* 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('Valid and 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).toContain(
'Please move all first-party global CSS imports'
)
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'
import { quote as shellQuote } from 'shell-quote'
// In order for the global isNextStart to be set
import 'e2e-utils'
describe('SCSS Support', () => {
;(Boolean((global as any).isNextStart) ? describe : describe.skip)(
'production only',
() => {
describe('Friendly Webpack Error', () => {
const appDir = __dirname
const mockFile = join(appDir, 'mock.js')
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should be a friendly error successfully', async () => {
const { code, stderr } = await nextBuild(appDir, [], {
env: { NODE_OPTIONS: shellQuote([`--require`, mockFile]) },
stderr: true,
})
let cleanScssErrMsg =
'\n\n' +
'./styles/global.scss\n' +
"To use Next.js' built-in Sass support, you first need to install `sass`.\n" +
'Run `npm i sass` or `yarn add sass` inside your workspace.\n' +
'\n' +
'Learn more: https://nextjs.org/docs/messages/install-sass\n'
// eslint-disable-next-line
expect(code).toBe(1)
// eslint-disable-next-line
expect(stderr).toContain('Failed to compile.')
// eslint-disable-next-line
expect(stderr).toContain(cleanScssErrMsg)
// eslint-disable-next-line
expect(stderr).not.toContain('css-loader')
// eslint-disable-next-line
expect(stderr).not.toContain('sass-loader')
})
})
}
)
})
import React from 'react'
import App from 'next/app'
import '../styles/global.scss'
class MyApp extends App {
render() {
const { Component, pageProps } = this.props
return <Component {...pageProps} />
}
}
export default MyApp
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe('Ordering with styled-jsx', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
sass: '1.54.0',
},
})
it('should have the correct color (css ordering)', async () => {
const browser = await next.browser('/')
expect(await browser.elementByCss('.my-text').getComputedCss('color')).toBe(
colorToRgb('green')
)
})
})
/* eslint-env jest */
import cheerio from 'cheerio'
import { readdir, readFile, remove } from 'fs-extra'
import {
findPort,
killApp,
nextBuild,
nextStart,
renderViaHTTP,
} from 'next-test-utils'
import { join } from 'path'
describe('3rd Party CSS Module Support', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = __dirname
let appPort
let app
let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
;({ code, stdout } = await nextBuild(appDir, [], {
stdout: true,
}))
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
it('should have compiled successfully', () => {
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
})
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(
`".index_foo__72b4D{position:relative}.index_foo__72b4D .bar,.index_foo__72b4D .baz{height:100%;overflow:hidden}.index_foo__72b4D .lol,.index_foo__72b4D>.lel{width:80%}"`
)
})
it(`should've injected the CSS on server render`, async () => {
const content = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(content)
const cssPreload = $('link[rel="preload"][as="style"]')
expect(cssPreload.length).toBe(1)
expect(cssPreload.attr('href')).toMatch(/^\/_next\/static\/css\/.*\.css$/)
const cssSheet = $('link[rel="stylesheet"]')
expect(cssSheet.length).toBe(1)
expect(cssSheet.attr('href')).toMatch(/^\/_next\/static\/css\/.*\.css$/)
expect($('#verify-div').attr('class')).toMatchInlineSnapshot(
`"index_foo__72b4D"`
)
})
})
})
import { foo } from './index.module.scss'
export default function Home() {
return <div id="verify-div" className={foo} />
}
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('Basic Module Include Paths Support', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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/)
})
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)
expect(await readFile(join(cssFolder, cssFiles[0]), 'utf8')).toContain(
'color:red'
)
})
})
})
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('Basic Module Prepend Data Support', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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/)
})
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)
expect(await readFile(join(cssFolder, cssFiles[0]), 'utf8')).toContain(
'color:red'
)
})
})
})
/* eslint-env jest */
import cheerio from 'cheerio'
import { readdir, readFile, remove } from 'fs-extra'
import {
findPort,
killApp,
nextBuild,
nextStart,
renderViaHTTP,
} from 'next-test-utils'
import { join } from 'path'
describe('Basic SCSS Module Support', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = __dirname
let appPort
let app
let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
;({ code, stdout } = await nextBuild(appDir, [], {
stdout: true,
}))
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
it('should have compiled successfully', () => {
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
})
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(`".index_redText__zXafh{color:red}"`)
})
it(`should've injected the CSS on server render`, async () => {
const content = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(content)
const cssPreload = $('link[rel="preload"][as="style"]')
expect(cssPreload.length).toBe(1)
expect(cssPreload.attr('href')).toMatch(/^\/_next\/static\/css\/.*\.css$/)
const cssSheet = $('link[rel="stylesheet"]')
expect(cssSheet.length).toBe(1)
expect(cssSheet.attr('href')).toMatch(/^\/_next\/static\/css\/.*\.css$/)
expect($('#verify-red').attr('class')).toMatchInlineSnapshot(
`"index_redText__zXafh"`
)
})
})
})
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { findPort, killApp, nextBuild, nextStart } from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'
describe('Catch-all Route CSS Module Usage', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = __dirname
let stdout
let code
let app
let appPort
beforeAll(async () => {
await remove(join(appDir, '.next'))
;({ code, stdout } = await nextBuild(appDir, [], {
stdout: true,
}))
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
it('should have compiled successfully', () => {
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
})
it('should apply styles correctly', async () => {
const browser = await webdriver(appPort, '/post-1')
const background = await browser
.elementByCss('#my-div')
.getComputedCss('background-color')
expect(background).toMatch(/rgb(a|)\(255, 0, 0/)
})
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(`".___post__home__bZNj1{background:red}"`)
})
})
})
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('CSS Module Composes Usage (Basic)', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
// This is a very bad feature. Do not use it.
const appDir = __dirname
let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
;({ code, stdout } = await nextBuild(appDir, [], {
stdout: true,
}))
})
it('should have compiled successfully', () => {
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
})
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(
`".index_className__OLWEh{background:red;color:#ff0}.index_subClass__Z_IFg{background:blue}"`
)
})
})
})
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('CSS Module Composes Usage (External)', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
// This is a very bad feature. Do not use it.
const appDir = __dirname
let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
;({ code, stdout } = await nextBuild(appDir, [], {
stdout: true,
}))
})
it('should have compiled successfully', () => {
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
})
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(
`".other_className__A8aN2{background:red;color:#ff0}.index_subClass__Z_IFg{background:blue}"`
)
})
})
})
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('SCSS Support loader handling', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('Data Urls', () => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should compile successfully', async () => {
const { code, stdout } = await nextBuild(appDir, [], {
stdout: true,
})
// eslint-disable-next-line
expect(code).toBe(0)
// eslint-disable-next-line
expect(stdout).toMatch(/Compiled successfully/)
})
it(`should've emitted expected files`, 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()).toMatch(
/^\.red-text\{color:red;background-image:url\("data:[^"]+"\)\}$/
)
})
})
})
})
/* eslint-env jest */
import { remove } from 'fs-extra'
import { findPort, killApp, launchApp } from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'
describe('Has CSS Module in computed styles in Development', () => {
const appDir = __dirname
let appPort
let app
beforeAll(async () => {
await remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
it('should have CSS for page', async () => {
const browser = await webdriver(appPort, '/')
const currentColor = await browser.eval(
`window.getComputedStyle(document.querySelector('#verify-red')).color`
)
expect(currentColor).toMatchInlineSnapshot(`"rgb(255, 0, 0)"`)
})
})
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { findPort, killApp, nextBuild, nextStart } from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'
describe('Dynamic Route CSS Module Usage', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = __dirname
let stdout
let code
let app
let appPort
beforeAll(async () => {
await remove(join(appDir, '.next'))
;({ code, stdout } = await nextBuild(appDir, [], {
stdout: true,
}))
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
it('should have compiled successfully', () => {
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
})
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(`"._post__home__ZI5mq{background:red}"`)
})
it('should apply styles correctly', async () => {
const browser = await webdriver(appPort, '/post-1')
const background = await browser
.elementByCss('#my-div')
.getComputedCss('background-color')
expect(background).toMatch(/rgb(a|)\(255, 0, 0/)
})
})
})
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('SCSS Support loader handling', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('External imports', () => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should compile successfully', async () => {
const { code, stdout } = await nextBuild(appDir, [], {
stdout: true,
})
// eslint-disable-next-line
expect(code).toBe(0)
// eslint-disable-next-line
expect(stdout).toMatch(/Compiled successfully/)
})
it(`should've emitted expected files`, 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()).toMatch(
/^@import"https:\/\/fonts\.googleapis\.com\/css2\?family=Poppins:wght@400&display=swap";\.red-text\{color:red;font-family:Poppins;font-style:normal;font-weight:400\}$/
)
})
})
})
})
/* eslint-env jest */
import { remove } from 'fs-extra'
import { File, findPort, killApp, launchApp, waitFor } from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'
describe('Can hot reload CSS Module without losing state', () => {
const appDir = __dirname
let appPort
let app
beforeAll(async () => {
await remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
it('should update CSS color without remounting <input>', async () => {
const browser = await webdriver(appPort, '/')
const desiredText = 'hello world'
await browser.elementById('text-input').type(desiredText)
expect(await browser.elementById('text-input').getValue()).toBe(desiredText)
const currentColor = await browser.eval(
`window.getComputedStyle(document.querySelector('#verify-red')).color`
)
expect(currentColor).toMatchInlineSnapshot(`"rgb(255, 0, 0)"`)
const cssFile = new File(join(appDir, 'pages/index.module.scss'))
try {
cssFile.replace('$var: red', '$var: purple')
await waitFor(2000) // wait for HMR
const refreshedColor = await browser.eval(
`window.getComputedStyle(document.querySelector('#verify-red')).color`
)
expect(refreshedColor).toMatchInlineSnapshot(`"rgb(128, 0, 128)"`)
// ensure text remained
expect(await browser.elementById('text-input').getValue()).toBe(
desiredText
)
} finally {
cssFile.restore()
}
})
})
/* eslint-env jest */
import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe.skip('Invalid CSS Global Module Usage in node_modules', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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'
describe('Invalid Global CSS with Custom App', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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'
describe('Invalid Global CSS', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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'
describe('Invalid SCSS in _document', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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'
describe.skip('Invalid CSS Module Usage in node_modules', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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 { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
// Tests css ordering
describe('Multi Global Support (reversed)', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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/)
})
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(`".blue-text{color:blue}.red-text{color:red}"`)
})
})
})
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('Multi Global Support', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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/)
})
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(`".red-text{color:red}.blue-text{color:blue}"`)
})
})
})
import Link from 'next/link'
import { blueText } from './blue.module.scss'
export default function Blue() {
return (
<>
<div id="verify-blue" className={blueText}>
This text should be blue.
</div>
<br />
<Link href="/red" prefetch id="link-red">
Red
</Link>
<br />
<Link href="/none" prefetch={false} id="link-none">
None
</Link>
</>
)
}
import Link from 'next/link'
export default function None() {
return (
<>
<div id="verify-black" style={{ color: 'black' }}>
This text should be black.
</div>
<br />
<Link href="/red" prefetch={false} id="link-red">
Red
</Link>
<br />
<Link href="/blue" prefetch={false} id="link-blue">
Blue
</Link>
</>
)
}
import Link from 'next/link'
import { redText } from './red.module.scss'
export default function Red() {
return (
<>
<div id="verify-red" className={redText}>
This text should be red.
</div>
<br />
<Link href="/blue" prefetch={false} id="link-blue">
Blue
</Link>
<br />
<Link href="/none" prefetch={false} id="link-none">
None
</Link>
</>
)
}
/* eslint-env jest */
import cheerio from 'cheerio'
import { remove } from 'fs-extra'
import {
findPort,
killApp,
launchApp,
nextBuild,
nextStart,
renderViaHTTP,
waitFor,
File,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'
describe('SCSS Support', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('Has CSS in computed styles in Production', () => {
const appDir = __dirname
let appPort
let app
let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
;({ code, stdout } = await nextBuild(appDir, [], {
stdout: true,
}))
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
it('should have compiled successfully', () => {
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
})
it('should have CSS for page', async () => {
const browser = await webdriver(appPort, '/page2')
const currentColor = await browser.eval(
`window.getComputedStyle(document.querySelector('.blue-text')).color`
)
expect(currentColor).toMatchInlineSnapshot(`"rgb(0, 0, 255)"`)
})
it(`should've preloaded the CSS file and injected it in <head>`, async () => {
const content = await renderViaHTTP(appPort, '/page2')
const $ = cheerio.load(content)
const cssPreload = $('link[rel="preload"][as="style"]')
expect(cssPreload.length).toBe(1)
expect(cssPreload.attr('href')).toMatch(
/^\/_next\/static\/css\/.*\.css$/
)
const cssSheet = $('link[rel="stylesheet"]')
expect(cssSheet.length).toBe(1)
expect(cssSheet.attr('href')).toMatch(/^\/_next\/static\/css\/.*\.css$/)
/* ensure CSS preloaded first */
const allPreloads = [].slice.call($('link[rel="preload"]'))
const styleIndexes = allPreloads.flatMap((p, i) =>
p.attribs.as === 'style' ? i : []
)
expect(styleIndexes).toEqual([0])
})
})
})
describe('development mode', () => {
describe('Can hot reload CSS without losing state', () => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
let appPort
let app
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
it('should update CSS color without remounting <input>', async () => {
let browser
try {
browser = await webdriver(appPort, '/page1')
const desiredText = 'hello world'
await browser.elementById('text-input').type(desiredText)
expect(await browser.elementById('text-input').getValue()).toBe(
desiredText
)
const currentColor = await browser.eval(
`window.getComputedStyle(document.querySelector('.red-text')).color`
)
expect(currentColor).toMatchInlineSnapshot(`"rgb(255, 0, 0)"`)
const cssFile = new File(join(appDir, 'styles/global1.scss'))
try {
cssFile.replace('$var: red', '$var: purple')
await waitFor(2000) // wait for HMR
const refreshedColor = await browser.eval(
`window.getComputedStyle(document.querySelector('.red-text')).color`
)
expect(refreshedColor).toMatchInlineSnapshot(`"rgb(128, 0, 128)"`)
// ensure text remained
expect(await browser.elementById('text-input').getValue()).toBe(
desiredText
)
} finally {
cssFile.restore()
}
} finally {
if (browser) {
await browser.close()
}
}
})
})
})
describe('Has CSS in computed styles in Development', () => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
let appPort
let app
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
it('should have CSS for page', async () => {
let browser
try {
browser = await webdriver(appPort, '/page2')
const currentColor = await browser.eval(
`window.getComputedStyle(document.querySelector('.blue-text')).color`
)
expect(currentColor).toMatchInlineSnapshot(`"rgb(0, 0, 255)"`)
} finally {
if (browser) {
await browser.close()
}
}
})
})
})
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('Nested @import() Global Support', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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/)
})
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(
`".red-text{color:purple;font-weight:bolder;color:red}.blue-text{color:orange;font-weight:bolder;color:blue}"`
)
})
})
})
/* eslint-env jest */
import cheerio from 'cheerio'
import { readdir, readFile, remove } from 'fs-extra'
import {
findPort,
killApp,
nextBuild,
nextStart,
renderViaHTTP,
} from 'next-test-utils'
import { join } from 'path'
describe('Valid Nested CSS Module Usage from within node_modules', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
let appPort
let app
let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
;({ code, stdout } = await nextBuild(appDir, [], {
stdout: true,
}))
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
it('should have compiled successfully', () => {
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
})
it(`should've prerendered with relevant data`, async () => {
const content = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(content)
const cssPreload = $('#nm-div')
expect(cssPreload.text()).toMatchInlineSnapshot(
`"{"message":"Why hello there"} {"other2":"example_other2__HNcoQ","subClass":"example_subClass__SxkPt other_className___l2o_"}"`
)
})
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(
`".other_other3__DvhyB{color:violet}.other_className___l2o_{background:red;color:#ff0}.example_other2__HNcoQ{color:red}.example_subClass__SxkPt{background:blue}"`
)
})
})
})
/* eslint-env jest */
import cheerio from 'cheerio'
import { readdir, readFile, remove } from 'fs-extra'
import {
findPort,
killApp,
nextBuild,
nextStart,
renderViaHTTP,
} from 'next-test-utils'
import { join } from 'path'
describe('Valid CSS Module Usage from within node_modules', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
let appPort
let app
let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
;({ code, stdout } = await nextBuild(appDir, [], {
stdout: true,
}))
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
it('should have compiled successfully', () => {
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
})
it(`should've prerendered with relevant data`, async () => {
const content = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(content)
const cssPreload = $('#nm-div')
expect(cssPreload.text()).toMatchInlineSnapshot(
`"{"message":"Why hello there"} {"redText":"example_redText__jsP_3"}"`
)
})
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(`".example_redText__jsP_3{color:red}"`)
})
})
})
/* eslint-env jest */
import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('CSS Import from node_modules', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should fail the build', async () => {
const { code, stderr } = await nextBuild(appDir, [], { stderr: true })
expect(code).toBe(0)
expect(stderr).not.toMatch(/Can't resolve '[^']*?nprogress[^']*?'/)
expect(stderr).not.toMatch(/Build error occurred/)
})
})
})
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('Good Nested CSS Import from node_modules', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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/)
})
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(`".other{color:blue}.test{color:red}"`)
})
})
})
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('Good CSS Import from node_modules', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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/)
})
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()).toMatch(/nprogress/)
})
})
})
/* eslint-env jest */
import { remove } from 'fs-extra'
import { findPort, killApp, nextBuild, nextStart } from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'
describe('Has CSS Module in computed styles in Production', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = __dirname
let appPort
let app
let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
;({ code, stdout } = await nextBuild(appDir, [], {
stdout: true,
}))
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
it('should have compiled successfully', () => {
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
})
it('should have CSS for page', async () => {
const browser = await webdriver(appPort, '/')
const currentColor = await browser.eval(
`window.getComputedStyle(document.querySelector('#verify-red')).color`
)
expect(currentColor).toMatchInlineSnapshot(`"rgb(255, 0, 0)"`)
})
})
})
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('Basic Global Support with src/ dir', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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/)
})
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)
expect(await readFile(join(cssFolder, cssFiles[0]), 'utf8')).toContain(
'color:red'
)
})
})
})
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('Basic Global Support scss', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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/)
})
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)
expect(await readFile(join(cssFolder, cssFiles[0]), 'utf8')).toContain(
'color:red'
)
})
})
})
/* eslint-env jest */
import { remove } from 'fs-extra'
import { findPort, killApp, launchApp, waitFor, File } from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'
describe('Body is not hidden when unused in Development', () => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
let appPort
let app
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
it('should have body visible', async () => {
let browser
try {
browser = await webdriver(appPort, '/')
const currentDisplay = await browser.eval(
`window.getComputedStyle(document.querySelector('body')).display`
)
expect(currentDisplay).toBe('block')
} finally {
if (browser) {
await browser.close()
}
}
})
})
describe('Body is not hidden when broken in Development', () => {
const appDir = __dirname
let appPort
let app
beforeAll(async () => {
await remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
it('should have body visible', async () => {
const pageFile = new File(join(appDir, 'pages/index.js'))
let browser
try {
pageFile.replace('<div />', '<div>')
await waitFor(2000) // wait for recompile
browser = await webdriver(appPort, '/')
const currentDisplay = await browser.eval(
`window.getComputedStyle(document.querySelector('body')).display`
)
expect(currentDisplay).toBe('block')
} finally {
pageFile.restore()
if (browser) {
await browser.close()
}
}
})
})
export default function Home() {
return <div className="red-text">This text should be red.</div>
}
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('SCSS Support loader handling', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('CSS URL via `file-loader` and asset prefix (1)', () => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should compile successfully', async () => {
const { code, stdout } = await nextBuild(appDir, [], {
stdout: true,
})
// eslint-disable-next-line
expect(code).toBe(0)
// eslint-disable-next-line
expect(stdout).toMatch(/Compiled successfully/)
})
it(`should've emitted expected files`, async () => {
const cssFolder = join(appDir, '.next/static/css')
const mediaFolder = join(appDir, '.next/static/media')
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()).toMatch(
/^\.red-text\{color:red;background-image:url\(\/foo\/_next\/static\/media\/dark\.[a-f0-9]{8}\.svg\) url\(\/foo\/_next\/static\/media\/dark2\.[a-f0-9]{8}\.svg\)\}\.blue-text\{color:orange;font-weight:bolder;background-image:url\(\/foo\/_next\/static\/media\/light\.[a-f0-9]{8}\.svg\);color:blue\}$/
)
const mediaFiles = await readdir(mediaFolder)
expect(mediaFiles.length).toBe(3)
expect(
mediaFiles
.map((fileName) =>
/^(.+?)\..{8}\.(.+?)$/.exec(fileName).slice(1).join('.')
)
.sort()
).toMatchInlineSnapshot(`
[
"dark.svg",
"dark2.svg",
"light.svg",
]
`)
})
})
})
})
export default function Home() {
return <div className="red-text">This text should be red.</div>
}
$var: red;
.red-text {
color: $var;
background-image: url('./dark.svg') url(dark2.svg);
}
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('SCSS Support loader handling', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('CSS URL via `file-loader` and asset prefix (2)', () => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should compile successfully', async () => {
const { code, stdout } = await nextBuild(appDir, [], {
stdout: true,
})
// eslint-disable-next-line
expect(code).toBe(0)
// eslint-disable-next-line
expect(stdout).toMatch(/Compiled successfully/)
})
it(`should've emitted expected files`, async () => {
const cssFolder = join(appDir, '.next/static/css')
const mediaFolder = join(appDir, '.next/static/media')
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()).toMatch(
/^\.red-text\{color:red;background-image:url\(\/foo\/_next\/static\/media\/dark\.[a-f0-9]{8}\.svg\) url\(\/foo\/_next\/static\/media\/dark2\.[a-f0-9]{8}\.svg\)\}\.blue-text\{color:orange;font-weight:bolder;background-image:url\(\/foo\/_next\/static\/media\/light\.[a-f0-9]{8}\.svg\);color:blue\}$/
)
const mediaFiles = await readdir(mediaFolder)
expect(mediaFiles.length).toBe(3)
expect(
mediaFiles
.map((fileName) =>
/^(.+?)\..{8}\.(.+?)$/.exec(fileName).slice(1).join('.')
)
.sort()
).toMatchInlineSnapshot(`
[
"dark.svg",
"dark2.svg",
"light.svg",
]
`)
})
})
})
})
export default function Home() {
return <div className="red-text">This text should be red.</div>
}
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('SCSS Support loader handling', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('CSS URL via file-loader sass partial', () => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should compile successfully', async () => {
const { code, stdout } = await nextBuild(appDir, [], {
stdout: true,
})
// eslint-disable-next-line
expect(code).toBe(0)
// eslint-disable-next-line
expect(stdout).toMatch(/Compiled successfully/)
})
it(`should've emitted expected files`, async () => {
const cssFolder = join(appDir, '.next/static/css')
const mediaFolder = join(appDir, '.next/static/media')
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(
'".red-text{color:red;background-image:url(/_next/static/media/darka.6b01655b.svg),url(/_next/static/media/darkb.6b01655b.svg)}.blue-text{color:orange;font-weight:bolder;background-image:url(/_next/static/media/light.2da1d3d6.svg);color:blue}"'
)
const mediaFiles = await readdir(mediaFolder)
expect(mediaFiles.length).toBe(3)
expect(
mediaFiles
.map((fileName) =>
/^(.+?)\..{8}\.(.+?)$/.exec(fileName).slice(1).join('.')
)
.sort()
).toMatchInlineSnapshot(`
[
"darka.svg",
"darkb.svg",
"light.svg",
]
`)
})
})
})
})
export default function Home() {
return <div className="red-text">This text should be red.</div>
}
$var: red;
.red-text {
color: $var;
background-image: url('./dark.svg') url(dark2.svg);
}
/* eslint-env jest */
import { readdir, readFile, remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('SCSS Support loader handling', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('CSS URL via `file-loader`', () => {
const appDir = __dirname
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should compile successfully', async () => {
const { code, stdout } = await nextBuild(appDir, [], {
stdout: true,
})
// eslint-disable-next-line
expect(code).toBe(0)
// eslint-disable-next-line
expect(stdout).toMatch(/Compiled successfully/)
})
it(`should've emitted expected files`, async () => {
const cssFolder = join(appDir, '.next/static/css')
const mediaFolder = join(appDir, '.next/static/media')
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()).toMatch(
/^\.red-text\{color:red;background-image:url\(\/_next\/static\/media\/dark\.[a-f0-9]{8}\.svg\) url\(\/_next\/static\/media\/dark2\.[a-f0-9]{8}\.svg\)\}\.blue-text\{color:orange;font-weight:bolder;background-image:url\(\/_next\/static\/media\/light\.[a-f0-9]{8}\.svg\);color:blue\}$/
)
const mediaFiles = await readdir(mediaFolder)
expect(mediaFiles.length).toBe(3)
expect(
mediaFiles
.map((fileName) =>
/^(.+?)\..{8}\.(.+?)$/.exec(fileName).slice(1).join('.')
)
.sort()
).toMatchInlineSnapshot(`
[
"dark.svg",
"dark2.svg",
"light.svg",
]
`)
})
})
})
})
/* eslint-env jest */
import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
describe('Valid and Invalid Global CSS with Custom App', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
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).toContain('Please move all first-party global CSS imports')
expect(stderr).toMatch(/Location:.*pages[\\/]index\.js/)
})
})
})
export default function Home() {
return <div className="red-text">This text should be red.</div>
}
/* eslint-env jest */
import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
import { quote as shellQuote } from 'shell-quote'
describe('SCSS Support', () => {
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('Friendly Webpack Error', () => {
const appDir = __dirname
const mockFile = join(appDir, 'mock.js')
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should be a friendly error successfully', async () => {
const { code, stderr } = await nextBuild(appDir, [], {
env: { NODE_OPTIONS: shellQuote([`--require`, mockFile]) },
stderr: true,
})
let cleanScssErrMsg =
'\n\n' +
'./styles/global.scss\n' +
"To use Next.js' built-in Sass support, you first need to install `sass`.\n" +
'Run `npm i sass` or `yarn add sass` inside your workspace.\n' +
'\n' +
'Learn more: https://nextjs.org/docs/messages/install-sass\n'
// eslint-disable-next-line
expect(code).toBe(1)
// eslint-disable-next-line
expect(stderr).toContain('Failed to compile.')
// eslint-disable-next-line
expect(stderr).toContain(cleanScssErrMsg)
// eslint-disable-next-line
expect(stderr).not.toContain('css-loader')
// eslint-disable-next-line
expect(stderr).not.toContain('sass-loader')
})
})
})
})
/* eslint-env jest */
import { remove } from 'fs-extra'
import {
findPort,
killApp,
nextBuild,
nextStart,
launchApp,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'
describe('Ordering with styled-jsx', () => {
describe('dev mode', () => {
const appDir = __dirname
let appPort
let app
beforeAll(async () => {
await remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
it('should have the correct color (css ordering)', async () => {
const browser = await webdriver(appPort, '/')
const currentColor = await browser.eval(
`window.getComputedStyle(document.querySelector('.my-text')).color`
)
expect(currentColor).toMatchInlineSnapshot(`"rgb(0, 128, 0)"`)
})
})
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = __dirname
let appPort
let app
let stdout
let code
beforeAll(async () => {
await remove(join(appDir, '.next'))
;({ code, stdout } = await nextBuild(appDir, [], {
stdout: true,
}))
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
it('should have compiled successfully', () => {
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
})
it('should have the correct color (css ordering)', async () => {
const browser = await webdriver(appPort, '/')
const currentColor = await browser.eval(
`window.getComputedStyle(document.querySelector('.my-text')).color`
)
expect(currentColor).toMatchInlineSnapshot(`"rgb(0, 128, 0)"`)
})
})
})
...@@ -254,6 +254,11 @@ export function nextTestSetup( ...@@ -254,6 +254,11 @@ export function nextTestSetup(
const nextProxy = new Proxy<NextInstance>({} as NextInstance, { const nextProxy = new Proxy<NextInstance>({} as NextInstance, {
get: function (_target, property) { get: function (_target, property) {
if (!next) {
throw new Error(
'next instance is not initialized yet, make sure you call methods on next instance in test body.'
)
}
const prop = next[property] const prop = next[property]
return typeof prop === 'function' ? prop.bind(next) : prop return typeof prop === 'function' ? prop.bind(next) : prop
}, },
......
...@@ -1111,6 +1111,34 @@ export async function getVersionCheckerText( ...@@ -1111,6 +1111,34 @@ export async function getVersionCheckerText(
return versionCheckerText.trim() return versionCheckerText.trim()
} }
export function colorToRgb(color) {
switch (color) {
case 'blue':
return 'rgb(0, 0, 255)'
case 'red':
return 'rgb(255, 0, 0)'
case 'green':
return 'rgb(0, 128, 0)'
case 'yellow':
return 'rgb(255, 255, 0)'
case 'purple':
return 'rgb(128, 0, 128)'
case 'black':
return 'rgb(0, 0, 0)'
default:
throw new Error('Unknown color')
}
}
export function getUrlFromBackgroundImage(backgroundImage: string) {
const matches = backgroundImage.match(/url\("[^)]+"\)/g).map((match) => {
// Extract the URL part from each match. The match includes 'url("' and '"")', so we remove those.
return match.slice(5, -2)
})
return matches
}
/** /**
* For better editor support, pass in the variants this should run on (`default` and/or `turbo`) as cases. * For better editor support, pass in the variants this should run on (`default` and/or `turbo`) as cases.
* *
......
...@@ -4555,6 +4555,243 @@ ...@@ -4555,6 +4555,243 @@
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
}, },
"test/e2e/app-dir/scss/multi-page/multi-page.test.ts": {
"passed": [
"SCSS Support Has CSS in computed styles in Production should have CSS for page",
"SCSS Support Can hot reload CSS without losing state should update CSS color without remounting <input>",
"SCSS Support Has CSS in computed styles in Development should have CSS for page"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/unused/unused.test.ts": {
"passed": [
"unused scss Body is not hidden when unused in Development development only should have body visible",
"unused scss Body is not hidden when broken in Development development only should have body visible"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/hmr-module/hmr-module.test.ts": {
"passed": [
"Can hot reload CSS Module without losing state development only should update CSS color without remounting <input>"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/url-global/url-global.test.ts": {
"passed": [
"SCSS Support loader handling CSS URL via `file-loader` should render the page"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/3rd-party-module/3rd-party-module.test.ts": {
"passed": ["3rd Party CSS Module Support should render the module"],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/external-url/external-url.test.ts": {
"passed": [
"SCSS Support loader handling External imports should include font on the page"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/composes-basic/composes-basic.test.ts": {
"passed": ["CSS Module Composes Usage (Basic) should render the module"],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/data-url/data-url.test.ts": {
"passed": [
"SCSS Support loader handling Data Urls should render the module"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/nested-global/nested-global.test.ts": {
"passed": ["Nested @import() Global Support should render the page"],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/npm-import-tilde/npm-import-tilde.test.ts": {
"passed": [
"Good CSS Import from node_modules with tilde should render the page"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/loader-order/loader-order.test.ts": {
"passed": [
"SCSS Support loader handling Preprocessor loader order should render the module"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/dev-module/dev-module.test.ts": {
"passed": [
"Has CSS Module in computed styles in Development should have CSS for page"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/npm-import/npm-import.test.ts": {
"passed": ["Good CSS Import from node_modules should render the page"],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/prod-module/prod-module.test.ts": {
"passed": [
"Has CSS Module in computed styles in Production should render the page"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/with-styled-jsx/with-styled-jsx.test.ts": {
"passed": [
"Ordering with styled-jsx should have the correct color (css ordering)"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/catch-all-module/catch-all-module.test.ts": {
"passed": ["Catch-all Route CSS Module Usage should render the module"],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/basic-module-additional-data/basic-module-additional-data.test.ts": {
"passed": ["Basic Module Additional Data Support should render the module"],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/basic-module-include-paths/basic-module-include-paths.test.ts": {
"passed": ["Basic Module Include Paths Support should render the module"],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/basic-module-prepend-data/basic-module-prepend-data.test.ts": {
"passed": ["Basic Module Prepend Data Support should render the module"],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/multi-global-reversed/multi-global-reversed.test.ts": {
"passed": ["Multi Global Support (reversed) should render the page"],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/single-global-src/single-global-src.test.ts": {
"passed": ["Basic Global Support with src/ dir should render the page"],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/basic-module/basic-module.test.ts": {
"passed": ["Basic SCSS Module Support should render the module"],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/single-global/single-global.test.ts": {
"passed": ["Basic Global Support scss should render the page"],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/multi-global/multi-global.test.ts": {
"passed": ["Multi Global Support should render the page"],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/npm-import-nested/npm-import-nested.test.ts": {
"passed": [
"Good Nested CSS Import from node_modules should render the page"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/nm-module-nested/nm-module-nested.test.ts": {
"passed": [
"Valid Nested CSS Module Usage from within node_modules should render the page"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/nm-module/nm-module.test.ts": {
"passed": [
"Valid CSS Module Usage from within node_modules should render the page"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/composes-external/composes-external.test.ts": {
"passed": ["CSS Module Composes Usage (External) should render the module"],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/scss/url-global-partial/url-global-partial.test.ts": {
"passed": [
"SCSS Support loader handling CSS URL via file-loader sass partial should render the page"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/search-params-react-key/layout-params.test.ts": { "test/e2e/app-dir/search-params-react-key/layout-params.test.ts": {
"passed": [ "passed": [
"app dir - search params keys should keep the React router instance the same when changing the search params" "app dir - search params keys should keep the React router instance the same when changing the search params"
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