Skip to content

Commit

Permalink
[minor] add assert.tsType.slowEquals
Browse files Browse the repository at this point in the history
  • Loading branch information
electrovir committed Sep 23, 2024
1 parent 87bdd8d commit 4a00925
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 63 deletions.
46 changes: 23 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions packages/assert/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions packages/assert/src/assertions/equality/ts-type-equality.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ describe('tsType', () => {
// @ts-expect-error
assert.tsType<string>('hi').equals<number>(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<unknown>().notEquals<string>();
assert.tsType<string>().notEquals<unknown>();
Expand Down
21 changes: 4 additions & 17 deletions packages/assert/src/assertions/equality/ts-type-equality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {type GuardGroup} from '../../guard-types/guard-group.js';
type AssertTypeOf<TestingType> = {
equals: ExpectTypeOf<TestingType, {positive: true}>['toEqualTypeOf'];
notEquals: ExpectTypeOf<TestingType, {positive: false}>['toEqualTypeOf'];

slowEquals: ExpectTypeOf<TestingType, {positive: true}>['branded']['toEqualTypeOf'];

matches: ExpectTypeOf<TestingType, {positive: true}>['toMatchTypeOf'];
notMatches: ExpectTypeOf<TestingType, {positive: false}>['toMatchTypeOf'];
};
Expand All @@ -26,27 +29,11 @@ function tsType<Actual>(
notEquals: () => {},
matches: () => {},
notMatches: () => {},
slowEquals: () => {},
} satisfies Record<keyof AssertTypeOf<any>, () => void> as AssertTypeOf<Actual>;
}

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<string>();
* ```
*/

/**
* 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.
Expand Down
2 changes: 1 addition & 1 deletion packages/assert/src/assertions/length.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Element, Length extends number>(
Expand Down
6 changes: 3 additions & 3 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
8 changes: 4 additions & 4 deletions packages/node/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -37,16 +37,16 @@
"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",
"type-fest": "^4.26.1",
"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",
Expand Down
8 changes: 4 additions & 4 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/test/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/web/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
1 change: 1 addition & 0 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 4a00925

Please sign in to comment.