bun-match-svg 0.0.1 → 0.0.2

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.
@@ -0,0 +1 @@
1
+ * @seveibar @tscircuit/core
@@ -0,0 +1,26 @@
1
+ # Created using @tscircuit/plop (npm install -g @tscircuit/plop)
2
+ name: Format Check
3
+
4
+ on:
5
+ push:
6
+ branches: [main]
7
+ pull_request:
8
+ branches: [main]
9
+
10
+ jobs:
11
+ format-check:
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+
17
+ - name: Setup bun
18
+ uses: oven-sh/setup-bun@v1
19
+ with:
20
+ bun-version: latest
21
+
22
+ - name: Install dependencies
23
+ run: bun install
24
+
25
+ - name: Run format check
26
+ run: bun run format:check
@@ -0,0 +1,25 @@
1
+ # Created using @tscircuit/plop (npm install -g @tscircuit/plop)
2
+ name: Publish to npm
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v3
12
+ - name: Setup bun
13
+ uses: oven-sh/setup-bun@v1
14
+ with:
15
+ bun-version: latest
16
+ - uses: actions/setup-node@v3
17
+ with:
18
+ node-version: 20
19
+ registry-url: https://registry.npmjs.org/
20
+ - run: npm install -g pver
21
+ - run: bun install --frozen-lockfile
22
+ - run: bun run build
23
+ - run: pver release
24
+ env:
25
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,24 @@
1
+ # Created using @tscircuit/plop (npm install -g @tscircuit/plop)
2
+ name: Bun Test
3
+
4
+ on:
5
+ pull_request:
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - name: Checkout code
13
+ uses: actions/checkout@v2
14
+
15
+ - name: Setup bun
16
+ uses: oven-sh/setup-bun@v1
17
+ with:
18
+ bun-version: latest
19
+
20
+ - name: Install dependencies
21
+ run: bun install
22
+
23
+ - name: Run tests
24
+ run: bun test
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 tscircuit Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,23 +1,85 @@
1
1
  # bun-match-svg
2
2
 
3
+ A custom matcher for Bun tests to compare SVG snapshots.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add -D bun-match-svg
9
+ ```
10
+
3
11
  ## Usage
4
12
 
13
+ ### Basic Usage
14
+
15
+ Import the library in your test file:
16
+
5
17
  ```ts
6
18
  import "bun-match-svg"
7
19
 
8
- test("getAllDimensionsForSchematicBox 1", () => {
9
- const params: Parameters<typeof getAllDimensionsForSchematicBox>[0] = {
10
- schWidth: 1,
11
- schPinSpacing: 0.2,
12
- schPinStyle: {},
13
- pinCount: 8,
14
- }
20
+ test("your SVG test", () => {
21
+ const svgContent = generateSomeSvg() // Your function to generate SVG
22
+ expect(svgContent).toMatchSvgSnapshot(import.meta.path, "uniqueName")
23
+ })
24
+ ```
15
25
 
16
- const dimensions = getAllDimensionsForSchematicBox(params)
26
+ The `toMatchSvgSnapshot` matcher takes two arguments:
17
27
 
18
- expect(getSchematicBoxSvg(dimensions)).toMatchSvgSnapshot(
19
- import.meta.path,
20
- "schematicbox1"
21
- )
22
- })
28
+ 1. `import.meta.path`: The path of the current test file.
29
+ 2. `uniqueName` (optional): A unique name for the snapshot. If not provided, it will use the test file name.
30
+
31
+ ### Automatically Preload
32
+
33
+ To make `toMatchSvgSnapshot` available in all your test files without importing it in each one:
34
+
35
+ 1. Create a file `tests/fixtures/preload.ts` with the following content:
36
+
37
+ ```ts
38
+ import "bun-match-svg"
39
+ ```
40
+
41
+ 2. Define a `bunfig.toml` file in your project root with:
42
+
43
+ ```toml
44
+ [test]
45
+ preload = ["./tests/fixtures/preload.ts"]
23
46
  ```
47
+
48
+ Now `toMatchSvgSnapshot` will be automatically available in every test file.
49
+
50
+ ## How It Works
51
+
52
+ - On first run, it creates a snapshot of your SVG.
53
+ - On subsequent runs, it compares the current SVG with the snapshot.
54
+ - If differences are found, it generates a diff image.
55
+
56
+ ## Updating Snapshots
57
+
58
+ To update existing snapshots, run your tests with:
59
+
60
+ ```bash
61
+ bun test --update-snapshots
62
+ ```
63
+
64
+ Or set the environment variable:
65
+
66
+ ```bash
67
+ BUN_UPDATE_SNAPSHOTS=1 bun test
68
+ ```
69
+
70
+ ## Configuration
71
+
72
+ The matcher uses `looks-same` for comparison with these default settings:
73
+
74
+ - `strict: false`
75
+ - `tolerance: 2`
76
+
77
+ There currently isn't a way to configure this, but PRs welcome!
78
+
79
+ ## Contributing
80
+
81
+ Contributions are welcome! Please feel free to submit a Pull Request.
82
+
83
+ ## License
84
+
85
+ This project is open source and available under the [MIT License](LICENSE).
package/index.ts CHANGED
@@ -6,10 +6,11 @@ import looksSame from "looks-same"
6
6
  async function toMatchSvgSnapshot(
7
7
  // biome-ignore lint/suspicious/noExplicitAny: bun doesn't expose
8
8
  this: any,
9
- received: string,
9
+ receivedMaybePromise: string | Promise<string>,
10
10
  testPathOriginal: string,
11
11
  svgName?: string,
12
12
  ): Promise<MatcherResult> {
13
+ const received = await receivedMaybePromise
13
14
  const testPath = testPathOriginal.replace(/\.test\.tsx?$/, "")
14
15
  const snapshotDir = path.join(path.dirname(testPath), "__snapshots__")
15
16
  const snapshotName = svgName
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-match-svg",
3
3
  "module": "index.ts",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "type": "module",
6
6
  "devDependencies": {
7
7
  "@types/bun": "latest"
@@ -13,6 +13,7 @@
13
13
  "looks-same": "^9.0.1"
14
14
  },
15
15
  "scripts": {
16
- "test": "bun test"
16
+ "test": "bun test",
17
+ "build": "echo 'no build step'"
17
18
  }
18
- }
19
+ }