Skip to content

Commit e153eb9

Browse files
sapphi-redjrmajor
andcommitted
test: add inject-url test for lightningcss as well
Co-authored-by: Jeremiasz Major <jrh.mjr@gmail.com>
1 parent b0240d1 commit e153eb9

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

playground/css/__tests__/tests.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,13 @@ export const tests = (isLightningCSS: boolean) => {
8282
await untilUpdated(() => getColor(imported), 'red')
8383
})
8484

85-
if (!isLightningCSS) {
86-
test('postcss plugin that injects url()', async () => {
87-
const imported = await page.$('.postcss-inject-url')
88-
// alias should be resolved
89-
expect(await getBg(imported)).toMatch(
90-
/localhost(?::\d+)?\/(?:assets\/)?ok.*\.png/,
91-
)
92-
})
93-
}
85+
test('postcss plugin that injects url()', async () => {
86+
const imported = await page.$('.inject-url')
87+
// alias should be resolved
88+
expect(await getBg(imported)).toMatch(
89+
/localhost(?::\d+)?\/(?:assets\/)?ok.*\.png/,
90+
)
91+
})
9492

9593
sassTest()
9694

playground/css/index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ <h1>CSS</h1>
2323
<p class="postcss">
2424
<span class="nesting">PostCSS nesting plugin: this should be pink</span>
2525
</p>
26-
<p class="postcss-inject-url">
27-
PostCSS plugin: this should have a background image
28-
</p>
26+
<p class="inject-url">PostCSS plugin: this should have a background image</p>
2927

3028
<p class="sass">SASS: This should be orange</p>
3129
<p class="sass-at-import">

playground/css/lightningcss-plugins.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,40 @@ export function nestedLikePlugin() {
171171
},
172172
}
173173
}
174+
175+
/** @returns {import('lightningcss').Visitor} */
176+
export function testInjectUrl() {
177+
return {
178+
Rule: {
179+
unknown: {
180+
'inject-url': (rule) => {
181+
return [
182+
{
183+
type: 'style',
184+
value: {
185+
selectors: [[{ type: 'class', name: 'inject-url' }]],
186+
declarations: {
187+
declarations: [
188+
{
189+
property: 'background-image',
190+
value: [
191+
{
192+
type: 'url',
193+
value: {
194+
url: '=/ok.png',
195+
loc: rule.loc,
196+
},
197+
},
198+
],
199+
},
200+
],
201+
},
202+
loc: rule.loc,
203+
},
204+
},
205+
]
206+
},
207+
},
208+
},
209+
}
210+
}

playground/css/postcss.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function testInjectUrl() {
6868
Once(root, { Rule }) {
6969
root.walkAtRules('inject-url', (atRule) => {
7070
const rule = new Rule({
71-
selector: '.postcss-inject-url',
71+
selector: '.inject-url',
7272
source: atRule.source,
7373
})
7474
rule.append({

playground/css/vite.config-lightningcss.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import baseConfig from './vite.config.js'
44
import {
55
nestedLikePlugin,
66
testDirDep,
7+
testInjectUrl,
78
testSourceInput,
89
} from './lightningcss-plugins'
910

@@ -20,6 +21,7 @@ export default defineConfig({
2021
nestedLikePlugin(),
2122
testDirDep(),
2223
testSourceInput(),
24+
testInjectUrl(),
2325
]),
2426
},
2527
},

0 commit comments

Comments
 (0)