Skip to content

Commit

Permalink
test: fix style update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 24, 2020
1 parent 7305c5b commit b674e88
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
Empty file added playground/css/empty.css
Empty file.
3 changes: 1 addition & 2 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export function updateStyle(id: string, content: string) {
style.replaceSync(content)
// @ts-ignore
document.adoptedStyleSheets = [...document.adoptedStyleSheets, style]
sheetsMap.set(id, style)
} else {
style.replaceSync(content)
}
Expand All @@ -187,11 +186,11 @@ export function updateStyle(id: string, content: string) {
style.setAttribute('type', 'text/css')
style.innerHTML = content
document.head.appendChild(style)
sheetsMap.set(id, style)
} else {
style.innerHTML = content
}
}
sheetsMap.set(id, style)
}

function removeStyle(id: string) {
Expand Down
22 changes: 11 additions & 11 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,26 +311,26 @@ describe('vite', () => {
// external imports are preserved, and is not supported with constructed
// CSSStyleSheet, so we need to remove the constructed sheet and fallback
// to <style> insertion
const externalImport = `@import url('https://fonts.googleapis.com/css2?family=Roboto')`
await updateFile('css/TestPostCss.vue', (content) =>
content
const externalImport = `@import 'http://localhost:3000/css/empty.css';`
await updateFile('css/TestPostCss.vue', (content) => {
return content
.replace(`<style>`, `<style>\n${externalImport}\n`)
.replace('color: green', 'color: red')
)
.replace('color: red;', 'color: green;')
})
// should work
await expectByPolling(
() => getComputedColor('.postcss-from-sfc'),
'rgb(255, 0, 0)'
'rgb(0, 128, 0)'
)
await updateFile('css/TestPostCss.vue', (content) =>
content
await updateFile('css/TestPostCss.vue', (content) => {
return content
.replace(externalImport, '')
.replace('color: red', 'color: green')
)
.replace('color: green;', 'color: red;')
})
// should work
await expectByPolling(
() => getComputedColor('.postcss-from-sfc'),
'rgb(0, 128, 0)'
'rgb(255, 0, 0)'
)
})

Expand Down

0 comments on commit b674e88

Please sign in to comment.