Skip to content

Commit c1a1aa4

Browse files
authored
Add test for TailwindCSS JIT mode reloading (#32130)
Test for tailwindlabs/tailwindcss#6265 Issue started with #31798 ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint`
1 parent 56c68db commit c1a1aa4

File tree

8 files changed

+8076
-8069
lines changed

8 files changed

+8076
-8069
lines changed

packages/next/compiled/webpack/bundle5.js

Lines changed: 7901 additions & 8061 deletions
Large diffs are not rendered by default.

packages/next/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
"webpack-sources1": "npm:webpack-sources@1.4.3",
269269
"webpack-sources3": "npm:webpack-sources@3.2.2",
270270
"webpack4": "npm:webpack@4.44.1",
271-
"webpack5": "npm:webpack@5.64.4",
271+
"webpack5": "npm:webpack@5.64.3",
272272
"ws": "8.2.3"
273273
},
274274
"resolutions": {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { join } from 'path'
2+
import webdriver from 'next-webdriver'
3+
import { createNext, FileRef } from 'e2e-utils'
4+
import { NextInstance } from 'test/lib/next-modes/base'
5+
import { check } from 'next-test-utils'
6+
7+
describe('TailwindCSS JIT', () => {
8+
let next: NextInstance
9+
10+
beforeAll(async () => {
11+
next = await createNext({
12+
files: {
13+
'postcss.config.js': new FileRef(
14+
join(__dirname, 'tailwind-jit/postcss.config.js')
15+
),
16+
'tailwind.config.js': new FileRef(
17+
join(__dirname, 'tailwind-jit/tailwind.config.js')
18+
),
19+
pages: new FileRef(join(__dirname, 'tailwind-jit/pages')),
20+
},
21+
dependencies: {
22+
tailwindcss: '2.2.19',
23+
postcss: '8.3.5',
24+
},
25+
})
26+
})
27+
afterAll(() => next.destroy())
28+
29+
it('works with JIT enabled', async () => {
30+
let browser
31+
try {
32+
browser = await webdriver(next.appPort, '/')
33+
const text = await browser.elementByCss('.text-6xl').text()
34+
expect(text).toMatch(/Welcome to/)
35+
const cssBlue = await browser
36+
.elementByCss('#test-link')
37+
.getComputedCss('color')
38+
expect(cssBlue).toBe('rgb(37, 99, 235)')
39+
40+
const aboutPagePath = join('pages', 'index.js')
41+
42+
const originalContent = await next.readFile(aboutPagePath)
43+
const editedContent = originalContent.replace(
44+
'<a className="text-blue-600" href="https://nextjs.org" id="test-link">',
45+
'<a className="text-red-600" href="https://nextjs.org" id="test-link">'
46+
)
47+
48+
// change the content
49+
try {
50+
await next.patchFile(aboutPagePath, editedContent)
51+
await check(
52+
() => browser.elementByCss('#test-link').getComputedCss('color'),
53+
/rgb\(220, 38, 38\)/
54+
)
55+
} finally {
56+
// add the original content
57+
await next.patchFile(aboutPagePath, originalContent)
58+
}
59+
} finally {
60+
if (browser) {
61+
await browser.close()
62+
}
63+
}
64+
})
65+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'tailwindcss/tailwind.css'
2+
3+
function MyApp({ Component, pageProps }) {
4+
return <Component {...pageProps} />
5+
}
6+
7+
export default MyApp
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
export default function Home() {
2+
return (
3+
<div className="flex flex-col items-center justify-center min-h-screen py-2">
4+
<main className="flex flex-col items-center justify-center w-full flex-1 px-20 text-center">
5+
<h1 className="text-6xl font-bold">
6+
Welcome to{' '}
7+
<a className="text-blue-600" href="https://nextjs.org" id="test-link">
8+
Next.js!
9+
</a>
10+
</h1>
11+
12+
<p className="mt-3 text-2xl">
13+
Get started by editing{' '}
14+
<code className="p-3 font-mono text-lg bg-gray-100 rounded-md">
15+
pages/index.js
16+
</code>
17+
</p>
18+
19+
<div className="flex flex-wrap items-center justify-around max-w-4xl mt-6 sm:w-full">
20+
<a
21+
href="https://nextjs.org/docs"
22+
className="p-6 mt-6 text-left border w-96 rounded-xl hover:text-blue-600 focus:text-blue-600"
23+
>
24+
<h3 className="text-2xl font-bold">Documentation &rarr;</h3>
25+
<p className="mt-4 text-xl">
26+
Find in-depth information about Next.js features and API.
27+
</p>
28+
</a>
29+
30+
<a
31+
href="https://nextjs.org/learn"
32+
className="p-6 mt-6 text-left border w-96 rounded-xl hover:text-blue-600 focus:text-blue-600"
33+
>
34+
<h3 className="text-2xl font-bold">Learn &rarr;</h3>
35+
<p className="mt-4 text-xl">
36+
Learn about Next.js in an interactive course with quizzes!
37+
</p>
38+
</a>
39+
40+
<a
41+
href="https://github.com/vercel/next.js/tree/master/examples"
42+
className="p-6 mt-6 text-left border w-96 rounded-xl hover:text-blue-600 focus:text-blue-600"
43+
>
44+
<h3 className="text-2xl font-bold">Examples &rarr;</h3>
45+
<p className="mt-4 text-xl">
46+
Discover and deploy boilerplate example Next.js projects.
47+
</p>
48+
</a>
49+
50+
<a
51+
href="https://vercel.com/import?filter=next.js&utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
52+
className="p-6 mt-6 text-left border w-96 rounded-xl hover:text-blue-600 focus:text-blue-600"
53+
>
54+
<h3 className="text-2xl font-bold">Deploy &rarr;</h3>
55+
<p className="mt-4 text-xl">
56+
Instantly deploy your Next.js site to a public URL with Vercel.
57+
</p>
58+
</a>
59+
</div>
60+
</main>
61+
</div>
62+
)
63+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// If you want to use other PostCSS plugins, see the following:
2+
// https://tailwindcss.com/docs/using-with-preprocessors
3+
module.exports = {
4+
plugins: {
5+
tailwindcss: {},
6+
},
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
mode: 'jit',
3+
purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'],
4+
darkMode: false, // or 'media' or 'class'
5+
theme: {
6+
extend: {},
7+
},
8+
variants: {
9+
extend: {},
10+
},
11+
plugins: [],
12+
}

yarn.lock

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19884,7 +19884,7 @@ watchpack-chokidar2@^2.0.0:
1988419884
dependencies:
1988519885
chokidar "^2.1.8"
1988619886

19887-
watchpack@2.3.0, watchpack@^2.3.0:
19887+
watchpack@2.3.0:
1988819888
version "2.3.0"
1988919889
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.3.0.tgz#a41bca3da6afaff31e92a433f4c856a0c25ea0c4"
1989019890
integrity sha512-MnN0Q1OsvB/GGHETrFeZPQaOelWh/7O+EiFlj8sM9GPjtQkis7k01aAxrg/18kTfoIVcLL+haEVFlXDaSRwKRw==
@@ -19903,6 +19903,14 @@ watchpack@^1.7.4:
1990319903
chokidar "^3.4.1"
1990419904
watchpack-chokidar2 "^2.0.0"
1990519905

19906+
watchpack@^2.2.0:
19907+
version "2.2.0"
19908+
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.2.0.tgz#47d78f5415fe550ecd740f99fe2882323a58b1ce"
19909+
integrity sha512-up4YAn/XHgZHIxFBVCdlMiWDj6WaLKpwVeGQk2I5thdYxF/KmF0aaz6TfJZ/hfl1h/XlcDr7k1KH7ThDagpFaA==
19910+
dependencies:
19911+
glob-to-regexp "^0.4.1"
19912+
graceful-fs "^4.1.2"
19913+
1990619914
wcwidth@^1.0.0, wcwidth@^1.0.1:
1990719915
version "1.0.1"
1990819916
resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8"
@@ -19981,11 +19989,16 @@ webpack-bundle-analyzer@4.3.0:
1998119989
source-list-map "^2.0.0"
1998219990
source-map "~0.6.1"
1998319991

19984-
"webpack-sources3@npm:webpack-sources@3.2.2", webpack-sources@^3.2.2:
19992+
"webpack-sources3@npm:webpack-sources@3.2.2":
1998519993
version "3.2.2"
1998619994
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.2.tgz#d88e3741833efec57c4c789b6010db9977545260"
1998719995
integrity sha512-cp5qdmHnu5T8wRg2G3vZZHoJPN14aqQ89SyQ11NpGH5zEMDCclt49rzo+MaRazk7/UeILhAI+/sEtcM+7Fr0nw==
1998819996

19997+
webpack-sources@^3.2.2:
19998+
version "3.2.2"
19999+
resolved "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.2.tgz#d88e3741833efec57c4c789b6010db9977545260"
20000+
integrity sha512-cp5qdmHnu5T8wRg2G3vZZHoJPN14aqQ89SyQ11NpGH5zEMDCclt49rzo+MaRazk7/UeILhAI+/sEtcM+7Fr0nw==
20001+
1998920002
"webpack4@npm:webpack@4.44.1":
1999020003
version "4.44.1"
1999120004
resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.44.1.tgz#17e69fff9f321b8f117d1fda714edfc0b939cc21"
@@ -20015,10 +20028,10 @@ webpack-bundle-analyzer@4.3.0:
2001520028
watchpack "^1.7.4"
2001620029
webpack-sources "^1.4.1"
2001720030

20018-
"webpack5@npm:webpack@5.64.4":
20019-
version "5.64.4"
20020-
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.64.4.tgz#e1454b6a13009f57cc2c78e08416cd674622937b"
20021-
integrity sha512-LWhqfKjCLoYJLKJY8wk2C3h77i8VyHowG3qYNZiIqD6D0ZS40439S/KVuc/PY48jp2yQmy0mhMknq8cys4jFMw==
20031+
"webpack5@npm:webpack@5.64.3":
20032+
version "5.64.3"
20033+
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.64.3.tgz#f4792cc3f8528db2c18375fa2cd269f69e0bf69f"
20034+
integrity sha512-XF6/IL9Bw2PPQioiR1UYA8Bs4tX3QXJtSelezKECdLFeSFzWoe44zqTzPW5N+xI3fACaRl2/G3sNA4WYHD7Iww==
2002220035
dependencies:
2002320036
"@types/eslint-scope" "^3.7.0"
2002420037
"@types/estree" "^0.0.50"
@@ -20042,7 +20055,7 @@ webpack-bundle-analyzer@4.3.0:
2004220055
schema-utils "^3.1.0"
2004320056
tapable "^2.1.1"
2004420057
terser-webpack-plugin "^5.1.3"
20045-
watchpack "^2.3.0"
20058+
watchpack "^2.2.0"
2004620059
webpack-sources "^3.2.2"
2004720060

2004820061
"webpack@link:./node_modules/webpack5":

0 commit comments

Comments
 (0)