VS Code extension that previews Archify diagrams from their JSON sources (live, as you type) and opens rendered Archify HTML in a viewer tab. Bundles the Archify 3.0.1 renderer and runs it on VS Code's Node runtime. Adds validation diagnostics, JSON schema help, source-link navigation, export saving, render-to-file and open-in-browser commands. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
38 lines
1.6 KiB
TypeScript
38 lines
1.6 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { test } from 'node:test';
|
|
import { prepareDiagramHtml } from '../src/webviewHtml';
|
|
|
|
const page = `<!DOCTYPE html><html><head>
|
|
<meta http-equiv="Content-Security-Policy" content="default-src *">
|
|
<script>var a = 1;</script>
|
|
<script id="data" type="application/json">{"x":1}</script>
|
|
</head><body><script>var b = 2;</script></body></html>`;
|
|
|
|
test('adds one CSP and nonces every inline script', () => {
|
|
const html = prepareDiagramHtml(page, { cspSource: 'vscode-resource:', nonce: 'N0NCE', theme: 'light' });
|
|
const csps = html.match(/Content-Security-Policy/g) ?? [];
|
|
assert.equal(csps.length, 1);
|
|
assert.match(html, /script-src ('|')nonce-N0NCE/);
|
|
const scripts = html.match(/<script\b[^>]*>/g) ?? [];
|
|
assert.equal(scripts.length, 4, 'bridge plus the three page scripts');
|
|
for (const tag of scripts) assert.match(tag, /nonce="N0NCE"/);
|
|
});
|
|
|
|
test('bridge runs before the page scripts and pins the theme', () => {
|
|
const html = prepareDiagramHtml(page, { cspSource: 'x', nonce: 'n', theme: 'dark', hash: '#focus=api' });
|
|
const bridge = html.indexOf('acquireVsCodeApi');
|
|
assert.ok(bridge > 0 && bridge < html.indexOf('var a = 1'));
|
|
assert.match(html, /"theme":"dark"/);
|
|
assert.match(html, /"hash":"#focus=api"/);
|
|
});
|
|
|
|
test('embedded config cannot close the script element', () => {
|
|
const html = prepareDiagramHtml(page, {
|
|
cspSource: 'x',
|
|
nonce: 'n',
|
|
theme: undefined,
|
|
notice: { kind: 'warning', text: '</script><script>alert(1)</script>' },
|
|
});
|
|
assert.ok(!html.includes('</script><script>alert(1)'));
|
|
});
|