bun-match-svg 0.0.6 ā 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/bun.lockb +0 -0
- package/cli.ts +71 -0
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
A custom matcher for Bun tests to compare SVG snapshots.
|
|
4
4
|
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
The fastest way to get started is to use the CLI to initialize your project:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bunx bun-match-svg init
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
This will:
|
|
14
|
+
1. Create an example test in `tests/svg.test.ts`
|
|
15
|
+
2. Set up automatic preloading by creating:
|
|
16
|
+
- `tests/fixtures/preload.ts`
|
|
17
|
+
- `bunfig.toml`
|
|
18
|
+
|
|
19
|
+
You can then run the example test:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bun test
|
|
23
|
+
```
|
|
24
|
+
|
|
5
25
|
## Installation
|
|
6
26
|
|
|
7
27
|
```bash
|
package/bun.lockb
CHANGED
|
Binary file
|
package/cli.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { mkdir, writeFile } from "node:fs/promises"
|
|
4
|
+
import { spawn } from "node:child_process"
|
|
5
|
+
|
|
6
|
+
const EXAMPLE_TEST = `import { expect, test } from "bun:test"
|
|
7
|
+
import "bun-match-svg"
|
|
8
|
+
|
|
9
|
+
const testSvg = \`<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
|
|
10
|
+
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
|
|
11
|
+
</svg>\`
|
|
12
|
+
|
|
13
|
+
test("svg snapshot example", async () => {
|
|
14
|
+
// First run will create the snapshot
|
|
15
|
+
// Subsequent runs will compare against the saved snapshot
|
|
16
|
+
await expect(testSvg).toMatchSvgSnapshot(import.meta.path, "example")
|
|
17
|
+
})
|
|
18
|
+
`
|
|
19
|
+
|
|
20
|
+
const PRELOAD_FILE = `import "bun-match-svg"`
|
|
21
|
+
|
|
22
|
+
const BUNFIG = `[test]
|
|
23
|
+
preload = ["./tests/fixtures/preload.ts"]`
|
|
24
|
+
|
|
25
|
+
async function installDependency() {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
const install = spawn('bun', ['add', '-d', 'bun-match-svg'], {
|
|
28
|
+
stdio: 'inherit'
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
install.on('close', (code) => {
|
|
32
|
+
if (code === 0) {
|
|
33
|
+
resolve(undefined)
|
|
34
|
+
} else {
|
|
35
|
+
reject(new Error(`Installation failed with code ${code}`))
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function init() {
|
|
42
|
+
try {
|
|
43
|
+
console.log("š¦ Installing bun-match-svg...")
|
|
44
|
+
await installDependency()
|
|
45
|
+
|
|
46
|
+
await mkdir("tests/fixtures", { recursive: true })
|
|
47
|
+
|
|
48
|
+
await writeFile("tests/svg.test.ts", EXAMPLE_TEST)
|
|
49
|
+
|
|
50
|
+
await writeFile("tests/fixtures/preload.ts", PRELOAD_FILE)
|
|
51
|
+
|
|
52
|
+
await writeFile("bunfig.toml", BUNFIG)
|
|
53
|
+
|
|
54
|
+
console.log("ā
Installed bun-match-svg")
|
|
55
|
+
console.log("ā
Created example test in tests/svg.test.ts")
|
|
56
|
+
console.log("ā
Created preload file in tests/fixtures/preload.ts")
|
|
57
|
+
console.log("ā
Created bunfig.toml")
|
|
58
|
+
console.log("\nš You can now run: bun test")
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error("ā Error during initialization:", error)
|
|
61
|
+
process.exit(1)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const command = process.argv[2]
|
|
66
|
+
|
|
67
|
+
if (command === "init") {
|
|
68
|
+
init().catch(console.error)
|
|
69
|
+
} else {
|
|
70
|
+
console.log("Usage: bunx bun-match-svg init")
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-match-svg",
|
|
3
3
|
"module": "index.ts",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"bun-match-svg": "./cli.ts"
|
|
8
|
+
},
|
|
6
9
|
"devDependencies": {
|
|
7
|
-
"@types/bun": "latest"
|
|
10
|
+
"@types/bun": "latest",
|
|
11
|
+
"biome": "^0.3.3"
|
|
8
12
|
},
|
|
9
13
|
"peerDependencies": {
|
|
10
14
|
"typescript": "^5.0.0"
|
|
@@ -14,6 +18,8 @@
|
|
|
14
18
|
},
|
|
15
19
|
"scripts": {
|
|
16
20
|
"test": "bun test",
|
|
17
|
-
"build": "echo 'no build step'"
|
|
21
|
+
"build": "echo 'no build step'",
|
|
22
|
+
"format": "biome format . --write",
|
|
23
|
+
"format:check": "biome format ."
|
|
18
24
|
}
|
|
19
25
|
}
|