Skip to content

Commit 8d2e7aa

Browse files
committed
Added tests for multiple versions.
1 parent 204e004 commit 8d2e7aa

22 files changed

+4896
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"filename": "OneUnsafe.svelte",
3+
"parsed": true,
4+
"error": null,
5+
"warnings": [
6+
{
7+
"filename": "OneUnsafe.svelte",
8+
"message": "Unsafe raw HTML insertion without sanitizer",
9+
"start": {
10+
"line": 1,
11+
"column": 12
12+
},
13+
"end": {
14+
"line": 1,
15+
"column": 45
16+
}
17+
}
18+
]
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>{@html '<p>this is some unsafe html</p>'}</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"filename": "OneUnsafeWithIgnoreComment.svelte",
3+
"parsed": true,
4+
"error": null,
5+
"warnings": []
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div>
2+
<!-- svelte-ignore unsafe_html -->
3+
{@html '<p>this is some unsafe html</p>'}
4+
</div>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"filename": "OneUnsafeWithScript.svelte",
3+
"parsed": true,
4+
"error": null,
5+
"warnings": [
6+
{
7+
"filename": "OneUnsafeWithScript.svelte",
8+
"message": "Unsafe raw HTML insertion without sanitizer",
9+
"start": {
10+
"line": 5,
11+
"column": 12
12+
},
13+
"end": {
14+
"line": 5,
15+
"column": 45
16+
}
17+
}
18+
]
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
let title = "One Unsafe With Script";
3+
</script>
4+
5+
<div>{@html '<p>this is some unsafe html</p>'}</div>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"filename": "TwoUnsafe.svelte",
3+
"parsed": true,
4+
"error": null,
5+
"warnings": [
6+
{
7+
"filename": "TwoUnsafe.svelte",
8+
"message": "Unsafe raw HTML insertion without sanitizer",
9+
"start": {
10+
"line": 1,
11+
"column": 10
12+
},
13+
"end": {
14+
"line": 1,
15+
"column": 28
16+
}
17+
},
18+
{
19+
"filename": "TwoUnsafe.svelte",
20+
"message": "Unsafe raw HTML insertion without sanitizer",
21+
"start": {
22+
"line": 4,
23+
"column": 10
24+
},
25+
"end": {
26+
"line": 4,
27+
"column": 48
28+
}
29+
}
30+
]
31+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<p>{@html '<b>Bold Text</b>'}</p>
2+
3+
4+
<p>{@html '<script>alert("XSS Attack")</script>'}</p>

tests/run-all.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { exec } from "child_process";
2+
import path from "path";
3+
import { promisify } from "util";
4+
5+
const asyncExec = promisify(exec);
6+
7+
const dirs = ["svelte3", "svelte4", "svelte5-legacy"];
8+
const cwd = process.cwd();
9+
10+
11+
async function testDir(dir) {
12+
const testDir = path.join(cwd, "tests", dir);
13+
console.log(`\n🧹 Testing ${dir}...`);
14+
15+
try {
16+
// Cleanup
17+
await asyncExec("rm -rf node_modules package-lock.json", { cwd: testDir });
18+
// await asyncExec("npm cache clean --force");
19+
20+
// Install
21+
await asyncExec("npm install", { cwd: testDir, stdio: "inherit" });
22+
23+
// Run tests
24+
await asyncExec("npm test", { cwd: testDir, stdio: "inherit" });
25+
26+
console.log(`✅ ${dir} passed`);
27+
} catch (err) {
28+
console.error(`❌ ${dir} failed:\n`, err.stderr || err.message);
29+
process.exitCode = 1;
30+
}
31+
}
32+
33+
(async () => {
34+
console.log("🚀 Running tests in parallel...\n");
35+
await Promise.all(dirs.map(testDir));
36+
console.log("\n✅ All tests completed.");
37+
})();

0 commit comments

Comments
 (0)