Skip to content

Commit

Permalink
test(e2e): add case for importing styles from packages
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed May 31, 2024
1 parent 19e4d40 commit 81ab881
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 0 deletions.
7 changes: 7 additions & 0 deletions e2e/docs/.vuepress/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { defineClientConfig } from 'vuepress/client'
import RootComponentFromUserConfig from './components/RootComponentFromUserConfig.vue'

// static imported styles file
import '@vuepress-e2e/style-exports/foo.css'

export default defineClientConfig({
async enhance() {
// dynamic imported styles file
await import('@vuepress-e2e/style-exports')
},
rootComponents: [RootComponentFromUserConfig],
})
3 changes: 3 additions & 0 deletions e2e/docs/imports/style-exports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="style-exports">dynamic import</div>

<div class="style-exports-foo">static import</div>
3 changes: 3 additions & 0 deletions e2e/modules/style-exports/foo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.style-exports-foo {
font-size: 30px;
}
3 changes: 3 additions & 0 deletions e2e/modules/style-exports/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.style-exports {
font-size: 20px;
}
17 changes: 17 additions & 0 deletions e2e/modules/style-exports/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@vuepress-e2e/style-exports",
"type": "module",
"exports": {
".": {
"types": "./types.d.ts",
"default": "./index.css"
},
"./foo.css": {
"types": "./types.d.ts",
"default": "./foo.css"
}
},
"main": "./index.css",
"module": "./index.css",
"types": "./types.d.ts"
}
1 change: 1 addition & 0 deletions e2e/modules/style-exports/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
1 change: 1 addition & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@vuepress-e2e/conditional-exports": "file:./modules/conditional-exports",
"@vuepress-e2e/style-exports": "file:./modules/style-exports",
"@vuepress/bundler-vite": "workspace:*",
"@vuepress/bundler-webpack": "workspace:*",
"sass": "^1.77.4",
Expand Down
19 changes: 19 additions & 0 deletions e2e/tests/imports/style-exports.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect, test } from '@playwright/test'

test('should load dynamic imported styles correctly', async ({ page }) => {
await page.goto('imports/style-exports.html')

const locator = page.locator('.style-exports')

await expect(locator).toHaveText('dynamic import')

Check failure on line 8 in e2e/tests/imports/style-exports.spec.ts

View workflow job for this annotation

GitHub Actions / e2e (macos-latest, 20, vite)

[chromium] › imports/style-exports.spec.ts:3:1 › should load dynamic imported styles correctly

1) [chromium] › imports/style-exports.spec.ts:3:1 › should load dynamic imported styles correctly Error: Timed out 5000ms waiting for expect(locator).toHaveText(expected) Locator: locator('.style-exports') Expected string: "dynamic import" Received: <element(s) not found> Call log: - expect.toHaveText with timeout 5000ms - waiting for locator('.style-exports') 6 | const locator = page.locator('.style-exports') 7 | > 8 | await expect(locator).toHaveText('dynamic import') | ^ 9 | await expect(locator).toHaveCSS('font-size', '20px') 10 | }) 11 | at /Users/runner/work/core/core/e2e/tests/imports/style-exports.spec.ts:8:25
await expect(locator).toHaveCSS('font-size', '20px')
})

test('should load static imported styles correctly', async ({ page }) => {
await page.goto('imports/style-exports.html')

const locator = page.locator('.style-exports-foo')

await expect(locator).toHaveText('static import')
await expect(locator).toHaveCSS('font-size', '30px')
})
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 81ab881

Please sign in to comment.