From 4a00925c8a85b96d7dabb40b7b31b09fdfaac2d0 Mon Sep 17 00:00:00 2001 From: electrovir Date: Mon, 23 Sep 2024 12:53:30 +0000 Subject: [PATCH] [minor] add assert.tsType.slowEquals --- package-lock.json | 46 +++++++++---------- package.json | 2 +- packages/assert/package.json | 4 +- .../equality/ts-type-equality.test.ts | 13 ++++++ .../assertions/equality/ts-type-equality.ts | 21 ++------- packages/assert/src/assertions/length.ts | 2 +- packages/common/package.json | 6 +-- packages/core/package.json | 2 +- packages/node/package.json | 8 ++-- packages/scripts/package.json | 8 ++-- packages/test/package.json | 6 +-- packages/web/package.json | 8 ++-- todo.md | 1 + 13 files changed, 64 insertions(+), 63 deletions(-) diff --git a/package-lock.json b/package-lock.json index e1d5b7a6..3a80a166 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@augment-vir/mono-repo-root", - "version": "30.0.5", + "version": "30.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@augment-vir/mono-repo-root", - "version": "30.0.5", + "version": "30.1.0", "hasInstallScript": true, "license": "(MIT or CC0 1.0)", "workspaces": [ @@ -18944,10 +18944,10 @@ }, "packages/assert": { "name": "@augment-vir/assert", - "version": "30.0.5", + "version": "30.1.0", "license": "(MIT or CC0 1.0)", "dependencies": { - "@augment-vir/core": "^30.0.5", + "@augment-vir/core": "^30.1.0", "@date-vir/duration": "^6.0.0", "deep-eql": "^5.0.2", "expect-type": "^0.20.0", @@ -18979,11 +18979,11 @@ }, "packages/common": { "name": "@augment-vir/common", - "version": "30.0.5", + "version": "30.1.0", "license": "(MIT or CC0 1.0)", "dependencies": { - "@augment-vir/assert": "^30.0.5", - "@augment-vir/core": "^30.0.5", + "@augment-vir/assert": "^30.1.0", + "@augment-vir/core": "^30.1.0", "@date-vir/duration": "^6.0.0", "ansi-styles": "^6.2.1", "json5": "^2.2.3", @@ -19077,7 +19077,7 @@ }, "packages/core": { "name": "@augment-vir/core", - "version": "30.0.5", + "version": "30.1.0", "license": "(MIT or CC0 1.0)", "dependencies": { "@date-vir/duration": "^6.0.0", @@ -19096,11 +19096,11 @@ }, "packages/node": { "name": "@augment-vir/node", - "version": "30.0.5", + "version": "30.1.0", "license": "(MIT or CC0 1.0)", "dependencies": { - "@augment-vir/assert": "^30.0.5", - "@augment-vir/common": "^30.0.5", + "@augment-vir/assert": "^30.1.0", + "@augment-vir/common": "^30.1.0", "@date-vir/duration": "^6.0.0", "ansi-styles": "^6.2.1", "terminate": "^2.8.0", @@ -19108,7 +19108,7 @@ "typed-event-target": "^3.4.0" }, "devDependencies": { - "@augment-vir/test": "^30.0.5", + "@augment-vir/test": "^30.1.0", "@prisma/client": "^5.19.1", "@types/node": "^22.5.5", "@web/dev-server-esbuild": "^1.0.2", @@ -19199,17 +19199,17 @@ }, "packages/scripts": { "name": "@augment-vir/scripts", - "version": "30.0.5", + "version": "30.1.0", "license": "(MIT or CC0 1.0)", "dependencies": { - "@augment-vir/assert": "^30.0.5", - "@augment-vir/core": "^30.0.5", + "@augment-vir/assert": "^30.1.0", + "@augment-vir/core": "^30.1.0", "@virmator/docs": "^13.3.15", "jsdom": "^25.0.1", "typedoc": "^0.26.7" }, "devDependencies": { - "@augment-vir/test": "^30.0.5", + "@augment-vir/test": "^30.1.0", "@types/jsdom": "^21.1.7", "@types/node": "^22.5.5" }, @@ -19219,11 +19219,11 @@ }, "packages/test": { "name": "@augment-vir/test", - "version": "30.0.5", + "version": "30.1.0", "license": "(MIT or CC0 1.0)", "dependencies": { - "@augment-vir/assert": "^30.0.5", - "@augment-vir/common": "^30.0.5", + "@augment-vir/assert": "^30.1.0", + "@augment-vir/common": "^30.1.0", "@open-wc/testing-helpers": "^3.0.1", "type-fest": "^4.26.1" }, @@ -19316,17 +19316,17 @@ }, "packages/web": { "name": "@augment-vir/web", - "version": "30.0.5", + "version": "30.1.0", "license": "(MIT or CC0 1.0)", "dependencies": { - "@augment-vir/assert": "^30.0.5", - "@augment-vir/common": "^30.0.5", + "@augment-vir/assert": "^30.1.0", + "@augment-vir/common": "^30.1.0", "@date-vir/duration": "^6.0.0", "html-spec-tags": "^2.2.1", "type-fest": "^4.26.1" }, "devDependencies": { - "@augment-vir/test": "^30.0.5", + "@augment-vir/test": "^30.1.0", "bowser": "^2.11.0", "typescript": "^5.6.2" }, diff --git a/package.json b/package.json index 01d5894b..a6a6f1a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@augment-vir/mono-repo-root", - "version": "30.0.5", + "version": "30.1.0", "private": true, "homepage": "https://github.com/electrovir/augment-vir", "bugs": { diff --git a/packages/assert/package.json b/packages/assert/package.json index d823d042..eac0bba8 100644 --- a/packages/assert/package.json +++ b/packages/assert/package.json @@ -1,6 +1,6 @@ { "name": "@augment-vir/assert", - "version": "30.0.5", + "version": "30.1.0", "description": "A collection of assertions for test and production code alike.", "keywords": [ "augment", @@ -41,7 +41,7 @@ "test:update": "npm test" }, "dependencies": { - "@augment-vir/core": "^30.0.5", + "@augment-vir/core": "^30.1.0", "@date-vir/duration": "^6.0.0", "deep-eql": "^5.0.2", "expect-type": "^0.20.0", diff --git a/packages/assert/src/assertions/equality/ts-type-equality.test.ts b/packages/assert/src/assertions/equality/ts-type-equality.test.ts index 66491265..4865ab91 100644 --- a/packages/assert/src/assertions/equality/ts-type-equality.test.ts +++ b/packages/assert/src/assertions/equality/ts-type-equality.test.ts @@ -76,6 +76,19 @@ describe('tsType', () => { // @ts-expect-error assert.tsType('hi').equals(5); }); + it('can compare enums', () => { + enum MyEnum { + First = 'first', + Second = 'second', + Third = 'third', + } + + assert.tsType<{myEnum: MyEnum}>().equals<{myEnum: MyEnum}>(); + }); + it('supports slowEquals', () => { + assert.tsType<{a: string} & {b: number}>().notEquals<{a: string; b: number}>(); + assert.tsType<{a: string} & {b: number}>().slowEquals<{a: string; b: number}>(); + }); it('can compare unknown', () => { assert.tsType().notEquals(); assert.tsType().notEquals(); diff --git a/packages/assert/src/assertions/equality/ts-type-equality.ts b/packages/assert/src/assertions/equality/ts-type-equality.ts index 9a82bd0c..87d5838b 100644 --- a/packages/assert/src/assertions/equality/ts-type-equality.ts +++ b/packages/assert/src/assertions/equality/ts-type-equality.ts @@ -4,6 +4,9 @@ import {type GuardGroup} from '../../guard-types/guard-group.js'; type AssertTypeOf = { equals: ExpectTypeOf['toEqualTypeOf']; notEquals: ExpectTypeOf['toEqualTypeOf']; + + slowEquals: ExpectTypeOf['branded']['toEqualTypeOf']; + matches: ExpectTypeOf['toMatchTypeOf']; notMatches: ExpectTypeOf['toMatchTypeOf']; }; @@ -26,27 +29,11 @@ function tsType( notEquals: () => {}, matches: () => {}, notMatches: () => {}, + slowEquals: () => {}, } satisfies Record, () => void> as AssertTypeOf; } const assertions: { - /** - * Check if a value or type matches type expectations. Use this to write type tests. - * - * This should not be used in production code. It won't cause any issues there, but it also - * provides no value there. - * - * Performs no type guarding. - * - * @example - * - * ```ts - * import {assert} from '@augment-vir/assert'; - * - * assert.tsType('hello').equals(); - * ``` - */ - /** * Asserts within the TypeScript type system that a given type or value matches type * expectations (using the [`expect-type`](https://www.npmjs.com/package/expect-type) package. diff --git a/packages/assert/src/assertions/length.ts b/packages/assert/src/assertions/length.ts index 62447363..a687cbe0 100644 --- a/packages/assert/src/assertions/length.ts +++ b/packages/assert/src/assertions/length.ts @@ -67,7 +67,7 @@ function isLengthExactly( } } -/** These functions are not used at run time, they're only here for types. */ +// These functions are not used at run time, they're only here for types. /* node:coverage disable */ function checkIsLengthAtLeast( diff --git a/packages/common/package.json b/packages/common/package.json index 6ce05ed3..5a119d01 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@augment-vir/common", - "version": "30.0.5", + "version": "30.1.0", "description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.", "keywords": [ "augment", @@ -39,8 +39,8 @@ "test:web": "virmator --no-deps test web" }, "dependencies": { - "@augment-vir/assert": "^30.0.5", - "@augment-vir/core": "^30.0.5", + "@augment-vir/assert": "^30.1.0", + "@augment-vir/core": "^30.1.0", "@date-vir/duration": "^6.0.0", "ansi-styles": "^6.2.1", "json5": "^2.2.3", diff --git a/packages/core/package.json b/packages/core/package.json index d984ac39..537565a2 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@augment-vir/core", - "version": "30.0.5", + "version": "30.1.0", "description": "Core augment-vir augments. Use @augment-vir/common instead.", "homepage": "https://github.com/electrovir/augment-vir", "bugs": { diff --git a/packages/node/package.json b/packages/node/package.json index 231dc4f6..3cc29fcf 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -1,6 +1,6 @@ { "name": "@augment-vir/node", - "version": "30.0.5", + "version": "30.1.0", "description": "A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.", "keywords": [ "augment", @@ -37,8 +37,8 @@ "test:update": "npm test" }, "dependencies": { - "@augment-vir/assert": "^30.0.5", - "@augment-vir/common": "^30.0.5", + "@augment-vir/assert": "^30.1.0", + "@augment-vir/common": "^30.1.0", "@date-vir/duration": "^6.0.0", "ansi-styles": "^6.2.1", "terminate": "^2.8.0", @@ -46,7 +46,7 @@ "typed-event-target": "^3.4.0" }, "devDependencies": { - "@augment-vir/test": "^30.0.5", + "@augment-vir/test": "^30.1.0", "@prisma/client": "^5.19.1", "@types/node": "^22.5.5", "@web/dev-server-esbuild": "^1.0.2", diff --git a/packages/scripts/package.json b/packages/scripts/package.json index a3430089..e4ad1823 100644 --- a/packages/scripts/package.json +++ b/packages/scripts/package.json @@ -1,6 +1,6 @@ { "name": "@augment-vir/scripts", - "version": "30.0.5", + "version": "30.1.0", "private": true, "homepage": "https://github.com/electrovir/augment-vir", "bugs": { @@ -24,14 +24,14 @@ "test:update": "npm test" }, "dependencies": { - "@augment-vir/assert": "^30.0.5", - "@augment-vir/core": "^30.0.5", + "@augment-vir/assert": "^30.1.0", + "@augment-vir/core": "^30.1.0", "@virmator/docs": "^13.3.15", "jsdom": "^25.0.1", "typedoc": "^0.26.7" }, "devDependencies": { - "@augment-vir/test": "^30.0.5", + "@augment-vir/test": "^30.1.0", "@types/jsdom": "^21.1.7", "@types/node": "^22.5.5" }, diff --git a/packages/test/package.json b/packages/test/package.json index 25f71f84..b549d9ec 100644 --- a/packages/test/package.json +++ b/packages/test/package.json @@ -1,6 +1,6 @@ { "name": "@augment-vir/test", - "version": "30.0.5", + "version": "30.1.0", "description": "A universal testing suite that works with Mocha style test runners _and_ Node.js's built-in test runner.", "keywords": [ "test", @@ -42,8 +42,8 @@ "test:web": "virmator test --no-deps web 'src/test-web/**/*.test.ts'" }, "dependencies": { - "@augment-vir/assert": "^30.0.5", - "@augment-vir/common": "^30.0.5", + "@augment-vir/assert": "^30.1.0", + "@augment-vir/common": "^30.1.0", "@open-wc/testing-helpers": "^3.0.1", "type-fest": "^4.26.1" }, diff --git a/packages/web/package.json b/packages/web/package.json index 0033d069..2e2f6df8 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -1,6 +1,6 @@ { "name": "@augment-vir/web", - "version": "30.0.5", + "version": "30.1.0", "description": "A collection of augments, helpers types, functions, and classes only for web (frontend) JavaScript environments.", "keywords": [ "augment", @@ -35,14 +35,14 @@ "test:update": "npm test" }, "dependencies": { - "@augment-vir/assert": "^30.0.5", - "@augment-vir/common": "^30.0.5", + "@augment-vir/assert": "^30.1.0", + "@augment-vir/common": "^30.1.0", "@date-vir/duration": "^6.0.0", "html-spec-tags": "^2.2.1", "type-fest": "^4.26.1" }, "devDependencies": { - "@augment-vir/test": "^30.0.5", + "@augment-vir/test": "^30.1.0", "bowser": "^2.11.0", "typescript": "^5.6.2" }, diff --git a/todo.md b/todo.md index d0a5556b..972cb35b 100644 --- a/todo.md +++ b/todo.md @@ -28,6 +28,7 @@ - finish updating `date-vir` - add `parseJsonWithShape` to `object-shape-tester` + - in progress - rename `runtimeType` in `object-shape-tester` - deprecate `run-time-assertions` - use `ListenTarget` for `ShellEmitter`