[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(ui): escape html in error diff (#5325)

authored by

Hiroshi Ogawa and committed by
GitHub
(Mar 4, 2024, 9:02 PM +0100) ab60bf8d 14ee16df

+25 -3
+3
test/ui/vitest.config.ts
··· 4 4 test: { 5 5 dir: './fixtures', 6 6 environment: 'happy-dom', 7 + coverage: { 8 + reportOnFailure: true, 9 + }, 7 10 }, 8 11 })
+6
test/ui/fixtures/error.test.ts
··· 1 + import { expect, it } from "vitest" 2 + 3 + // https://github.com/vitest-dev/vitest/issues/5321 4 + it('escape html in error diff', () => { 5 + expect('<style>* {border: 2px solid green};</style>').toBe("") 6 + })
+7 -1
test/ui/test/html-report.spec.ts
··· 32 32 await page.goto(pageUrl) 33 33 34 34 // dashbaord 35 - await expect(page.locator('[aria-labelledby=tests]')).toContainText('5 Pass 0 Fail 5 Total') 35 + await expect(page.locator('[aria-labelledby=tests]')).toContainText('5 Pass 1 Fail 6 Total') 36 36 37 37 // unhandled errors 38 38 await expect(page.getByTestId('unhandled-errors')).toContainText( ··· 63 63 await page.goto(pageUrl) 64 64 await page.getByLabel('Show coverage').click() 65 65 await page.frameLocator('#vitest-ui-coverage').getByRole('heading', { name: 'All files' }).click() 66 + }) 67 + 68 + test('error', async ({ page }) => { 69 + await page.goto(pageUrl) 70 + await page.getByText('fixtures/error.test.ts').click() 71 + await expect(page.getByTestId('diff')).toContainText('- Expected + Received + <style>* {border: 2px solid green};</style>') 66 72 }) 67 73 })
+7 -1
test/ui/test/ui.spec.ts
··· 23 23 await page.goto(pageUrl) 24 24 25 25 // dashbaord 26 - await expect(page.locator('[aria-labelledby=tests]')).toContainText('5 Pass 0 Fail 5 Total') 26 + await expect(page.locator('[aria-labelledby=tests]')).toContainText('5 Pass 1 Fail 6 Total') 27 27 28 28 // unhandled errors 29 29 await expect(page.getByTestId('unhandled-errors')).toContainText( ··· 61 61 await page.getByText('fixtures/console.test.ts').click() 62 62 await page.getByTestId('btn-console').click() 63 63 await page.getByText('/(?<char>\\w)/').click() 64 + }) 65 + 66 + test('error', async ({ page }) => { 67 + await page.goto(pageUrl) 68 + await page.getByText('fixtures/error.test.ts').click() 69 + await expect(page.getByTestId('diff')).toContainText('- Expected + Received + <style>* {border: 2px solid green};</style>') 64 70 }) 65 71 66 72 test('file-filter', async ({ page }) => {
+2 -1
packages/ui/client/components/views/ViewReportError.vue
··· 1 1 <script setup lang="ts"> 2 2 import type { ErrorWithDiff } from 'vitest' 3 3 import { openInEditor, shouldOpenInEditor } from '~/composables/error' 4 + import { escapeHtml } from '~/utils/escape'; 4 5 5 6 const props = defineProps<{ 6 7 root: string ··· 20 21 return !!props.error?.diff 21 22 }) 22 23 23 - const diff = computed(() => props.error.diff ? filter.value.toHtml(props.error.diff) : undefined) 24 + const diff = computed(() => props.error.diff ? filter.value.toHtml(escapeHtml(props.error.diff)) : undefined) 24 25 </script> 25 26 26 27 <template>