@altano/vitest-plugins 1.1.2 → 2.0.0
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/package.json +21 -17
- package/src/matchers/types.d.ts +6 -5
- package/CHANGELOG.md +0 -54
- package/src/serializers/.prettierrc.json +0 -5
- package/tests/tsconfig.json +0 -9
- package/tests/unit/matchers/readme.spec.ts +0 -21
- package/tests/unit/matchers/response/toHaveHeader.spec.ts +0 -49
- package/tests/unit/matchers/response/toHaveStatus.spec.ts +0 -42
- package/tests/unit/matchers/toBeDirectory.spec.ts +0 -33
- package/tests/unit/matchers/toBeFile.spec.ts +0 -20
- package/tests/unit/matchers/toBePath.spec.ts +0 -32
- package/tests/unit/matchers/toEqualFile.spec.ts +0 -28
- package/tests/unit/matchers/toHaveExifProperty.spec.ts +0 -59
- package/tests/unit/matchers/toMatchError.spec.ts +0 -45
- package/tests/unit/matchers/toThrowErrorMatching.spec.ts +0 -31
- package/tests/unit/serializers/absolutePath.spec.ts +0 -16
- package/tests/unit/serializers/html.spec.ts +0 -58
- package/tests/unit/serializers/url.spec.ts +0 -14
- package/tests/unit/serializers/vFile.spec.ts +0 -80
- package/tsconfig.json +0 -4
- package/vitest.config.ts +0 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altano/vitest-plugins",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Custom matchers and snapshot serializers to enhance vitest",
|
|
5
5
|
"homepage": "https://github.com/altano/npm-packages/tree/main/packages/vitest-plugins",
|
|
6
6
|
"repository": {
|
|
@@ -11,10 +11,14 @@
|
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"author": {
|
|
13
13
|
"name": "Alan Norbauer",
|
|
14
|
-
"email": "
|
|
14
|
+
"email": "alan@norbauer.com",
|
|
15
15
|
"url": "https://alan.norbauer.com"
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
|
18
|
+
"sideEffects": true,
|
|
19
|
+
"files": [
|
|
20
|
+
"src/**/*.ts"
|
|
21
|
+
],
|
|
18
22
|
"exports": {
|
|
19
23
|
"./matchers": {
|
|
20
24
|
"types": "./src/matchers/types.d.ts",
|
|
@@ -26,26 +30,26 @@
|
|
|
26
30
|
"./serializers/*": "./src/serializers/*.ts"
|
|
27
31
|
},
|
|
28
32
|
"dependencies": {
|
|
29
|
-
"@prettier/sync": "^0.
|
|
33
|
+
"@prettier/sync": "^0.6.1",
|
|
30
34
|
"exifr": "^7.1.3",
|
|
31
|
-
"serialize-error": "^
|
|
32
|
-
"vfile": "^6.0.3"
|
|
33
|
-
"vitest": "^4.1.0"
|
|
35
|
+
"serialize-error": "^13.0.2",
|
|
36
|
+
"vfile": "^6.0.3"
|
|
34
37
|
},
|
|
35
38
|
"devDependencies": {
|
|
36
|
-
"@types/node": "^
|
|
37
|
-
"@vitest/coverage-v8": "^
|
|
38
|
-
"@vitest/expect": "^
|
|
39
|
+
"@types/node": "^26.6.4",
|
|
40
|
+
"@vitest/coverage-v8": "^5.0.3",
|
|
41
|
+
"@vitest/expect": "^5.0.3",
|
|
39
42
|
"depcheck": "^1.4.7",
|
|
40
|
-
"eslint": "^
|
|
41
|
-
"prettier": "
|
|
42
|
-
"typescript": "^
|
|
43
|
-
"vite": "^
|
|
44
|
-
"vitest": "^
|
|
43
|
+
"eslint": "^10.12.0",
|
|
44
|
+
"prettier": "3.9.9",
|
|
45
|
+
"typescript": "^6.0.3",
|
|
46
|
+
"vite": "^8.3.2",
|
|
47
|
+
"vitest": "^5.0.3",
|
|
45
48
|
"@altano/tsconfig": "0.0.1"
|
|
46
49
|
},
|
|
47
50
|
"peerDependencies": {
|
|
48
|
-
"prettier": "3.x.x"
|
|
51
|
+
"prettier": "3.x.x",
|
|
52
|
+
"vitest": "5.x.x"
|
|
49
53
|
},
|
|
50
54
|
"publishConfig": {
|
|
51
55
|
"access": "public"
|
|
@@ -55,8 +59,8 @@
|
|
|
55
59
|
"check:types:test": "tsc --noEmit --project ./tests/tsconfig.json",
|
|
56
60
|
"check:unused-dependencies": "depcheck",
|
|
57
61
|
"clean": "rm -rf .turbo && rm -rf .tsbuildinfo && rm -rf node_modules && rm -rf dist",
|
|
58
|
-
"format": "prettier --check
|
|
59
|
-
"format:fix": "prettier --write
|
|
62
|
+
"format": "prettier --check .",
|
|
63
|
+
"format:fix": "prettier --write .",
|
|
60
64
|
"lint": "eslint",
|
|
61
65
|
"lint:fix": "TIMING=1 pnpm lint --fix",
|
|
62
66
|
"lint:timing": "TIMING=1 pnpm lint",
|
package/src/matchers/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Have to import these to get declaration merging.
|
|
2
2
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3
|
-
import type {
|
|
3
|
+
import type { Matchers } from "vitest";
|
|
4
4
|
|
|
5
5
|
interface CustomMatchers<R = unknown> {
|
|
6
6
|
/**
|
|
@@ -52,9 +52,10 @@ interface ResponseMatchers<R = unknown> {
|
|
|
52
52
|
toHaveStatus(expectedStatus: number): R;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
56
55
|
declare module "vitest" {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
// Type parameters must match the original declaration exactly, so the
|
|
57
|
+
// unused `T` has to stay.
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
59
|
+
interface Matchers<R extends void | Promise<void>, T>
|
|
60
|
+
extends CustomMatchers<R>, ResponseMatchers<R> {}
|
|
60
61
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# @altano/vitest-plugins
|
|
2
|
-
|
|
3
|
-
## 1.1.2
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- 72b15cc: update dependencies
|
|
8
|
-
- fb3c931: upgrade tsdown
|
|
9
|
-
|
|
10
|
-
## 1.1.1
|
|
11
|
-
|
|
12
|
-
### Patch Changes
|
|
13
|
-
|
|
14
|
-
- b461e76: fix readme
|
|
15
|
-
|
|
16
|
-
## 1.1.0
|
|
17
|
-
|
|
18
|
-
### Minor Changes
|
|
19
|
-
|
|
20
|
-
- e07daa2: add explicit types export for matchers
|
|
21
|
-
|
|
22
|
-
## 1.0.0
|
|
23
|
-
|
|
24
|
-
### Major Changes
|
|
25
|
-
|
|
26
|
-
- 989abbb: added snapshot serializers and a matcher
|
|
27
|
-
|
|
28
|
-
### Patch Changes
|
|
29
|
-
|
|
30
|
-
- 4c2162f: remove unused dependencies
|
|
31
|
-
|
|
32
|
-
## 0.2.0
|
|
33
|
-
|
|
34
|
-
### Minor Changes
|
|
35
|
-
|
|
36
|
-
- e936f78: removed sideEffects:true from package.json
|
|
37
|
-
|
|
38
|
-
## 0.1.1
|
|
39
|
-
|
|
40
|
-
### Patch Changes
|
|
41
|
-
|
|
42
|
-
- 2266961: fix import extensions for node libraries
|
|
43
|
-
|
|
44
|
-
## 0.1.0
|
|
45
|
-
|
|
46
|
-
### Minor Changes
|
|
47
|
-
|
|
48
|
-
- f2dda42: new filesystem matchers
|
|
49
|
-
|
|
50
|
-
## 0.0.2
|
|
51
|
-
|
|
52
|
-
### Patch Changes
|
|
53
|
-
|
|
54
|
-
- 7d75608: initial package publish
|
package/tests/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import "../../../src/matchers/setup";
|
|
3
|
-
|
|
4
|
-
describe("readme", () => {
|
|
5
|
-
it("should describe toMatchError", () => {
|
|
6
|
-
expect(new Error("face")).toMatchError(
|
|
7
|
-
expect.objectContaining({
|
|
8
|
-
stack: expect.stringContaining("readme.spec.ts") as unknown,
|
|
9
|
-
}),
|
|
10
|
-
);
|
|
11
|
-
});
|
|
12
|
-
it("should describe toThrowErrorMatching", () => {
|
|
13
|
-
expect(() => {
|
|
14
|
-
throw new Error("face");
|
|
15
|
-
}).toThrowErrorMatching(
|
|
16
|
-
expect.objectContaining({
|
|
17
|
-
stack: expect.stringContaining("readme.spec.ts") as unknown,
|
|
18
|
-
}),
|
|
19
|
-
);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import "../../../../src/matchers/setup";
|
|
3
|
-
|
|
4
|
-
describe("toHaveHeader", () => {
|
|
5
|
-
const r = new Response("", {
|
|
6
|
-
headers: {
|
|
7
|
-
"Content-Type": "image/png",
|
|
8
|
-
},
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it("should pass when the property exists", async () => {
|
|
12
|
-
expect(r).toHaveHeader("Content-Type");
|
|
13
|
-
});
|
|
14
|
-
it("should pass when the property doesn't exist", async () => {
|
|
15
|
-
expect(r).not.toHaveHeader("face");
|
|
16
|
-
});
|
|
17
|
-
it("should pass when the property value is correct", async () => {
|
|
18
|
-
expect(r).toHaveHeader("Content-Type", "image/png");
|
|
19
|
-
});
|
|
20
|
-
it("should pass when the property value is incorrect", async () => {
|
|
21
|
-
expect(r).not.toHaveHeader("Content-Type", 15);
|
|
22
|
-
expect(r).not.toHaveHeader("face", 15);
|
|
23
|
-
});
|
|
24
|
-
it("should error when the property should not exist but does", async () => {
|
|
25
|
-
expect(() =>
|
|
26
|
-
expect(r).not.toHaveHeader("Content-Type"),
|
|
27
|
-
).toThrowErrorMatchingInlineSnapshot(`[Error: Received should not have the header "Content-Type"]`);
|
|
28
|
-
});
|
|
29
|
-
it("should error when the property should exist but doesn't", async () => {
|
|
30
|
-
expect(() =>
|
|
31
|
-
expect(r).toHaveHeader("face"),
|
|
32
|
-
).toThrowErrorMatchingInlineSnapshot(`[Error: Received does not have the header "face"]`);
|
|
33
|
-
});
|
|
34
|
-
it("should error when the value should not match but does", async () => {
|
|
35
|
-
expect(() =>
|
|
36
|
-
expect(r).not.toHaveHeader("Content-Type", "image/png"),
|
|
37
|
-
).toThrowErrorMatchingInlineSnapshot(`[Error: Header "Content-Type" should not be expected value]`);
|
|
38
|
-
});
|
|
39
|
-
it("should error when the value should match but doesn't", async () => {
|
|
40
|
-
expect(() =>
|
|
41
|
-
expect(r).toHaveHeader("Content-Type", 17),
|
|
42
|
-
).toThrowErrorMatchingInlineSnapshot(`[Error: Header "Content-Type" is not expected value]`);
|
|
43
|
-
});
|
|
44
|
-
it("should error when a non-buffer is passed in", async () => {
|
|
45
|
-
expect(() =>
|
|
46
|
-
expect(1234).toHaveHeader("face"),
|
|
47
|
-
).toThrowErrorMatchingInlineSnapshot(`[TypeError: Cannot read properties of undefined (reading 'has')]`);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import "../../../../src/matchers/setup";
|
|
3
|
-
|
|
4
|
-
const getResponse = (status: number): Response =>
|
|
5
|
-
new Response("", {
|
|
6
|
-
status,
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
describe("toHaveStatus", () => {
|
|
10
|
-
const status200 = getResponse(200);
|
|
11
|
-
const status404 = getResponse(404);
|
|
12
|
-
|
|
13
|
-
it("should pass when the status is correct", async () => {
|
|
14
|
-
expect(status200).toHaveStatus(200);
|
|
15
|
-
expect(status404).toHaveStatus(404);
|
|
16
|
-
});
|
|
17
|
-
it("should pass when the status is incorrect", async () => {
|
|
18
|
-
expect(status200).not.toHaveStatus(500);
|
|
19
|
-
expect(status404).not.toHaveStatus(500);
|
|
20
|
-
});
|
|
21
|
-
it("should error when the value should not match but does", async () => {
|
|
22
|
-
expect(() =>
|
|
23
|
-
expect(status200).not.toHaveStatus(200),
|
|
24
|
-
).toThrowErrorMatchingInlineSnapshot(
|
|
25
|
-
`[Error: Status should not be expected value]`,
|
|
26
|
-
);
|
|
27
|
-
});
|
|
28
|
-
it("should error when the value should match but doesn't", async () => {
|
|
29
|
-
expect(() =>
|
|
30
|
-
expect(status200).toHaveStatus(500),
|
|
31
|
-
).toThrowErrorMatchingInlineSnapshot(
|
|
32
|
-
`[Error: Status is not expected value]`,
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
it("should error when a non-Response is passed in", async () => {
|
|
36
|
-
expect(() =>
|
|
37
|
-
expect(1234).toHaveStatus(3),
|
|
38
|
-
).toThrowErrorMatchingInlineSnapshot(
|
|
39
|
-
`[Error: Status is not expected value]`,
|
|
40
|
-
);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import os from "node:os";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import "../../../src/matchers/setup";
|
|
4
|
-
|
|
5
|
-
describe("matchers", () => {
|
|
6
|
-
describe("toBeDirectory", () => {
|
|
7
|
-
it("should recognize the root", () => {
|
|
8
|
-
expect("/").toBeDirectory();
|
|
9
|
-
});
|
|
10
|
-
it("should recognize the home directory", () => {
|
|
11
|
-
expect(os.homedir()).toBeDirectory();
|
|
12
|
-
});
|
|
13
|
-
it("should recognize this test's directory", () => {
|
|
14
|
-
expect(import.meta.dirname).toBeDirectory();
|
|
15
|
-
});
|
|
16
|
-
it("should not match on garbage", () => {
|
|
17
|
-
expect("fucking garbage").not.toBeDirectory();
|
|
18
|
-
});
|
|
19
|
-
it("should not match on a made up dir", () => {
|
|
20
|
-
expect("/some/plausible/horseshit").not.toBeDirectory();
|
|
21
|
-
});
|
|
22
|
-
it("should NOT recognize this test file as a directory", () => {
|
|
23
|
-
expect(import.meta.filename).not.toBeDirectory();
|
|
24
|
-
});
|
|
25
|
-
it("should throw an error when not a directory", () => {
|
|
26
|
-
expect(() => {
|
|
27
|
-
expect("face").toBeDirectory();
|
|
28
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
29
|
-
`[Error: Received is not a directory (or cannot be accessed by the current user)]`,
|
|
30
|
-
);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import "../../../src/matchers/setup";
|
|
3
|
-
|
|
4
|
-
describe("matchers", () => {
|
|
5
|
-
describe("toBeFile", () => {
|
|
6
|
-
it("should recognize this test file as a file", () => {
|
|
7
|
-
expect(import.meta.filename).toBeFile();
|
|
8
|
-
});
|
|
9
|
-
it("should NOT recognize this test directory as a file", () => {
|
|
10
|
-
expect(import.meta.dirname).not.toBeFile();
|
|
11
|
-
});
|
|
12
|
-
it("should throw an error when not a file", () => {
|
|
13
|
-
expect(() => {
|
|
14
|
-
expect("face").toBeFile();
|
|
15
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
16
|
-
`[Error: face is not a file (or cannot be accessed by the current user)]`,
|
|
17
|
-
);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import "../../../src/matchers/setup";
|
|
4
|
-
|
|
5
|
-
describe("matchers", () => {
|
|
6
|
-
describe("toBePath", () => {
|
|
7
|
-
it("should recognize this test file as a file", () => {
|
|
8
|
-
const weirdPath = path.join(
|
|
9
|
-
import.meta.dirname,
|
|
10
|
-
"..",
|
|
11
|
-
path.basename(import.meta.dirname),
|
|
12
|
-
);
|
|
13
|
-
expect(import.meta.dirname).toBePath(weirdPath);
|
|
14
|
-
});
|
|
15
|
-
it("should throw an error for a non-matching path", () => {
|
|
16
|
-
const wrongPath = path.join(import.meta.dirname, "..");
|
|
17
|
-
expect(() => {
|
|
18
|
-
expect(import.meta.dirname).toBePath(wrongPath);
|
|
19
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
20
|
-
`[Error: The realpath of the received path did not match the expected one]`,
|
|
21
|
-
);
|
|
22
|
-
});
|
|
23
|
-
it("should throw an error for a path that isn't accessible", () => {
|
|
24
|
-
const nonExistentPath = path.join(import.meta.dirname, "face");
|
|
25
|
-
expect(() => {
|
|
26
|
-
expect(import.meta.dirname).toBePath(nonExistentPath);
|
|
27
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
28
|
-
`[Error: One of the paths wasn't an accessible file on disk and couldn't be compared]`,
|
|
29
|
-
);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import "../../../src/matchers/setup";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
|
|
5
|
-
describe("matchers", () => {
|
|
6
|
-
describe("toEqualFile", () => {
|
|
7
|
-
// Okay this is a silly test but *shrug*
|
|
8
|
-
it("should produce a hash of this test file", () => {
|
|
9
|
-
expect(import.meta.filename).toEqualFile(import.meta.filename);
|
|
10
|
-
});
|
|
11
|
-
it("should fail when given two differing files", async () => {
|
|
12
|
-
expect(() => {
|
|
13
|
-
expect(import.meta.filename).toEqualFile(
|
|
14
|
-
path.join(import.meta.dirname, "toBePath.spec.ts"),
|
|
15
|
-
);
|
|
16
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
17
|
-
`[Error: The checksum of the file contents of the files do not match]`,
|
|
18
|
-
);
|
|
19
|
-
});
|
|
20
|
-
it("should fail when given a non-existent file", async () => {
|
|
21
|
-
expect(() => {
|
|
22
|
-
expect("faaaaaaaaaace").toEqualFile("khaaaaaaaaan");
|
|
23
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
24
|
-
`[Error: ENOENT: no such file or directory, open 'faaaaaaaaaace']`,
|
|
25
|
-
);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import "../../../src/matchers/setup";
|
|
3
|
-
|
|
4
|
-
describe("toHaveExifProperty", () => {
|
|
5
|
-
const buffer = Buffer.from(
|
|
6
|
-
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2O4v3EyBwAGwgIsY3pRcwAAAABJRU5ErkJggg==",
|
|
7
|
-
"base64url",
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
it("should pass when the property exists", async () => {
|
|
11
|
-
await expect(buffer).toHaveExifProperty("ImageWidth");
|
|
12
|
-
});
|
|
13
|
-
it("should pass when the property doesn't exist", async () => {
|
|
14
|
-
await expect(buffer).not.toHaveExifProperty("face");
|
|
15
|
-
});
|
|
16
|
-
it("should pass when the property value is correct", async () => {
|
|
17
|
-
await expect(buffer).toHaveExifProperty("ImageHeight", 1);
|
|
18
|
-
await expect(buffer).toHaveExifProperty("ImageWidth", 1);
|
|
19
|
-
});
|
|
20
|
-
it("should pass when the property value is incorrect", async () => {
|
|
21
|
-
await expect(buffer).not.toHaveExifProperty("ImageWidth", 15);
|
|
22
|
-
await expect(buffer).not.toHaveExifProperty("face", 15);
|
|
23
|
-
});
|
|
24
|
-
it("should error when the property should not exist but does", async () => {
|
|
25
|
-
await expect(async () =>
|
|
26
|
-
expect(buffer).not.toHaveExifProperty("ImageWidth"),
|
|
27
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
28
|
-
`[Error: Received should not have the property "ImageWidth"]`,
|
|
29
|
-
);
|
|
30
|
-
});
|
|
31
|
-
it("should error when the property should exist but doesn't", async () => {
|
|
32
|
-
await expect(async () =>
|
|
33
|
-
expect(buffer).toHaveExifProperty("face"),
|
|
34
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
35
|
-
`[Error: Received does not have the property "face"]`,
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
it("should error when the value should not match but does", async () => {
|
|
39
|
-
await expect(async () =>
|
|
40
|
-
expect(buffer).not.toHaveExifProperty("ImageWidth", 1),
|
|
41
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
42
|
-
`[Error: Property "ImageWidth" should not be expected value]`,
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
it("should error when the value should match but doesn't", async () => {
|
|
46
|
-
await expect(async () =>
|
|
47
|
-
expect(buffer).toHaveExifProperty("ImageWidth", 17),
|
|
48
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
49
|
-
`[Error: Property "ImageWidth" is not expected value]`,
|
|
50
|
-
);
|
|
51
|
-
});
|
|
52
|
-
it("should error when a non-buffer is passed in", async () => {
|
|
53
|
-
await expect(async () =>
|
|
54
|
-
expect(1234).toHaveExifProperty("face"),
|
|
55
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
56
|
-
`[Error: Invalid input argument]`,
|
|
57
|
-
);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import "../../../src/matchers/setup";
|
|
3
|
-
|
|
4
|
-
describe("matchers", () => {
|
|
5
|
-
describe("toMatchError", () => {
|
|
6
|
-
it("should match an error exactly", () => {
|
|
7
|
-
expect(new Error("face")).toMatchError(
|
|
8
|
-
expect.objectContaining({
|
|
9
|
-
message: "face",
|
|
10
|
-
name: "Error",
|
|
11
|
-
stack: expect.any(String) as unknown,
|
|
12
|
-
}),
|
|
13
|
-
);
|
|
14
|
-
});
|
|
15
|
-
it("should match an error by substring", () => {
|
|
16
|
-
expect(new Error("your stupid face")).toMatchError(
|
|
17
|
-
expect.objectContaining({
|
|
18
|
-
message: expect.stringContaining("stupid") as unknown,
|
|
19
|
-
}),
|
|
20
|
-
);
|
|
21
|
-
});
|
|
22
|
-
it("should NOT match an invalid string", () => {
|
|
23
|
-
expect(new Error("face")).not.toMatchError(
|
|
24
|
-
expect.objectContaining({
|
|
25
|
-
message: "hat",
|
|
26
|
-
}),
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
it("should throw an error when there is no match", () => {
|
|
30
|
-
expect(() => {
|
|
31
|
-
expect(new Error("face")).toMatchError(
|
|
32
|
-
expect.objectContaining({
|
|
33
|
-
message: "hat",
|
|
34
|
-
}),
|
|
35
|
-
);
|
|
36
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
37
|
-
`[Error: Expected errors to match]`,
|
|
38
|
-
);
|
|
39
|
-
});
|
|
40
|
-
it.todo("should display the other Error fields in the error", () => {
|
|
41
|
-
// I don't know how to capture vitest's full error output to verify it
|
|
42
|
-
// contains what we expect.
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import "../../../src/matchers/setup";
|
|
3
|
-
|
|
4
|
-
describe("matchers", () => {
|
|
5
|
-
describe("toThrowErrorMatching", () => {
|
|
6
|
-
it("should match an error exactly", () => {
|
|
7
|
-
expect(() => {
|
|
8
|
-
throw new Error("face");
|
|
9
|
-
}).toThrow("fac");
|
|
10
|
-
});
|
|
11
|
-
it("should NOT match an just the message", () => {
|
|
12
|
-
expect(() => {
|
|
13
|
-
throw new Error("face");
|
|
14
|
-
}).not.toThrowErrorMatching("face");
|
|
15
|
-
});
|
|
16
|
-
it("should NOT match an invalid message", () => {
|
|
17
|
-
expect(() => {
|
|
18
|
-
throw new Error("face");
|
|
19
|
-
}).not.toThrowErrorMatching(
|
|
20
|
-
expect.objectContaining({
|
|
21
|
-
message: "hat",
|
|
22
|
-
}),
|
|
23
|
-
);
|
|
24
|
-
});
|
|
25
|
-
it("should throw an error when an error wasn't thrown", () => {
|
|
26
|
-
expect(() => {
|
|
27
|
-
expect(() => 1).toThrowErrorMatching("face");
|
|
28
|
-
}).toThrowErrorMatchingInlineSnapshot(`[Error: Did not throw an Error]`);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import absolutePathSerializer from "../../../src/serializers/absolutePath.js";
|
|
4
|
-
expect.addSnapshotSerializer(absolutePathSerializer);
|
|
5
|
-
|
|
6
|
-
describe("serializers", () => {
|
|
7
|
-
describe("absolutePath", () => {
|
|
8
|
-
it("should remove absolute file paths in a string", () => {
|
|
9
|
-
expect(
|
|
10
|
-
`String with an absolute path: ${import.meta.dirname}`,
|
|
11
|
-
).toMatchInlineSnapshot(
|
|
12
|
-
`"String with an absolute path: <cwd>/tests/unit/serializers"`,
|
|
13
|
-
);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import htmlSerializer from "../../../src/serializers/html.js";
|
|
4
|
-
expect.addSnapshotSerializer(htmlSerializer);
|
|
5
|
-
|
|
6
|
-
describe("serializers", () => {
|
|
7
|
-
describe("html", () => {
|
|
8
|
-
it("should prettier format the html", () => {
|
|
9
|
-
expect(
|
|
10
|
-
`<html><head><title>your face</title></head><body>is stupid</body></html>`,
|
|
11
|
-
).toMatchInlineSnapshot(`
|
|
12
|
-
"<!-- Formatted HTML -->
|
|
13
|
-
<html>
|
|
14
|
-
<head>
|
|
15
|
-
<title>your face</title>
|
|
16
|
-
</head>
|
|
17
|
-
<body>
|
|
18
|
-
is stupid
|
|
19
|
-
</body>
|
|
20
|
-
</html>"
|
|
21
|
-
`);
|
|
22
|
-
});
|
|
23
|
-
it("should ignore already formatted html", () => {
|
|
24
|
-
const html = `
|
|
25
|
-
<html>
|
|
26
|
-
<head>
|
|
27
|
-
<title>your face</title>
|
|
28
|
-
</head>
|
|
29
|
-
<body>
|
|
30
|
-
is stupid
|
|
31
|
-
</body>
|
|
32
|
-
</html>"
|
|
33
|
-
`;
|
|
34
|
-
expect(html).toMatchInlineSnapshot(`
|
|
35
|
-
"
|
|
36
|
-
<html>
|
|
37
|
-
<head>
|
|
38
|
-
<title>your face</title>
|
|
39
|
-
</head>
|
|
40
|
-
<body>
|
|
41
|
-
is stupid
|
|
42
|
-
</body>
|
|
43
|
-
</html>"
|
|
44
|
-
"
|
|
45
|
-
`);
|
|
46
|
-
});
|
|
47
|
-
it("should ignore non-html strings", () => {
|
|
48
|
-
expect(`I'm just some content that isn't html`).toMatchInlineSnapshot(
|
|
49
|
-
`"I'm just some content that isn't html"`,
|
|
50
|
-
);
|
|
51
|
-
});
|
|
52
|
-
it("should ignore malformed html", () => {
|
|
53
|
-
expect(`<html><p>oiajsdfpoiajsdf</a></q></face>`).toMatchInlineSnapshot(`
|
|
54
|
-
"<html><p>oiajsdfpoiajsdf</a></q></face>"
|
|
55
|
-
`);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import urlSerializer from "../../../src/serializers/url.js";
|
|
4
|
-
expect.addSnapshotSerializer(urlSerializer);
|
|
5
|
-
|
|
6
|
-
describe("serializers", () => {
|
|
7
|
-
describe("url", () => {
|
|
8
|
-
it("should remove the port in a localhost http[s] url", () => {
|
|
9
|
-
expect(
|
|
10
|
-
`String with http://localhost:1234/path/to/face url`,
|
|
11
|
-
).toMatchInlineSnapshot(`"String with http://localhost/path/to/face url"`);
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { VFile } from "vfile";
|
|
3
|
-
|
|
4
|
-
// We're not testing the absolute path serializer, but the test isn't
|
|
5
|
-
// reproducible without it. So just add both.
|
|
6
|
-
import "../../../src/serializers/setup";
|
|
7
|
-
|
|
8
|
-
describe("serializers", () => {
|
|
9
|
-
describe("vFile", () => {
|
|
10
|
-
it("should produce a snapshot for a plain text VFile (not Prettier supported)", () => {
|
|
11
|
-
const file = new VFile({
|
|
12
|
-
path: "~/example.txt",
|
|
13
|
-
value: "Alpha *braavo* charlie.",
|
|
14
|
-
});
|
|
15
|
-
expect(file).toMatchInlineSnapshot(`
|
|
16
|
-
FormattedVFile {
|
|
17
|
-
"cwd": "<cwd>",
|
|
18
|
-
"data": {},
|
|
19
|
-
"history": [
|
|
20
|
-
"~/example.txt",
|
|
21
|
-
],
|
|
22
|
-
"messages": [],
|
|
23
|
-
"value": "Alpha *braavo* charlie.",
|
|
24
|
-
}
|
|
25
|
-
`);
|
|
26
|
-
});
|
|
27
|
-
it("should produce a formatted snapshot for a Prettier-compatible file", () => {
|
|
28
|
-
const file = new VFile({
|
|
29
|
-
path: "~/example.js",
|
|
30
|
-
value: `function face( ) {console.log("hi" ); }`,
|
|
31
|
-
});
|
|
32
|
-
expect(file).toMatchInlineSnapshot(`
|
|
33
|
-
FormattedVFile {
|
|
34
|
-
"cwd": "<cwd>",
|
|
35
|
-
"data": {},
|
|
36
|
-
"history": [
|
|
37
|
-
"~/example.js",
|
|
38
|
-
],
|
|
39
|
-
"messages": [],
|
|
40
|
-
"value": "function face() {
|
|
41
|
-
console.log("hi");
|
|
42
|
-
}",
|
|
43
|
-
}
|
|
44
|
-
`);
|
|
45
|
-
});
|
|
46
|
-
it("should throw if given a file that Prettier supports but can't format", () => {
|
|
47
|
-
const file = new VFile({
|
|
48
|
-
path: "~/example.js",
|
|
49
|
-
value: `function ( ) {1 }`,
|
|
50
|
-
});
|
|
51
|
-
file.cwd = "/root/path"; // make snapshot reproducible
|
|
52
|
-
expect(() => {
|
|
53
|
-
expect(file).toMatchInlineSnapshot(`"function ( ) {1 }"`);
|
|
54
|
-
}).toThrowErrorMatchingInlineSnapshot(`
|
|
55
|
-
[PrettyFormatPluginError: Unexpected token (1:10)
|
|
56
|
-
> 1 | function ( ) {1 }
|
|
57
|
-
| ^]
|
|
58
|
-
`);
|
|
59
|
-
});
|
|
60
|
-
it("should remove absolute file paths in a vFile", () => {
|
|
61
|
-
const file = new VFile({
|
|
62
|
-
path: "~/example.json",
|
|
63
|
-
value: `{ "key": "${import.meta.dirname}" }`,
|
|
64
|
-
});
|
|
65
|
-
expect(file).toMatchInlineSnapshot(`
|
|
66
|
-
FormattedVFile {
|
|
67
|
-
"cwd": "<cwd>",
|
|
68
|
-
"data": {},
|
|
69
|
-
"history": [
|
|
70
|
-
"~/example.json",
|
|
71
|
-
],
|
|
72
|
-
"messages": [],
|
|
73
|
-
"value": "{
|
|
74
|
-
"key": "<cwd>/tests/unit/serializers"
|
|
75
|
-
}",
|
|
76
|
-
}
|
|
77
|
-
`);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
package/tsconfig.json
DELETED
package/vitest.config.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defineConfig, type ViteUserConfig } from "vitest/config";
|
|
2
|
-
|
|
3
|
-
const config: ViteUserConfig = defineConfig({
|
|
4
|
-
test: {
|
|
5
|
-
dir: "tests/unit",
|
|
6
|
-
coverage: {
|
|
7
|
-
enabled: true,
|
|
8
|
-
include: ["src"],
|
|
9
|
-
provider: "v8",
|
|
10
|
-
clean: true,
|
|
11
|
-
skipFull: true,
|
|
12
|
-
thresholds: { "100": true },
|
|
13
|
-
reportsDirectory: ".coverage",
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export default config;
|