Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add tests to demonstrate that PostCSS configs are not reused across projects #1

Merged
merged 2 commits into from Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/playground/css/postcss-caching/blue-app/imported.css
@@ -0,0 +1,3 @@
.postcss-a {
color: pink;
}
12 changes: 12 additions & 0 deletions packages/playground/css/postcss-caching/blue-app/index.html
@@ -0,0 +1,12 @@
<div class="wrapper">
<h1>CSS</h1>

<p>Imported css string:</p>
<pre class="imported-css"></pre>

<p class="postcss-a">This should be blue</p>

<p class="postcss-b">This should be black</p>
</div>

<script type="module" src="./main.js"></script>
6 changes: 6 additions & 0 deletions packages/playground/css/postcss-caching/blue-app/main.js
@@ -0,0 +1,6 @@
import css from './imported.css'
text('.imported-css', css)

function text(el, text) {
document.querySelector(el).textContent = text
}
11 changes: 11 additions & 0 deletions packages/playground/css/postcss-caching/blue-app/package.json
@@ -0,0 +1,11 @@
{
"name": "blue-app",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"debug": "node --inspect-brk ../../vite/bin/vite",
"serve": "vite preview"
}
}
15 changes: 15 additions & 0 deletions packages/playground/css/postcss-caching/blue-app/postcss.config.js
@@ -0,0 +1,15 @@
module.exports = {
plugins: [replacePinkWithBlue]
}

function replacePinkWithBlue() {
return {
postcssPlugin: 'replace-pink-with-blue',
Declaration(decl) {
if (decl.value === 'pink') {
decl.value = 'blue'
}
}
}
}
replacePinkWithBlue.postcss = true
29 changes: 29 additions & 0 deletions packages/playground/css/postcss-caching/css.spec.ts
@@ -0,0 +1,29 @@
import { getColor } from '../../testUtils'
import { createServer } from 'vite'
import path from 'path'

test('postcss config', async () => {
const port = 5005
const blueAppDir = path.join(__dirname, 'blue-app')
const greenAppDir = path.join(__dirname, 'green-app')

process.chdir(blueAppDir)
const blueApp = await createServer()
await blueApp.listen(port)
await page.goto(`http://localhost:${port}`)
const blueA = await page.$('.postcss-a')
expect(await getColor(blueA)).toBe('blue')
const blueB = await page.$('.postcss-b')
expect(await getColor(blueB)).toBe('black')
await blueApp.close()

process.chdir(greenAppDir)
const greenApp = await createServer()
await greenApp.listen(port)
await page.goto(`http://localhost:${port}`)
const greenA = await page.$('.postcss-a')
expect(await getColor(greenA)).toBe('black')
const greenB = await page.$('.postcss-b')
expect(await getColor(greenB)).toBe('green')
await greenApp.close()
})
@@ -0,0 +1,3 @@
.postcss-b {
color: pink;
}
12 changes: 12 additions & 0 deletions packages/playground/css/postcss-caching/green-app/index.html
@@ -0,0 +1,12 @@
<div class="wrapper">
<h1>CSS</h1>

<p>Imported css string:</p>
<pre class="imported-css"></pre>

<p class="postcss-a">This should be black</p>

<p class="postcss-b">This should be green</p>
</div>

<script type="module" src="./main.js"></script>
6 changes: 6 additions & 0 deletions packages/playground/css/postcss-caching/green-app/main.js
@@ -0,0 +1,6 @@
import css from './imported.css'
text('.imported-css', css)

function text(el, text) {
document.querySelector(el).textContent = text
}
11 changes: 11 additions & 0 deletions packages/playground/css/postcss-caching/green-app/package.json
@@ -0,0 +1,11 @@
{
"name": "green-app",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"debug": "node --inspect-brk ../../vite/bin/vite",
"serve": "vite preview"
}
}
@@ -0,0 +1,15 @@
module.exports = {
plugins: [replacePinkWithGreen]
}

function replacePinkWithGreen() {
return {
postcssPlugin: 'replace-pink-with-green',
Declaration(decl) {
if (decl.value === 'pink') {
decl.value = 'green'
}
}
}
}
replacePinkWithGreen.postcss = true