Skip to content
This repository was archived by the owner on Dec 30, 2023. It is now read-only.

Commit f037f45

Browse files
authored
feat(packages): ✨ Implement test with reusable snippets for unit testing (#28)
1 parent 9afe9b9 commit f037f45

28 files changed

+726
-163
lines changed

.changeset/heavy-lamps-camp.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@terminal-nerds/snippets-test": minor
3+
---
4+
5+
Add reusable snippets group for unit testing `unit`, it includes:
6+
7+
- `returns`,
8+
- `throws`,

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,9 @@ Reusable pieces of code, which can be **reused** across the projects.
101101
| [![snippets badge]][snippets] | [![snippets version badge]][snippets npm page] |
102102
| <!-- PACKAGES --> | <!-- PACKAGES --> |
103103
| [![error badge]][error] | [![error version badge]][error npm page] |
104-
| [![function badge]][function] | [![function version badge]][function npm page] |
105-
| [![test badge]][test] | [![test version badge]][test npm page] |
106104
| [![regexp badge]][regexp] | [![regexp version badge]][regexp npm page] |
107105
| [![string badge]][string] | [![string version badge]][string npm page] |
106+
| [![test badge]][test] | [![test version badge]][test npm page] |
108107

109108
[snippets]: ./packages/snippets/README.md
110109
[snippets badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets&style=flat-square&color=informational
@@ -123,11 +122,6 @@ Reusable pieces of code, which can be **reused** across the projects.
123122
[function version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-function/latest?style=flat-square&logo=npm
124123
[function npm page]: https://www.npmjs.com/package/@terminal-nerds/snippets-function
125124

126-
[test]: ./packages/test/README.md
127-
[test badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets-test&style=flat-square&color=informational
128-
[test version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-test/latest?style=flat-square&logo=npm
129-
[test npm page]: https://www.npmjs.com/package/@terminal-nerds/snippets-test
130-
131125
[regexp]: ./packages/regexp/README.md
132126
[regexp badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets-regexp&style=flat-square&color=informational
133127
[regexp version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-regexp/latest?style=flat-square&logo=npm
@@ -137,6 +131,11 @@ Reusable pieces of code, which can be **reused** across the projects.
137131
[string badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets-string&style=flat-square&color=informational
138132
[string version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-string/latest?style=flat-square&logo=npm
139133
[string npm page]: https://www.npmjs.com/package/@terminal-nerds/snippets-string
134+
135+
[test]: ./packages/test/README.md
136+
[test badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets-test&style=flat-square&color=informational
137+
[test version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-test/latest?style=flat-square&logo=npm
138+
[test npm page]: https://www.npmjs.com/package/@terminal-nerds/snippets-test
140139
<!-- prettier-ignore-end -->
141140

142141
---

packages/error/.depcheckrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"ignores": ["@terminal-nerds/*-config", "tsup", "vitest"]
2+
"ignores": ["@terminal-nerds/*-config", "modern-errors", "tsup", "vitest"]
33
}

packages/error/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,8 @@
6363
"dependencies": {
6464
"modern-errors": "5.5.1",
6565
"zod": "3.21.0"
66+
},
67+
"devDependencies": {
68+
"@terminal-nerds/snippets-test": "workspace:*"
6669
}
6770
}
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { returns } from "@terminal-nerds/snippets-test/unit";
12
import { describe, expect, it } from "vitest";
23

34
import {
@@ -11,95 +12,95 @@ import {
1112
} from "./built-in.js";
1213

1314
describe("isError(error)", () => {
14-
it(`🔙 returns a boolean 🟢 'true' - on Error`, () => {
15+
it(returns(true).on(`Error`), () => {
1516
expect(isError(new Error("message"))).toBe(true);
1617
});
1718

18-
it(`🔙 returns a boolean 🔴 'false' - on random value`, () => {
19+
it(returns(false).on(`random value`).sample(""), () => {
1920
expect(isError("")).toBe(false);
2021
});
2122
});
2223

2324
describe("isEvalError(error)", () => {
24-
it(`🔙 returns a boolean 🔴 'false' - on Error`, () => {
25+
it(returns(false).on(`Error`), () => {
2526
expect(isRangeError(Error)).toBe(false);
2627
});
2728

28-
it(`🔙 returns a boolean 🔴 'false' - on random value`, () => {
29+
it(returns(false).on(`random value`).sample(""), () => {
2930
expect(isEvalError("")).toBe(false);
3031
});
3132

32-
it(`🔙 returns a boolean 🟢 'true' - on EvalError`, () => {
33+
it(returns(true).on(`EvalError`), () => {
3334
expect(isEvalError(new EvalError("message"))).toBe(true);
3435
});
3536
});
3637

3738
describe("isRangeError(error)", () => {
38-
it(`🔙 returns a boolean 🔴 'false' - on Error`, () => {
39+
it(returns(false).on(`Error`), () => {
3940
expect(isRangeError(Error)).toBe(false);
4041
});
4142

42-
it(`🔙 returns a boolean 🔴 'false' - on random value`, () => {
43+
it(returns(false).on(`random value`), () => {
4344
expect(isRangeError("")).toBe(false);
4445
});
4546

46-
it(`🔙 returns a boolean 🟢 'true' - on RangeError`, () => {
47+
it(returns(true).on(`RangeError`), () => {
4748
expect(isRangeError(new RangeError("message"))).toBe(true);
4849
});
4950
});
5051

5152
describe("isReferenceError(error)", () => {
52-
it(`🔙 returns a boolean 🔴 'false' - on Error`, () => {
53+
it(returns(false).on(`Error`), () => {
5354
expect(isRangeError(Error)).toBe(false);
5455
});
5556

56-
it(`🔙 returns a boolean 🔴 'false' - on random value`, () => {
57+
it(returns(false).on(`random value`).sample(""), () => {
5758
expect(isReferenceError("")).toBe(false);
5859
});
5960

60-
it(`🔙 returns a boolean 🟢 'true' - on ReferenceError`, () => {
61+
it(returns(true).on(`ReferenceError`), () => {
6162
expect(isReferenceError(new ReferenceError("message"))).toBe(true);
6263
});
6364
});
6465

6566
describe("isSyntaxError(error)", () => {
66-
it(`🔙 returns a boolean 🔴 'false' - on Error`, () => {
67+
it(returns(false).on(`Error`), () => {
6768
expect(isRangeError(Error)).toBe(false);
6869
});
6970

70-
it(`🔙 returns a boolean 🔴 'false' - on random value`, () => {
71+
it(returns(false).on(`random value`).sample(""), () => {
7172
expect(isSyntaxError("")).toBe(false);
7273
});
7374

74-
it(`🔙 returns a boolean 🟢 'true' - on SyntaxError`, () => {
75+
it(returns(true).on(`SyntaxError`), () => {
7576
expect(isSyntaxError(new SyntaxError("message"))).toBe(true);
7677
});
7778
});
7879

7980
describe("isTypeError(error)", () => {
80-
it(`🔙 returns a boolean 🔴 'false' - on Error`, () => {
81+
it(returns(false).on(`Error`), () => {
8182
expect(isRangeError(Error)).toBe(false);
8283
});
8384

84-
it(`🔙 returns a boolean 🔴 'false' - on random value`, () => {
85+
it(returns(false).on(`random value`).sample(""), () => {
8586
expect(isTypeError("")).toBe(false);
8687
});
8788

88-
it(`🔙 returns a boolean 🟢 'true' - on TypeError`, () => {
89+
it(returns(true).on(`TypeError`), () => {
8990
expect(isTypeError(new TypeError("message"))).toBe(true);
9091
});
9192
});
9293

9394
describe("isURIError(error)", () => {
94-
it(`🔙 returns a boolean 🔴 'false' - on Error`, () => {
95+
it(returns(false).on(`Error`), () => {
9596
expect(isRangeError(Error)).toBe(false);
9697
});
9798

98-
it(`🔙 returns a boolean 🔴 'false' - on random value`, () => {
99+
it(returns(false).on(`random value`).sample(""), () => {
99100
expect(isURIError("")).toBe(false);
100101
});
101102

102-
it(`🔙 returns a boolean 🟢 'true' - on URIError`, () => {
103+
it(returns(true).on(`URIError`), () => {
103104
expect(isURIError(new URIError("message"))).toBe(true);
104105
});
105106
});
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1+
import { returns } from "@terminal-nerds/snippets-test/unit";
12
import { describe, expect, it } from "vitest";
23

34
import { isRuntimeError, isValidationError, RuntimeError, ValidationError } from "./custom.js";
45

56
describe("isRuntimeError(error)", () => {
6-
it(`🔙 returns a boolean 🔴 'false' - on Error`, () => {
7+
it(returns(false).on(`Error`), () => {
78
expect(isRuntimeError(Error)).toBe(false);
89
});
910

10-
it(`🔙 returns a boolean 🔴 'false' - on random value`, () => {
11+
it(returns(false).on(`random value`).sample(""), () => {
1112
expect(isRuntimeError("")).toBe(false);
1213
});
1314

14-
it(`🔙 returns a boolean 🟢 'true' - on RuntimeError`, () => {
15+
it(returns(true).on(`RuntimeError`), () => {
1516
expect(isRuntimeError(new RuntimeError("message"))).toBe(true);
1617
});
1718
});
1819

1920
describe("isValidationError(error)", () => {
20-
it(`🔙 returns a boolean 🔴 'false' - on Error`, () => {
21-
expect(isValidationError(Error)).toBe(false);
21+
it(returns(false).on(`Error`), () => {
22+
expect(isValidationError(new Error("message"))).toBe(false);
2223
});
2324

24-
it(`🔙 returns a boolean 🔴 'false' - on random value`, () => {
25+
it(returns(false).on(`random value`).sample(""), () => {
2526
expect(isValidationError("")).toBe(false);
2627
});
2728

28-
it(`🔙 returns a boolean 🟢 'true' - on ValidationError`, () => {
29+
it(returns(true).on(`ValidationError`), () => {
2930
expect(isValidationError(new ValidationError([]))).toBe(true);
3031
});
3132
});

packages/snippets/README.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515

1616
## Packages included
1717

18-
| Name | Version |
19-
| ----------------------------- | ---------------------------------------------- |
20-
| [![error badge]][error] | [![error version badge]][error npm page] |
21-
| [![function badge]][function] | [![function version badge]][function npm page] |
22-
| [![test badge]][test] | [![test version badge]][test npm page] |
23-
| [![regexp badge]][regexp] | [![regexp version badge]][regexp npm page] |
24-
| [![string badge]][string] | [![string version badge]][string npm page] |
18+
| Name | Version |
19+
| ------------------------- | ------------------------------------------ |
20+
| [![error badge]][error] | [![error version badge]][error npm page] |
21+
| [![regexp badge]][regexp] | [![regexp version badge]][regexp npm page] |
22+
| [![string badge]][string] | [![string version badge]][string npm page] |
23+
| [![test badge]][test] | [![test version badge]][test npm page] |
2524

2625
<!-- prettier-ignore-start -->
2726
<!-- PACKAGES LINKS -->
@@ -30,16 +29,6 @@
3029
[error version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-error/latest?style=flat-square&logo=npm
3130
[error npm page]: https://www.npmjs.com/package/@terminal-nerds/snippets-error
3231

33-
[function]: https://github.com/terminal-nerds/snippets/blob/main/packages/function/README.md
34-
[function badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets-function&style=flat-square&color=informational
35-
[function version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-function/latest?style=flat-square&logo=npm
36-
[function npm page]: https://www.npmjs.com/package/@terminal-nerds/snippets-function
37-
38-
[test]: https://github.com/terminal-nerds/snippets/blob/main/packages/test/README.md
39-
[test badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets-test&style=flat-square&color=informational
40-
[test version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-test/latest?style=flat-square&logo=npm
41-
[test npm page]: https://www.npmjs.com/package/@terminal-nerds/snippets-test
42-
4332
[regexp]: https://github.com/terminal-nerds/snippets/blob/main/packages/regexp/README.md
4433
[regexp badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets-regexp&style=flat-square&color=informational
4534
[regexp version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-regexp/latest?style=flat-square&logo=npm
@@ -49,6 +38,11 @@
4938
[string badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets-string&style=flat-square&color=informational
5039
[string version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-string/latest?style=flat-square&logo=npm
5140
[string npm page]: https://www.npmjs.com/package/@terminal-nerds/snippets-string
41+
42+
[test]: https://github.com/terminal-nerds/snippets/blob/main/packages/test/README.md
43+
[test badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets-test&style=flat-square&color=informational
44+
[test version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-test/latest?style=flat-square&logo=npm
45+
[test npm page]: https://www.npmjs.com/package/@terminal-nerds/snippets-test
5246
<!-- prettier-ignore-end -->
5347

5448
---

packages/snippets/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
"dependencies": {
6161
"@terminal-nerds/snippets-error": "workspace:*",
6262
"@terminal-nerds/snippets-regexp": "workspace:*",
63-
"@terminal-nerds/snippets-string": "workspace:*"
63+
"@terminal-nerds/snippets-string": "workspace:*",
64+
"@terminal-nerds/snippets-test": "workspace:*"
6465
},
6566
"peerDependenciesMeta": {
6667
"typescript": {

packages/snippets/source/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
export * from "@terminal-nerds/snippets-error";
33
export * from "@terminal-nerds/snippets-regexp";
44
export * from "@terminal-nerds/snippets-string";
5+
export * from "@terminal-nerds/snippets-test";

packages/string/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,8 @@
7373
"typescript": {
7474
"optional": true
7575
}
76+
},
77+
"devDependencies": {
78+
"@terminal-nerds/snippets-test": "workspace:*"
7679
}
7780
}

0 commit comments

Comments
 (0)