@digitaldefiance/express-suite-test-utils 1.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/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # @digitaldefiance/express-suite-test-utils
2
+
3
+ Test utilities for Digital Defiance Express Suite projects.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @digitaldefiance/express-suite-test-utils
9
+ # or
10
+ yarn add @digitaldefiance/express-suite-test-utils
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### toThrowType Matcher
16
+
17
+ Custom Jest matcher for testing error types with optional validation:
18
+
19
+ ```typescript
20
+ import '@digitaldefiance/express-suite-test-utils';
21
+
22
+ class CustomError extends Error {
23
+ constructor(public code: number) {
24
+ super('Custom error');
25
+ }
26
+ }
27
+
28
+ // Basic usage
29
+ expect(() => {
30
+ throw new CustomError(404);
31
+ }).toThrowType(CustomError);
32
+
33
+ // With validator
34
+ expect(() => {
35
+ throw new CustomError(404);
36
+ }).toThrowType(CustomError, (error) => {
37
+ expect(error.code).toBe(404);
38
+ });
39
+ ```
40
+
41
+ ### ErrorClass Type
42
+
43
+ ```typescript
44
+ import { ErrorClass } from '@digitaldefiance/express-suite-test-utils';
45
+
46
+ function testError<E extends Error>(ErrorType: ErrorClass<E>) {
47
+ // Use ErrorType constructor
48
+ }
49
+ ```
50
+
51
+ ### Console Mocks
52
+
53
+ Mock console methods in tests:
54
+
55
+ ```typescript
56
+ import { withConsoleMocks, spyContains } from '@digitaldefiance/express-suite-test-utils';
57
+
58
+ it('should log message', async () => {
59
+ await withConsoleMocks({ mute: true }, async (spies) => {
60
+ console.log('test message');
61
+ expect(spies.log).toHaveBeenCalledWith('test message');
62
+ expect(spyContains(spies.log, 'test', 'message')).toBe(true);
63
+ });
64
+ });
65
+ ```
66
+
67
+ ## License
68
+
69
+ MIT
70
+
71
+ ## ChangeLog
72
+
73
+ ### v1.0.0
74
+
75
+ - Initial Release
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@digitaldefiance/express-suite-test-utils",
3
+ "version": "1.0.0",
4
+ "description": "Test utilities for Digital Defiance Express Suite",
5
+ "main": "src/index.js",
6
+ "types": "src/index.d.ts",
7
+ "scripts": {
8
+ "build": "npx nx build digitaldefiance-express-suite-test-utils",
9
+ "build:stream": "npx nx build --outputStyle=stream digitaldefiance-express-suite-test-utils",
10
+ "build:logged": "npx nx build --outputStyle=stream digitaldefiance-express-suite-test-utils 2>&1 | ansifilter -o build.log",
11
+ "test": "npx nx test digitaldefiance-express-suite-test-utils",
12
+ "test:stream": "npx nx test --outputStyle=stream digitaldefiance-express-suite-test-utils",
13
+ "test:logged": "npx nx test --outputStyle=stream digitaldefiance-express-suite-test-utils 2>&1 | ansifilter -o test.log",
14
+ "test:coverage": "npx jest --coverage --testPathPattern=digitaldefiance-express-suite-test-utils --coverageReporters=text",
15
+ "lint": "npx nx lint digitaldefiance-express-suite-test-utils",
16
+ "lint:fix": "npx nx lint digitaldefiance-express-suite-test-utils --fix",
17
+ "prettier:check": "prettier --check 'src/**/*.{ts,tsx}'",
18
+ "prettier:fix": "prettier --write 'src/**/*.{ts,tsx}'",
19
+ "format": "npx nx format:write --projects=digitaldefiance-express-suite-test-utils",
20
+ "format:check": "npx nx format:check --projects=digitaldefiance-express-suite-test-utils",
21
+ "prepublishOnly": "npx nx build digitaldefiance-express-suite-test-utils",
22
+ "publish:public": "npm publish --access public"
23
+ },
24
+ "files": [
25
+ "src",
26
+ "README.md"
27
+ ],
28
+ "keywords": [
29
+ "test",
30
+ "jest",
31
+ "typescript",
32
+ "utilities"
33
+ ],
34
+ "author": "Digital Defiance, Jessica Mulein",
35
+ "license": "MIT",
36
+ "packageManager": "yarn@4.10.3",
37
+ "dependencies": {
38
+ "@jest/globals": "^30.0.5",
39
+ "@types/jest": "^30.0.0",
40
+ "expect": "^30.0.5"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^22.0.0"
44
+ },
45
+ "type": "commonjs"
46
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './lib/to-throw-type';
2
+ export * from './lib/console';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-express-suite-test-utils/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC"}
@@ -0,0 +1,20 @@
1
+ export type ConsoleSpies = {
2
+ log: jest.SpyInstance;
3
+ info: jest.SpyInstance;
4
+ warn: jest.SpyInstance;
5
+ error: jest.SpyInstance;
6
+ debug: jest.SpyInstance;
7
+ };
8
+ export interface WithConsoleOptions {
9
+ mute?: boolean;
10
+ }
11
+ /**
12
+ * Wrap a test body with console spies that are always restored.
13
+ * By default mutes console output to keep test logs clean.
14
+ */
15
+ export declare function withConsoleMocks<T = unknown>(options: WithConsoleOptions, fn: (spies: ConsoleSpies) => Promise<T> | T): Promise<T>;
16
+ /**
17
+ * True if any call to the spy contains all provided substrings, in order-agnostic check.
18
+ */
19
+ export declare function spyContains(spy: jest.SpyInstance, ...needles: string[]): boolean;
20
+ //# sourceMappingURL=console.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-test-utils/src/lib/console.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC;IACtB,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC;IACvB,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC;IACvB,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC;IACxB,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC;CACzB,CAAC;AAEF,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,GAAG,OAAO,EAChD,OAAO,EAAE,kBAAkB,EAC3B,EAAE,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAC1C,OAAO,CAAC,CAAC,CAAC,CAkCZ;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,IAAI,CAAC,WAAW,EACrB,GAAG,OAAO,EAAE,MAAM,EAAE,GACnB,OAAO,CAKT"}
@@ -0,0 +1,7 @@
1
+ import type { MatcherContext } from 'expect';
2
+ export type ErrorClass<E extends Error> = new (...args: any[]) => E;
3
+ export declare const toThrowType: <E extends Error>(this: MatcherContext, received: (() => unknown | Promise<unknown>) | Promise<unknown>, errorType: ErrorClass<E>, validator?: (error: E) => void) => Promise<{
4
+ pass: boolean;
5
+ message: () => string;
6
+ }>;
7
+ //# sourceMappingURL=to-throw-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-throw-type.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-test-utils/src/lib/to-throw-type.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAI7C,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,KAAK,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAoDpE,eAAO,MAAM,WAAW,GAAmB,CAAC,SAAS,KAAK,EACxD,MAAM,cAAc,EACpB,UAAU,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,EAC/D,WAAW,UAAU,CAAC,CAAC,CAAC,EACxB,YAAY,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,KAC7B,OAAO,CAAC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,MAAM,CAAA;CAAE,CA4HlD,CAAC"}
@@ -0,0 +1,16 @@
1
+ export {};
2
+ declare global {
3
+ namespace jest {
4
+ interface Matchers<R> {
5
+ toThrowType<E extends Error, T extends new (...args: any[]) => E>(errorType: T, validator?: (error: E) => void): R;
6
+ }
7
+ }
8
+ }
9
+ declare module 'expect' {
10
+ interface ExpectExtendMap {
11
+ toThrowType: {
12
+ <E extends Error, T extends new (...args: any[]) => E>(this: jest.MatcherContext, received: () => unknown, errorType: T, validator?: (error: E) => void): jest.CustomMatcherResult;
13
+ };
14
+ }
15
+ }
16
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-test-utils/src/lib/types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC;AAEV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,IAAI,CAAC;QACb,UAAU,QAAQ,CAAC,CAAC;YAElB,WAAW,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAC9D,SAAS,EAAE,CAAC,EACZ,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAC7B,CAAC,CAAC;SACN;KACF;CACF;AAED,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,eAAe;QACvB,WAAW,EAAE;YAEX,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EACnD,IAAI,EAAE,IAAI,CAAC,cAAc,EACzB,QAAQ,EAAE,MAAM,OAAO,EACvB,SAAS,EAAE,CAAC,EACZ,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAC7B,IAAI,CAAC,mBAAmB,CAAC;SAC7B,CAAC;KACH;CACF"}