tstyche 1.0.0-beta.5 → 1.0.0-beta.7

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/CHANGELOG.md CHANGED
@@ -1,19 +1,43 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.0-beta.7] - 2023-12-29
4
+
5
+ ### Changed
6
+
7
+ - **Breaking!** Add new `Expect` class to validate provided values and orchestrate matchers logic ([#39](https://github.com/tstyche/tstyche/pull/39))
8
+
9
+ ### Added
10
+
11
+ - **New!** Load local language service plugins to support files like `.svelte` or `.vue` ([#56](https://github.com/tstyche/tstyche/pull/56))
12
+
13
+ ### Fixed
14
+
15
+ - Make the source argument checks stricter for the `.toHaveProperty()` matcher ([#46](https://github.com/tstyche/tstyche/pull/46))
16
+
17
+ ## [1.0.0-beta.6] - 2023-12-03
18
+
19
+ ### Added
20
+
21
+ - **New!** Add `.toHaveProperty()` matcher ([#36](https://github.com/tstyche/tstyche/pull/36))
22
+
23
+ ### Fixed
24
+
25
+ - Accept template literals as arguments of the `.toRaiseError()` matcher ([#38](https://github.com/tstyche/tstyche/pull/38))
26
+
3
27
  ## [1.0.0-beta.5] - 2023-11-27
4
28
 
5
29
  ### Changed
6
30
 
7
- - **Breaking:** Move retry logic to the `Lock` class ([#31](https://github.com/tstyche/tstyche/pull/31))
31
+ - **Breaking!** Move retry logic to the `Lock` class ([#31](https://github.com/tstyche/tstyche/pull/31))
8
32
  - Bring back support for Node.js 16 ([#28](https://github.com/tstyche/tstyche/pull/28), [#27](https://github.com/tstyche/tstyche/pull/27))
9
33
 
10
34
  ### Added
11
35
 
12
- - Add support for the `current` target tag ([#33](https://github.com/tstyche/tstyche/pull/33))
36
+ - **New!** Add support for the `current` target tag ([#33](https://github.com/tstyche/tstyche/pull/33))
13
37
 
14
38
  ### Fixed
15
39
 
16
- - Allow `.raiseError()` to take template literals as arguments. ([#35](https://github.com/tstyche/tstyche/pull/35))
40
+ - Allow `.raiseError()` to take template literals as arguments ([#35](https://github.com/tstyche/tstyche/pull/35))
17
41
 
18
42
  ## [1.0.0-beta.4] - 2023-11-24
19
43
 
@@ -23,9 +47,9 @@
23
47
 
24
48
  ### Removed
25
49
 
26
- - **Breaking:** Remove the `context()` helper ([#24](https://github.com/tstyche/tstyche/pull/24))
27
- - **Breaking:** Drop support for Node.js 16 ([#22](https://github.com/tstyche/tstyche/pull/22))
28
- - **Breaking:** Rename methods of the `StoreService` class ([`5d74201`](https://github.com/tstyche/tstyche/commit/5d74201))
50
+ - **Breaking!** Remove the `context()` helper ([#24](https://github.com/tstyche/tstyche/pull/24))
51
+ - **Breaking!** Drop support for Node.js 16 ([#22](https://github.com/tstyche/tstyche/pull/22))
52
+ - **Breaking!** Rename methods of the `StoreService` class ([`5d74201`](https://github.com/tstyche/tstyche/commit/5d74201))
29
53
 
30
54
  ### Fixed
31
55
 
@@ -55,6 +79,8 @@
55
79
 
56
80
  _First pre-release._
57
81
 
82
+ [1.0.0-beta.7]: https://github.com/tstyche/tstyche/releases/tag/v1.0.0-beta.7
83
+ [1.0.0-beta.6]: https://github.com/tstyche/tstyche/releases/tag/v1.0.0-beta.6
58
84
  [1.0.0-beta.5]: https://github.com/tstyche/tstyche/releases/tag/v1.0.0-beta.5
59
85
  [1.0.0-beta.4]: https://github.com/tstyche/tstyche/releases/tag/v1.0.0-beta.4
60
86
  [1.0.0-beta.3]: https://github.com/tstyche/tstyche/releases/tag/v1.0.0-beta.3
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![version][version-src]][version-href]
4
4
  [![license][license-src]][license-href]
5
- [![checks][checks-src]][checks-href]
5
+ [![packagephobia][packagephobia-src]][packagephobia-href]
6
6
  [![coverage][coverage-src]][coverage-href]
7
7
 
8
8
  The Essential Type Testing Tool.
@@ -56,9 +56,10 @@ test("handles numbers", () => {
56
56
 
57
57
  Here is the list of all matchers:
58
58
 
59
- - `.toBeAssignable()`, `.toEqual()`, `.toMatch()` compares types or types of expression;
60
- - `.toRaiseError()` captures the error message or code;
61
- - `.toBeString()`, `.toBeNumber()`, `.toBeVoid()` and 9 more checks for primitive types.
59
+ - `.toBeAssignable()`, `.toEqual()`, `.toMatch()` compares types or types of expression,
60
+ - `.toHaveProperty()` looks up keys on an object type,
61
+ - `.toRaiseError()` captures the type error message or code,
62
+ - `.toBeString()`, `.toBeNumber()`, `.toBeVoid()` and 9 more shorthand checks for primitive types.
62
63
 
63
64
  ## Runner
64
65
 
@@ -82,7 +83,7 @@ Visit [https://tstyche.org](https://tstyche.org) to view the full documentation.
82
83
  [version-href]: https://npmjs.com/package/tstyche
83
84
  [license-src]: https://badgen.net/github/license/tstyche/tstyche
84
85
  [license-href]: https://github.com/tstyche/tstyche/blob/main/LICENSE.md
85
- [checks-src]: https://badgen.net/github/checks/tstyche/tstyche
86
- [checks-href]: https://github.com/tstyche/tstyche/actions/workflows/checks.yml
86
+ [packagephobia-src]: https://badgen.net/packagephobia/install/tstyche
87
+ [packagephobia-href]: https://packagephobia.com/result?p=tstyche
87
88
  [coverage-src]: https://badgen.net/codecov/c/github/tstyche/tstyche
88
89
  [coverage-href]: https://app.codecov.io/gh/tstyche/tstyche
package/build/index.d.cts CHANGED
@@ -133,6 +133,10 @@ interface Matchers {
133
133
  */
134
134
  (target: unknown): void;
135
135
  };
136
+ /**
137
+ * Checks if a property key exists on the source type.
138
+ */
139
+ toHaveProperty: (key: string | number | symbol) => void;
136
140
  /**
137
141
  * Checks if the target type is a subtype the source type.
138
142
  */
package/build/index.d.ts CHANGED
@@ -133,6 +133,10 @@ interface Matchers {
133
133
  */
134
134
  (target: unknown): void;
135
135
  };
136
+ /**
137
+ * Checks if a property key exists on the source type.
138
+ */
139
+ toHaveProperty: (key: string | number | symbol) => void;
136
140
  /**
137
141
  * Checks if the target type is a subtype the source type.
138
142
  */
@@ -23,6 +23,7 @@ declare class Diagnostic {
23
23
  constructor(text: string | Array<string>, category: DiagnosticCategory, origin?: DiagnosticOrigin | undefined);
24
24
  add(options: {
25
25
  code?: string;
26
+ origin?: DiagnosticOrigin;
26
27
  related?: Array<Diagnostic>;
27
28
  }): this;
28
29
  static error(text: string | Array<string>, origin?: DiagnosticOrigin): Diagnostic;
@@ -39,18 +40,12 @@ declare class StoreService {
39
40
  install(tag: string, signal?: AbortSignal): Promise<string | undefined>;
40
41
  load(tag: string, signal?: AbortSignal): Promise<typeof ts | undefined>;
41
42
  open(signal?: AbortSignal): Promise<void>;
42
- prune(): Promise<void>;
43
+ prune: () => Promise<void>;
43
44
  resolveTag(tag: string): string | undefined;
44
45
  update(signal?: AbortSignal): Promise<void>;
45
46
  validateTag(tag: string): boolean;
46
47
  }
47
48
 
48
- interface TypeChecker extends ts.TypeChecker {
49
- isTypeAssignableTo?: (source: ts.Type, target: ts.Type) => boolean;
50
- isTypeIdenticalTo?: (source: ts.Type, target: ts.Type) => boolean;
51
- isTypeSubtypeOf?: (source: ts.Type, target: ts.Type) => boolean;
52
- }
53
-
54
49
  declare enum OptionBrand {
55
50
  String = "string",
56
51
  Number = "number",
@@ -210,9 +205,10 @@ declare class TSTyche {
210
205
  run(testFiles: Array<string | URL>): Promise<void>;
211
206
  }
212
207
 
213
- declare enum AssertionSource {
214
- Argument = 0,
215
- TypeArgument = 1
208
+ declare class Cli {
209
+ #private;
210
+ constructor(process: NodeJS.Process);
211
+ run(commandLineArgs: Array<string>): Promise<void>;
216
212
  }
217
213
 
218
214
  declare enum TestMemberBrand {
@@ -233,9 +229,8 @@ declare class TestTree {
233
229
  compiler: typeof ts;
234
230
  diagnostics: Array<ts.Diagnostic>;
235
231
  sourceFile: ts.SourceFile;
236
- typeChecker?: TypeChecker | undefined;
237
232
  members: Array<TestMember | Assertion>;
238
- constructor(compiler: typeof ts, diagnostics: Array<ts.Diagnostic>, sourceFile: ts.SourceFile, typeChecker?: TypeChecker | undefined);
233
+ constructor(compiler: typeof ts, diagnostics: Array<ts.Diagnostic>, sourceFile: ts.SourceFile);
239
234
  get hasOnly(): boolean;
240
235
  }
241
236
 
@@ -249,7 +244,6 @@ declare class TestMember {
249
244
  diagnostics: Array<ts.Diagnostic>;
250
245
  members: Array<TestMember | Assertion>;
251
246
  name: string;
252
- typeChecker?: TypeChecker | undefined;
253
247
  constructor(brand: TestMemberBrand, node: ts.CallExpression, parent: TestTree | TestMember, flags: TestMemberFlags);
254
248
  get ancestorNames(): Array<string>;
255
249
  validate(): Array<Diagnostic>;
@@ -268,16 +262,8 @@ declare class Assertion extends TestMember {
268
262
  constructor(brand: TestMemberBrand, node: ts.CallExpression, parent: TestTree | TestMember, flags: TestMemberFlags, matcherNode: MatcherNode, modifierNode: ts.PropertyAccessExpression, notNode: ts.PropertyAccessExpression | undefined);
269
263
  get ancestorNames(): Array<string>;
270
264
  get matcherName(): ts.MemberName;
271
- get sourceArguments(): ts.NodeArray<ts.Expression>;
272
- get sourceType(): {
273
- source: AssertionSource;
274
- type: ts.Type;
275
- } | undefined;
276
- get targetArguments(): ts.NodeArray<ts.Expression>;
277
- get targetType(): {
278
- source: AssertionSource;
279
- type: ts.Type;
280
- } | undefined;
265
+ get source(): ts.NodeArray<ts.Expression> | ts.NodeArray<ts.TypeNode>;
266
+ get target(): ts.NodeArray<ts.Expression> | ts.NodeArray<ts.TypeNode>;
281
267
  }
282
268
 
283
269
  declare class CollectService {
@@ -287,21 +273,7 @@ declare class CollectService {
287
273
  readonly modifierIdentifiers: string[];
288
274
  readonly notIdentifier = "not";
289
275
  constructor(compiler: typeof ts);
290
- createTestTree(sourceFile: ts.SourceFile, semanticDiagnostics?: Array<ts.Diagnostic>, typeChecker?: ts.TypeChecker | undefined): TestTree;
291
- }
292
-
293
- declare class Checker {
294
- #private;
295
- compiler: typeof ts;
296
- constructor(compiler: typeof ts);
297
- explain(assertion: Assertion): Array<Diagnostic>;
298
- match(assertion: Assertion): boolean;
299
- }
300
-
301
- declare class Cli {
302
- #private;
303
- constructor(process: NodeJS.Process);
304
- run(commandLineArgs: Array<string>): Promise<void>;
276
+ createTestTree(sourceFile: ts.SourceFile, semanticDiagnostics?: Array<ts.Diagnostic>): TestTree;
305
277
  }
306
278
 
307
279
  declare class Environment {
@@ -481,6 +453,89 @@ declare class EventEmitter {
481
453
  static removeHandler(handler: EventHandler): void;
482
454
  }
483
455
 
456
+ interface MatchResult {
457
+ explain: () => Array<Diagnostic>;
458
+ isMatch: boolean;
459
+ }
460
+ interface TypeChecker extends ts.TypeChecker {
461
+ isTypeAssignableTo: (source: ts.Type, target: ts.Type) => boolean;
462
+ isTypeIdenticalTo: (source: ts.Type, target: ts.Type) => boolean;
463
+ isTypeSubtypeOf: (source: ts.Type, target: ts.Type) => boolean;
464
+ }
465
+
466
+ declare class PrimitiveTypeMatcher {
467
+ #private;
468
+ typeChecker: TypeChecker;
469
+ constructor(typeChecker: TypeChecker, targetTypeFlag: ts.TypeFlags, targetTypeText: string);
470
+ match(sourceType: ts.Type, isNot: boolean): MatchResult;
471
+ }
472
+
473
+ declare class ToBeAssignable {
474
+ #private;
475
+ typeChecker: TypeChecker;
476
+ constructor(typeChecker: TypeChecker);
477
+ match(sourceType: ts.Type, targetType: ts.Type, isNot: boolean): MatchResult;
478
+ }
479
+
480
+ declare class ToEqual {
481
+ #private;
482
+ typeChecker: TypeChecker;
483
+ constructor(typeChecker: TypeChecker);
484
+ match(sourceType: ts.Type, targetType: ts.Type, isNot: boolean): MatchResult;
485
+ }
486
+
487
+ declare class ToHaveProperty {
488
+ #private;
489
+ compiler: typeof ts;
490
+ typeChecker: TypeChecker;
491
+ constructor(compiler: typeof ts, typeChecker: TypeChecker);
492
+ match(sourceType: ts.Type, targetType: ts.StringLiteralType | ts.NumberLiteralType | ts.UniqueESSymbolType, isNot: boolean): MatchResult;
493
+ }
494
+
495
+ declare class ToMatch {
496
+ #private;
497
+ typeChecker: TypeChecker;
498
+ constructor(typeChecker: TypeChecker);
499
+ match(sourceType: ts.Type, targetType: ts.Type, isNot: boolean): MatchResult;
500
+ }
501
+
502
+ declare class ToRaiseError {
503
+ #private;
504
+ compiler: typeof ts;
505
+ typeChecker: TypeChecker;
506
+ constructor(compiler: typeof ts, typeChecker: TypeChecker);
507
+ match(source: {
508
+ diagnostics: Array<ts.Diagnostic>;
509
+ node: ts.Expression | ts.TypeNode;
510
+ }, targetTypes: Array<ts.StringLiteralType | ts.NumberLiteralType>, isNot: boolean): MatchResult;
511
+ }
512
+
513
+ declare class Expect {
514
+ #private;
515
+ compiler: typeof ts;
516
+ typeChecker: TypeChecker;
517
+ toBeAny: PrimitiveTypeMatcher;
518
+ toBeAssignable: ToBeAssignable;
519
+ toBeBigInt: PrimitiveTypeMatcher;
520
+ toBeBoolean: PrimitiveTypeMatcher;
521
+ toBeNever: PrimitiveTypeMatcher;
522
+ toBeNull: PrimitiveTypeMatcher;
523
+ toBeNumber: PrimitiveTypeMatcher;
524
+ toBeString: PrimitiveTypeMatcher;
525
+ toBeSymbol: PrimitiveTypeMatcher;
526
+ toBeUndefined: PrimitiveTypeMatcher;
527
+ toBeUniqueSymbol: PrimitiveTypeMatcher;
528
+ toBeUnknown: PrimitiveTypeMatcher;
529
+ toBeVoid: PrimitiveTypeMatcher;
530
+ toEqual: ToEqual;
531
+ toHaveProperty: ToHaveProperty;
532
+ toMatch: ToMatch;
533
+ toRaiseError: ToRaiseError;
534
+ constructor(compiler: typeof ts, typeChecker: TypeChecker);
535
+ static assertTypeChecker(typeChecker: ts.TypeChecker): typeChecker is TypeChecker;
536
+ match(assertion: Assertion, expectResult: ExpectResult): MatchResult | undefined;
537
+ }
538
+
484
539
  /**
485
540
  * Options to configure an instance of the {@link Logger}.
486
541
  */
@@ -554,17 +609,6 @@ declare class TaskRunner {
554
609
  run(testFiles: Array<URL>, target: Array<string>, signal?: AbortSignal): Promise<Result>;
555
610
  }
556
611
 
557
- declare enum Color {
558
- Reset = "0",
559
- Red = "31",
560
- Green = "32",
561
- Yellow = "33",
562
- Blue = "34",
563
- Magenta = "35",
564
- Cyan = "36",
565
- Gray = "90"
566
- }
567
-
568
612
  declare function addsPackageStepText(compilerVersion: string, installationPath: string): JSX.Element;
569
613
 
570
614
  declare function describeNameText(name: string, indent?: number): JSX.Element;
@@ -575,16 +619,9 @@ declare function fileStatusText(status: FileResultStatus, testFile: URL): JSX.El
575
619
 
576
620
  declare function fileViewText(lines: Array<JSX.Element>, addEmptyFinalLine: boolean): JSX.Element;
577
621
 
578
- interface LineProps {
579
- children?: JSX.ElementChildrenAttribute["children"];
580
- color?: Color;
581
- indent?: number;
582
- }
583
- declare class Line implements JSX.ElementClass {
584
- readonly props: LineProps;
585
- constructor(props: LineProps);
586
- render(): JSX.Element;
587
- }
622
+ declare function formattedText(input: string | Array<string> | Record<string, unknown>): JSX.Element;
623
+
624
+ declare function helpText(optionDefinitions: Map<string, OptionDefinition>, tstycheVersion: string): JSX.Element;
588
625
 
589
626
  declare function summaryText({ duration, expectCount, fileCount, onlyMatch, pathMatch, skipMatch, targetCount, testCount, }: {
590
627
  duration: number;
@@ -599,21 +636,21 @@ declare function summaryText({ duration, expectCount, fileCount, onlyMatch, path
599
636
 
600
637
  declare function testNameText(status: "fail" | "pass" | "skip" | "todo", name: string, indent?: number): JSX.Element;
601
638
 
602
- interface TextProps {
603
- children?: JSX.ElementChildrenAttribute["children"];
604
- color?: Color | undefined;
605
- indent?: number | undefined;
606
- }
607
- declare class Text implements JSX.ElementClass {
608
- readonly props: TextProps;
609
- constructor(props: TextProps);
610
- render(): JSX.Element;
611
- }
612
-
613
639
  declare function usesCompilerStepText(compilerVersion: string, tsconfigFilePath: string | undefined, options?: {
614
640
  prependEmptyLine: boolean;
615
641
  }): JSX.Element;
616
642
 
643
+ declare enum Color {
644
+ Reset = "0",
645
+ Red = "31",
646
+ Green = "32",
647
+ Yellow = "33",
648
+ Blue = "34",
649
+ Magenta = "35",
650
+ Cyan = "36",
651
+ Gray = "90"
652
+ }
653
+
617
654
  type ElementChildren = Array<ElementChildren> | JSX.Element | string | undefined;
618
655
  type ComponentConstructor = new (props: Record<string, unknown>) => JSX.ElementClass;
619
656
  declare global {
@@ -676,4 +713,4 @@ declare class Scribbler {
676
713
  render(element: JSX.Element | null): string;
677
714
  }
678
715
 
679
- export { Assertion, AssertionSource, Checker, Cli, CollectService, Color, type CommandLineOptions, type ConfigFileOptions, ConfigService, DescribeResult, Diagnostic, DiagnosticCategory, type DiagnosticOrigin, Environment, type Event, EventEmitter, type EventHandler, ExpectResult, FileResult, type FileResultStatus, type ItemDefinition, Line, Logger, type LoggerOptions, OptionBrand, type OptionDefinition, OptionDefinitionsMap, OptionGroup, ProjectResult, ProjectService, Reporter, type ResolvedConfig, Result, ResultCount, ResultManager, ResultStatus, ResultTiming, Scribbler, type ScribblerOptions, StoreService, SummaryReporter, TSTyche, TargetResult, TaskRunner, TestMember, TestMemberBrand, TestMemberFlags, TestResult, TestTree, Text, ThoroughReporter, type TypeChecker, addsPackageStepText, describeNameText, diagnosticText, fileStatusText, fileViewText, summaryText, testNameText, usesCompilerStepText };
716
+ export { Assertion, Cli, CollectService, type CommandLineOptions, type ConfigFileOptions, ConfigService, DescribeResult, Diagnostic, DiagnosticCategory, type DiagnosticOrigin, Environment, type Event, EventEmitter, type EventHandler, Expect, ExpectResult, FileResult, type FileResultStatus, type ItemDefinition, Logger, type LoggerOptions, type MatchResult, OptionBrand, type OptionDefinition, OptionDefinitionsMap, OptionGroup, ProjectResult, ProjectService, Reporter, type ResolvedConfig, Result, ResultCount, ResultManager, ResultStatus, ResultTiming, Scribbler, type ScribblerOptions, StoreService, SummaryReporter, TSTyche, TargetResult, TaskRunner, TestMember, TestMemberBrand, TestMemberFlags, TestResult, TestTree, ThoroughReporter, type TypeChecker, addsPackageStepText, describeNameText, diagnosticText, fileStatusText, fileViewText, formattedText, helpText, summaryText, testNameText, usesCompilerStepText };