Skip to content

Commit bde6e3b

Browse files
committed
fix: css test
1 parent 6b7a483 commit bde6e3b

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

src/css.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
import { transform } from './helpers.js'
2+
13
export class CSS {
24
private readonly styles = new Map<string, string>()
35

4-
add(path: string, styles: string): string {
5-
this.styles.set(path, styles.replace('\n', ''))
6+
async add(
7+
name: string,
8+
file: string,
9+
isBuildWatch: boolean
10+
): Promise<string> {
11+
const styles = await transform({
12+
name,
13+
file,
14+
minify: isBuildWatch,
15+
loader: 'css'
16+
})
17+
18+
this.styles.set(name, styles.replace('\n', ''))
619
return ''
720
}
821

src/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,7 @@ export default function UserscriptPlugin(
9797
let code = src
9898

9999
if (regexpStyles.test(path)) {
100-
const styles = await transform({
101-
minify: !isBuildWatch,
102-
file: code,
103-
name: path,
104-
loader: 'css'
105-
})
106-
code = css.add(path, styles)
100+
code = await css.add(path, code, !isBuildWatch)
107101
}
108102

109103
if (path.includes(config.entry)) {

test/css.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ const style2 = `
2020

2121
test('snapshot css modules', async () => {
2222
const css = new CSS()
23-
await css.add(style1, '/style1.css')
24-
await css.add(style2, '/style2.css')
23+
await css.add('/style1.css', style1, true)
24+
await css.add('/style2.css', style2, true)
2525
css.merge(['/style2.css'])
2626
expect(css.inject()).toMatchSnapshot()
2727
})
2828

2929
test('snapshot css modules (undefined)', async () => {
3030
const css = new CSS()
31-
await css.add(style1, '/style1.css')
31+
await css.add('/style1.css', style1, true)
3232
css.merge([])
3333
expect(css.inject()).toMatchSnapshot()
3434
})

0 commit comments

Comments
 (0)