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

test: css content tests #8873

Merged
merged 2 commits into from Jul 1, 2022
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
11 changes: 11 additions & 0 deletions playground/css/__tests__/css.spec.ts
Expand Up @@ -349,6 +349,11 @@ test('PostCSS dir-dependency', async () => {
}
})

test('import dependency includes css import', async () => {
expect(await getColor('.css-js-dep')).toBe('green')
expect(await getColor('.css-js-dep-module')).toBe('green')
})

test('URL separation', async () => {
const urlSeparated = await page.$('.url-separated')
const baseUrl = 'url(images/dog.webp)'
Expand Down Expand Up @@ -426,3 +431,9 @@ test('PostCSS source.input.from includes query', async () => {
// should resolve assets
expect(code).toContain('/postcss-source-input.css?query=foo')
})

test('aliased css has content', async () => {
expect(await getColor('.aliased')).toBe('blue')
expect(await page.textContent('.aliased-content')).toMatch('.aliased')
expect(await getColor('.aliased-module')).toBe('blue')
})
3 changes: 3 additions & 0 deletions playground/css/aliased/bar.module.css
@@ -0,0 +1,3 @@
.aliasedModule {
color: blue;
}
3 changes: 3 additions & 0 deletions playground/css/aliased/foo.css
@@ -0,0 +1,3 @@
.aliased {
color: blue;
}
3 changes: 3 additions & 0 deletions playground/css/css-js-dep/bar.module.css
@@ -0,0 +1,3 @@
.cssJsDepModule {
color: green;
}
3 changes: 3 additions & 0 deletions playground/css/css-js-dep/foo.css
@@ -0,0 +1,3 @@
.css-js-dep {
color: green;
}
4 changes: 4 additions & 0 deletions playground/css/css-js-dep/index.js
@@ -0,0 +1,4 @@
import './foo.css'
import barModuleClasses from './bar.module.css'

export { barModuleClasses }
7 changes: 7 additions & 0 deletions playground/css/css-js-dep/package.json
@@ -0,0 +1,7 @@
{
"name": "css-js-dep",
"private": true,
"type": "module",
"version": "1.0.0",
"main": "index.js"
}
12 changes: 12 additions & 0 deletions playground/css/index.html
Expand Up @@ -117,6 +117,13 @@ <h1>CSS</h1>
PostCSS dir-dependency (file 3): this should be grey too
</p>

<p class="css-js-dep">
import dependency includes 'import "./foo.css"': this should be green
</p>
<p class="css-js-dep-module">
import dependency includes 'import "./bar.module.css"': this should be green
</p>

<p class="url-separated">
URL separation preservation: should have valid background-image
</p>
Expand All @@ -141,6 +148,11 @@ <h1>CSS</h1>

<p>PostCSS source.input.from. Should include query</p>
<pre class="postcss-source-input"></pre>

<p>Aliased</p>
<p class="aliased">import '#alias': this should be blue</p>
<pre class="aliased-content"></pre>
<p class="aliased-module">import '#alias-module': this should be blue</p>
</div>

<script type="module" src="./main.js"></script>
12 changes: 12 additions & 0 deletions playground/css/main.js
Expand Up @@ -47,6 +47,11 @@ text('.charset-css', charset)
import './dep.css'
import './glob-dep.css'

import { barModuleClasses } from 'css-js-dep'
document
.querySelector('.css-js-dep-module')
.classList.add(barModuleClasses.cssJsDepModule)

function text(el, text) {
document.querySelector(el).textContent = text
}
Expand Down Expand Up @@ -92,3 +97,10 @@ text('.imported-css-globEager', JSON.stringify(globEager, null, 2))

import postcssSourceInput from './postcss-source-input.css?query=foo'
text('.postcss-source-input', postcssSourceInput)

import aliasContent from '#alias'
text('.aliased-content', aliasContent)
import aliasModule from '#alias-module'
document
.querySelector('.aliased-module')
.classList.add(aliasModule.aliasedModule)
1 change: 1 addition & 0 deletions playground/css/package.json
Expand Up @@ -13,6 +13,7 @@
},
"devDependencies": {
"css-dep": "link:./css-dep",
"css-js-dep": "file:./css-js-dep",
"fast-glob": "^3.2.11",
"less": "^4.1.3",
"postcss-nested": "^5.0.6",
Expand Down
4 changes: 3 additions & 1 deletion playground/css/vite.config.js
Expand Up @@ -10,7 +10,9 @@ module.exports = {
resolve: {
alias: {
'@': __dirname,
spacefolder: __dirname + '/folder with space'
spacefolder: __dirname + '/folder with space',
'#alias': __dirname + '/aliased/foo.css',
'#alias-module': __dirname + '/aliased/bar.module.css'
}
},
css: {
Expand Down
16 changes: 15 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.