bun-match-svg 0.0.6 ā 0.0.8
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/index.ts +6 -6
- package/package.json +9 -3
- package/tsconfig.json +11 -1
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/index.ts
CHANGED
|
@@ -25,7 +25,7 @@ async function toMatchSvgSnapshot(
|
|
|
25
25
|
const updateSnapshot =
|
|
26
26
|
process.argv.includes("--update-snapshots") ||
|
|
27
27
|
process.argv.includes("-u") ||
|
|
28
|
-
Boolean(process.env
|
|
28
|
+
Boolean(process.env["BUN_UPDATE_SNAPSHOTS"])
|
|
29
29
|
|
|
30
30
|
if (!fs.existsSync(filePath) || updateSnapshot) {
|
|
31
31
|
console.log("Writing snapshot to", filePath)
|
|
@@ -38,7 +38,7 @@ async function toMatchSvgSnapshot(
|
|
|
38
38
|
|
|
39
39
|
const existingSnapshot = fs.readFileSync(filePath, "utf-8")
|
|
40
40
|
|
|
41
|
-
const result = await looksSame(
|
|
41
|
+
const result: any = await looksSame(
|
|
42
42
|
Buffer.from(received),
|
|
43
43
|
Buffer.from(existingSnapshot),
|
|
44
44
|
{
|
|
@@ -75,8 +75,8 @@ async function toMatchMultipleSvgSnapshots(
|
|
|
75
75
|
testPathOriginal: string,
|
|
76
76
|
svgNames: string[],
|
|
77
77
|
): Promise<MatcherResult> {
|
|
78
|
-
const passed = []
|
|
79
|
-
const failed = []
|
|
78
|
+
const passed: any[] = []
|
|
79
|
+
const failed: any[] = []
|
|
80
80
|
for (let index = 0; index < svgNames.length; index++) {
|
|
81
81
|
const svgName = svgNames[index]
|
|
82
82
|
const received = await receivedMaybePromise
|
|
@@ -94,7 +94,7 @@ async function toMatchMultipleSvgSnapshots(
|
|
|
94
94
|
const updateSnapshot =
|
|
95
95
|
process.argv.includes("--update-snapshots") ||
|
|
96
96
|
process.argv.includes("-u") ||
|
|
97
|
-
Boolean(process.env
|
|
97
|
+
Boolean(process.env["BUN_UPDATE_SNAPSHOTS"])
|
|
98
98
|
|
|
99
99
|
if (!fs.existsSync(filePath) || updateSnapshot) {
|
|
100
100
|
console.log("Writing snapshot to", filePath)
|
|
@@ -108,7 +108,7 @@ async function toMatchMultipleSvgSnapshots(
|
|
|
108
108
|
|
|
109
109
|
const existingSnapshot = fs.readFileSync(filePath, "utf-8")
|
|
110
110
|
|
|
111
|
-
const result = await looksSame(
|
|
111
|
+
const result: any = await looksSame(
|
|
112
112
|
Buffer.from(received[index] as any),
|
|
113
113
|
Buffer.from(existingSnapshot),
|
|
114
114
|
{
|
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.8",
|
|
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
|
}
|
package/tsconfig.json
CHANGED
|
@@ -13,6 +13,16 @@
|
|
|
13
13
|
"allowImportingTsExtensions": true,
|
|
14
14
|
"verbatimModuleSyntax": true,
|
|
15
15
|
"noEmit": true,
|
|
16
|
+
"noImplicitAny": true,
|
|
17
|
+
"strictNullChecks": true,
|
|
18
|
+
"strictFunctionTypes": true,
|
|
19
|
+
"strictBindCallApply": true,
|
|
20
|
+
"strictPropertyInitialization": true,
|
|
21
|
+
"noImplicitThis": true,
|
|
22
|
+
"useUnknownInCatchVariables": true,
|
|
23
|
+
"alwaysStrict": true,
|
|
24
|
+
"exactOptionalPropertyTypes": false,
|
|
25
|
+
"noImplicitReturns": true,
|
|
16
26
|
|
|
17
27
|
// Best practices
|
|
18
28
|
"strict": true,
|
|
@@ -22,6 +32,6 @@
|
|
|
22
32
|
// Some stricter flags (disabled by default)
|
|
23
33
|
"noUnusedLocals": false,
|
|
24
34
|
"noUnusedParameters": false,
|
|
25
|
-
"noPropertyAccessFromIndexSignature":
|
|
35
|
+
"noPropertyAccessFromIndexSignature": true
|
|
26
36
|
}
|
|
27
37
|
}
|