-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runtime-dom): Trusted Types compatibility (#10844)
- Loading branch information
1 parent
998dca5
commit 6d4eb94
Showing
8 changed files
with
187 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" href="data:;base64,iVBORw0KGgo="> | ||
<meta | ||
http-equiv="content-security-policy" | ||
content="require-trusted-types-for 'script'" | ||
/> | ||
<title>Vue App</title> | ||
<script src="../../dist/vue.global.js"></script> | ||
</head> | ||
|
||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { once } from 'node:events' | ||
import { createServer } from 'node:http' | ||
import path from 'node:path' | ||
import { beforeAll } from 'vitest' | ||
import serveHandler from 'serve-handler' | ||
|
||
import { E2E_TIMEOUT, setupPuppeteer } from './e2eUtils' | ||
|
||
// use the `vue` package root as the public directory | ||
// because we need to serve the Vue runtime for the tests | ||
const serverRoot = path.resolve(import.meta.dirname, '../../') | ||
const testPort = 9090 | ||
const basePath = path.relative( | ||
serverRoot, | ||
path.resolve(import.meta.dirname, './trusted-types.html'), | ||
) | ||
const baseUrl = `http://localhost:${testPort}/${basePath}` | ||
|
||
const { page, html } = setupPuppeteer() | ||
|
||
let server: ReturnType<typeof createServer> | ||
beforeAll(async () => { | ||
// sets up the static server | ||
server = createServer((req, res) => { | ||
return serveHandler(req, res, { | ||
public: serverRoot, | ||
cleanUrls: false, | ||
}) | ||
}) | ||
|
||
server.listen(testPort) | ||
await once(server, 'listening') | ||
}) | ||
|
||
afterAll(async () => { | ||
server.close() | ||
await once(server, 'close') | ||
}) | ||
|
||
describe('e2e: trusted types', () => { | ||
beforeEach(async () => { | ||
await page().goto(baseUrl) | ||
await page().waitForSelector('#app') | ||
}) | ||
|
||
test( | ||
'should render the hello world app', | ||
async () => { | ||
await page().evaluate(() => { | ||
const { createApp, ref, h } = (window as any).Vue | ||
createApp({ | ||
setup() { | ||
const msg = ref('✅success: hello world') | ||
return function render() { | ||
return h('div', msg.value) | ||
} | ||
}, | ||
}).mount('#app') | ||
}) | ||
expect(await html('#app')).toContain('<div>✅success: hello world</div>') | ||
}, | ||
E2E_TIMEOUT, | ||
) | ||
|
||
test( | ||
'should render static vnode without error', | ||
async () => { | ||
await page().evaluate(() => { | ||
const { createApp, createStaticVNode } = (window as any).Vue | ||
createApp({ | ||
render() { | ||
return createStaticVNode('<div>✅success: static vnode</div>') | ||
}, | ||
}).mount('#app') | ||
}) | ||
expect(await html('#app')).toContain('<div>✅success: static vnode</div>') | ||
}, | ||
E2E_TIMEOUT, | ||
) | ||
|
||
test( | ||
'should accept v-html with custom policy', | ||
async () => { | ||
await page().evaluate(() => { | ||
const testPolicy = (window as any).trustedTypes.createPolicy('test', { | ||
createHTML: (input: string): string => input, | ||
}) | ||
|
||
const { createApp, ref, h } = (window as any).Vue | ||
createApp({ | ||
setup() { | ||
const msg = ref('✅success: v-html') | ||
return function render() { | ||
return h('div', { innerHTML: testPolicy.createHTML(msg.value) }) | ||
} | ||
}, | ||
}).mount('#app') | ||
}) | ||
expect(await html('#app')).toContain('<div>✅success: v-html</div>') | ||
}, | ||
E2E_TIMEOUT, | ||
) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.