Skip to content

Commit

Permalink
test: Add failing tests for async css modules
Browse files Browse the repository at this point in the history
  • Loading branch information
IanVS committed Jan 6, 2022
1 parent eb9b374 commit e6cd509
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/playground/css/__tests__/css.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ test('treeshaken async chunk', async () => {
}
})

test('async css modules', async () => {
const blue = await page.$('.async-modules-blue')
const red = await page.$('.async-modules-red')

expect(await getColor(blue)).toBe('blue')
expect(await getColor(red)).toBe('red')
})

test('PostCSS dir-dependency', async () => {
const el1 = await page.$('.dir-dep')
const el2 = await page.$('.dir-dep-2')
Expand Down
10 changes: 10 additions & 0 deletions packages/playground/css/async-modules/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import styles from './black.module.css'

export function baseAsync(className, color) {
const div = document.createElement('div')
div.className = `${styles.black} ${className} async-modules-${color}`
document.body.appendChild(div)
div.textContent = `async css modules (${color}) ${
getComputedStyle(div).color
}`
}
3 changes: 3 additions & 0 deletions packages/playground/css/async-modules/black.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.black {
color: black;
}
4 changes: 4 additions & 0 deletions packages/playground/css/async-modules/blue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { baseAsync } from './base'
import styles from './blue.module.css'

baseAsync(styles.blue, 'blue')
3 changes: 3 additions & 0 deletions packages/playground/css/async-modules/blue.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.blue {
color: blue;
}
4 changes: 4 additions & 0 deletions packages/playground/css/async-modules/red.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { baseAsync } from './base'
import styles from './red.module.css'

baseAsync(styles.red, 'red')
3 changes: 3 additions & 0 deletions packages/playground/css/async-modules/red.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.red {
color: red;
}
4 changes: 4 additions & 0 deletions packages/playground/css/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ if (import.meta.env.DEV) {
// inlined
import inlined from './inlined.css?inline'
text('.inlined-code', inlined)

// async css modules
import('./async-modules/blue')
import('./async-modules/red')

0 comments on commit e6cd509

Please sign in to comment.