tstyche 1.0.0-beta.6 → 1.0.0-beta.8

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,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.0-beta.8] - 2024-01-05
4
+
5
+ ### Changed
6
+
7
+ - **Breaking!** Make `"target": ["current"]` the default instead of `"target": ["latest"]` ([#81](https://github.com/tstyche/tstyche/pull/81), [#80](https://github.com/tstyche/tstyche/pull/80), [#66](https://github.com/tstyche/tstyche/pull/66))
8
+ - **New!** Load the installed TypeScript package for type testing instead of installing another copy to the store ([#71](https://github.com/tstyche/tstyche/pull/71), [#64](https://github.com/tstyche/tstyche/pull/64))
9
+
10
+ ### Added
11
+
12
+ - Add the `Path` class ([#59](https://github.com/tstyche/tstyche/pull/59))
13
+
14
+ ### Fixed
15
+
16
+ - Correctly handle command line options that do not take a value ([#58](https://github.com/tstyche/tstyche/pull/58))
17
+
18
+ ## [1.0.0-beta.7] - 2023-12-29
19
+
20
+ ### Changed
21
+
22
+ - **Breaking!** Add new `Expect` class to validate provided values and orchestrate matchers logic ([#39](https://github.com/tstyche/tstyche/pull/39))
23
+
24
+ ### Added
25
+
26
+ - **New!** Load local language service plugins to support files like `.svelte` or `.vue` ([#56](https://github.com/tstyche/tstyche/pull/56))
27
+
28
+ ### Fixed
29
+
30
+ - Make the source argument checks stricter for the `.toHaveProperty()` matcher ([#46](https://github.com/tstyche/tstyche/pull/46))
31
+
3
32
  ## [1.0.0-beta.6] - 2023-12-03
4
33
 
5
34
  ### Added
@@ -65,6 +94,8 @@
65
94
 
66
95
  _First pre-release._
67
96
 
97
+ [1.0.0-beta.8]: https://github.com/tstyche/tstyche/releases/tag/v1.0.0-beta.8
98
+ [1.0.0-beta.7]: https://github.com/tstyche/tstyche/releases/tag/v1.0.0-beta.7
68
99
  [1.0.0-beta.6]: https://github.com/tstyche/tstyche/releases/tag/v1.0.0-beta.6
69
100
  [1.0.0-beta.5]: https://github.com/tstyche/tstyche/releases/tag/v1.0.0-beta.5
70
101
  [1.0.0-beta.4]: https://github.com/tstyche/tstyche/releases/tag/v1.0.0-beta.4
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.
@@ -83,7 +83,7 @@ Visit [https://tstyche.org](https://tstyche.org) to view the full documentation.
83
83
  [version-href]: https://npmjs.com/package/tstyche
84
84
  [license-src]: https://badgen.net/github/license/tstyche/tstyche
85
85
  [license-href]: https://github.com/tstyche/tstyche/blob/main/LICENSE.md
86
- [checks-src]: https://badgen.net/github/checks/tstyche/tstyche
87
- [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
88
88
  [coverage-src]: https://badgen.net/codecov/c/github/tstyche/tstyche
89
89
  [coverage-href]: https://app.codecov.io/gh/tstyche/tstyche
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
 
3
- import type ts from 'typescript/lib/tsserverlibrary.js';
3
+ import type ts from 'typescript';
4
4
 
5
5
  declare enum DiagnosticCategory {
6
6
  Error = "error",
@@ -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;
@@ -35,26 +36,21 @@ declare class Diagnostic {
35
36
  declare class StoreService {
36
37
  #private;
37
38
  constructor();
38
- get supportedTags(): Array<string>;
39
+ getSupportedTags(signal?: AbortSignal): Promise<Array<string>>;
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
- resolveTag(tag: string): string | undefined;
43
+ prune: () => Promise<void>;
44
+ resolveTag(tag: string, signal?: AbortSignal): Promise<string | undefined>;
44
45
  update(signal?: AbortSignal): Promise<void>;
45
- validateTag(tag: string): boolean;
46
- }
47
-
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;
46
+ validateTag(tag: string, signal?: AbortSignal): Promise<boolean>;
52
47
  }
53
48
 
54
49
  declare enum OptionBrand {
55
50
  String = "string",
56
51
  Number = "number",
57
52
  Boolean = "boolean",
53
+ True = "true",// an option which does not take a value
58
54
  List = "list",
59
55
  Object = "object"
60
56
  }
@@ -82,7 +78,7 @@ interface BaseOptionDefinition {
82
78
  required?: boolean;
83
79
  }
84
80
  interface PrimitiveTypeOptionDefinition extends BaseOptionDefinition {
85
- brand: OptionBrand.String | OptionBrand.Number | OptionBrand.Boolean;
81
+ brand: OptionBrand.String | OptionBrand.Number | OptionBrand.Boolean | OptionBrand.True;
86
82
  }
87
83
  interface ListTypeOptionDefinition extends BaseOptionDefinition {
88
84
  brand: OptionBrand.List;
@@ -115,7 +111,7 @@ interface CommandLineOptions {
115
111
  */
116
112
  failFast?: boolean;
117
113
  /**
118
- * Print the list of CLI options with brief descriptions and exit.
114
+ * Print the list of command line options with brief descriptions and exit.
119
115
  */
120
116
  help?: boolean;
121
117
  /**
@@ -195,7 +191,7 @@ declare class ConfigService {
195
191
  get commandLineOptions(): CommandLineOptions;
196
192
  get configFileOptions(): ConfigFileOptions;
197
193
  static get defaultOptions(): Required<ConfigFileOptions>;
198
- parseCommandLine(commandLineArgs: Array<string>): void;
194
+ parseCommandLine(commandLineArgs: Array<string>): Promise<void>;
199
195
  readConfigFile(filePath?: string, // TODO take URL as well
200
196
  sourceText?: string): Promise<void>;
201
197
  resolveConfig(): ResolvedConfig;
@@ -205,14 +201,15 @@ declare class ConfigService {
205
201
  declare class TSTyche {
206
202
  #private;
207
203
  readonly resolvedConfig: ResolvedConfig;
204
+ static readonly version = "__version__";
208
205
  constructor(resolvedConfig: ResolvedConfig, storeService: StoreService);
209
- static get version(): string;
210
206
  run(testFiles: Array<string | URL>): Promise<void>;
211
207
  }
212
208
 
213
- declare enum AssertionSource {
214
- Argument = 0,
215
- TypeArgument = 1
209
+ declare class Cli {
210
+ #private;
211
+ constructor(process: NodeJS.Process);
212
+ run(commandLineArguments: Array<string>): Promise<void>;
216
213
  }
217
214
 
218
215
  declare enum TestMemberBrand {
@@ -231,25 +228,22 @@ declare enum TestMemberFlags {
231
228
 
232
229
  declare class TestTree {
233
230
  compiler: typeof ts;
234
- diagnostics: Array<ts.Diagnostic>;
231
+ diagnostics: Set<ts.Diagnostic>;
235
232
  sourceFile: ts.SourceFile;
236
- typeChecker?: TypeChecker | undefined;
237
233
  members: Array<TestMember | Assertion>;
238
- constructor(compiler: typeof ts, diagnostics: Array<ts.Diagnostic>, sourceFile: ts.SourceFile, typeChecker?: TypeChecker | undefined);
234
+ constructor(compiler: typeof ts, diagnostics: Set<ts.Diagnostic>, sourceFile: ts.SourceFile);
239
235
  get hasOnly(): boolean;
240
236
  }
241
237
 
242
238
  declare class TestMember {
243
- #private;
244
239
  brand: TestMemberBrand;
245
240
  node: ts.CallExpression;
246
241
  parent: TestTree | TestMember;
247
242
  flags: TestMemberFlags;
248
243
  compiler: typeof ts;
249
- diagnostics: Array<ts.Diagnostic>;
244
+ diagnostics: Set<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>;
@@ -259,25 +253,15 @@ interface MatcherNode extends ts.CallExpression {
259
253
  expression: ts.PropertyAccessExpression;
260
254
  }
261
255
  declare class Assertion extends TestMember {
262
- #private;
263
256
  matcherNode: MatcherNode;
264
257
  modifierNode: ts.PropertyAccessExpression;
265
258
  notNode: ts.PropertyAccessExpression | undefined;
266
259
  isNot: boolean;
267
- name: string;
268
260
  constructor(brand: TestMemberBrand, node: ts.CallExpression, parent: TestTree | TestMember, flags: TestMemberFlags, matcherNode: MatcherNode, modifierNode: ts.PropertyAccessExpression, notNode: ts.PropertyAccessExpression | undefined);
269
261
  get ancestorNames(): Array<string>;
270
262
  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;
263
+ get source(): ts.NodeArray<ts.Expression> | ts.NodeArray<ts.TypeNode>;
264
+ get target(): ts.NodeArray<ts.Expression> | ts.NodeArray<ts.TypeNode>;
281
265
  }
282
266
 
283
267
  declare class CollectService {
@@ -287,25 +271,15 @@ declare class CollectService {
287
271
  readonly modifierIdentifiers: string[];
288
272
  readonly notIdentifier = "not";
289
273
  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>;
274
+ createTestTree(sourceFile: ts.SourceFile, semanticDiagnostics?: Array<ts.Diagnostic>): TestTree;
305
275
  }
306
276
 
307
277
  declare class Environment {
308
278
  #private;
279
+ /**
280
+ * Is `true` if the TypeScript package is installed.
281
+ */
282
+ static get isTypeScriptInstalled(): boolean;
309
283
  /**
310
284
  * Specifies whether color should be disabled in the output.
311
285
  */
@@ -481,6 +455,89 @@ declare class EventEmitter {
481
455
  static removeHandler(handler: EventHandler): void;
482
456
  }
483
457
 
458
+ interface MatchResult {
459
+ explain: () => Array<Diagnostic>;
460
+ isMatch: boolean;
461
+ }
462
+ interface TypeChecker extends ts.TypeChecker {
463
+ isTypeAssignableTo: (source: ts.Type, target: ts.Type) => boolean;
464
+ isTypeIdenticalTo: (source: ts.Type, target: ts.Type) => boolean;
465
+ isTypeSubtypeOf: (source: ts.Type, target: ts.Type) => boolean;
466
+ }
467
+
468
+ declare class PrimitiveTypeMatcher {
469
+ #private;
470
+ typeChecker: TypeChecker;
471
+ constructor(typeChecker: TypeChecker, targetTypeFlag: ts.TypeFlags, targetTypeText: string);
472
+ match(sourceType: ts.Type, isNot: boolean): MatchResult;
473
+ }
474
+
475
+ declare class ToBeAssignable {
476
+ #private;
477
+ typeChecker: TypeChecker;
478
+ constructor(typeChecker: TypeChecker);
479
+ match(sourceType: ts.Type, targetType: ts.Type, isNot: boolean): MatchResult;
480
+ }
481
+
482
+ declare class ToEqual {
483
+ #private;
484
+ typeChecker: TypeChecker;
485
+ constructor(typeChecker: TypeChecker);
486
+ match(sourceType: ts.Type, targetType: ts.Type, isNot: boolean): MatchResult;
487
+ }
488
+
489
+ declare class ToHaveProperty {
490
+ #private;
491
+ compiler: typeof ts;
492
+ typeChecker: TypeChecker;
493
+ constructor(compiler: typeof ts, typeChecker: TypeChecker);
494
+ match(sourceType: ts.Type, targetType: ts.StringLiteralType | ts.NumberLiteralType | ts.UniqueESSymbolType, isNot: boolean): MatchResult;
495
+ }
496
+
497
+ declare class ToMatch {
498
+ #private;
499
+ typeChecker: TypeChecker;
500
+ constructor(typeChecker: TypeChecker);
501
+ match(sourceType: ts.Type, targetType: ts.Type, isNot: boolean): MatchResult;
502
+ }
503
+
504
+ declare class ToRaiseError {
505
+ #private;
506
+ compiler: typeof ts;
507
+ typeChecker: TypeChecker;
508
+ constructor(compiler: typeof ts, typeChecker: TypeChecker);
509
+ match(source: {
510
+ diagnostics: Array<ts.Diagnostic>;
511
+ node: ts.Expression | ts.TypeNode;
512
+ }, targetTypes: Array<ts.StringLiteralType | ts.NumberLiteralType>, isNot: boolean): MatchResult;
513
+ }
514
+
515
+ declare class Expect {
516
+ #private;
517
+ compiler: typeof ts;
518
+ typeChecker: TypeChecker;
519
+ toBeAny: PrimitiveTypeMatcher;
520
+ toBeAssignable: ToBeAssignable;
521
+ toBeBigInt: PrimitiveTypeMatcher;
522
+ toBeBoolean: PrimitiveTypeMatcher;
523
+ toBeNever: PrimitiveTypeMatcher;
524
+ toBeNull: PrimitiveTypeMatcher;
525
+ toBeNumber: PrimitiveTypeMatcher;
526
+ toBeString: PrimitiveTypeMatcher;
527
+ toBeSymbol: PrimitiveTypeMatcher;
528
+ toBeUndefined: PrimitiveTypeMatcher;
529
+ toBeUniqueSymbol: PrimitiveTypeMatcher;
530
+ toBeUnknown: PrimitiveTypeMatcher;
531
+ toBeVoid: PrimitiveTypeMatcher;
532
+ toEqual: ToEqual;
533
+ toHaveProperty: ToHaveProperty;
534
+ toMatch: ToMatch;
535
+ toRaiseError: ToRaiseError;
536
+ constructor(compiler: typeof ts, typeChecker: TypeChecker);
537
+ static assertTypeChecker(typeChecker: ts.TypeChecker): typeChecker is TypeChecker;
538
+ match(assertion: Assertion, expectResult: ExpectResult): MatchResult | undefined;
539
+ }
540
+
484
541
  /**
485
542
  * Options to configure an instance of the {@link Logger}.
486
543
  */
@@ -521,6 +578,46 @@ declare class Logger {
521
578
  writeWarning(body: JSX.Element | Array<JSX.Element>): void;
522
579
  }
523
580
 
581
+ declare function addsPackageStepText(compilerVersion: string, installationPath: string): JSX.Element;
582
+
583
+ declare function describeNameText(name: string, indent?: number): JSX.Element;
584
+
585
+ declare function diagnosticText(diagnostic: Diagnostic): JSX.Element;
586
+
587
+ declare function fileStatusText(status: FileResultStatus, testFile: URL): JSX.Element;
588
+
589
+ declare function fileViewText(lines: Array<JSX.Element>, addEmptyFinalLine: boolean): JSX.Element;
590
+
591
+ declare function formattedText(input: string | Array<string> | Record<string, unknown>): JSX.Element;
592
+
593
+ declare function helpText(optionDefinitions: Map<string, OptionDefinition>, tstycheVersion: string): JSX.Element;
594
+
595
+ declare function summaryText({ duration, expectCount, fileCount, onlyMatch, pathMatch, skipMatch, targetCount, testCount, }: {
596
+ duration: number;
597
+ expectCount: ResultCount;
598
+ fileCount: ResultCount;
599
+ onlyMatch: string | undefined;
600
+ pathMatch: Array<string>;
601
+ skipMatch: string | undefined;
602
+ targetCount: ResultCount;
603
+ testCount: ResultCount;
604
+ }): JSX.Element;
605
+
606
+ declare function testNameText(status: "fail" | "pass" | "skip" | "todo", name: string, indent?: number): JSX.Element;
607
+
608
+ declare function usesCompilerStepText(compilerVersion: string, tsconfigFilePath: string | undefined, options?: {
609
+ prependEmptyLine: boolean;
610
+ }): JSX.Element;
611
+
612
+ declare class Path {
613
+ static basename(filePath: string): string;
614
+ static dirname(filePath: string): string;
615
+ static join(...filePaths: Array<string>): string;
616
+ static normalizeSlashes(filePath: string): string;
617
+ static relative(from: string, to: string): string;
618
+ static resolve(...filePaths: Array<string>): string;
619
+ }
620
+
524
621
  declare class ProjectService {
525
622
  #private;
526
623
  compiler: typeof ts;
@@ -565,16 +662,6 @@ declare enum Color {
565
662
  Gray = "90"
566
663
  }
567
664
 
568
- declare function addsPackageStepText(compilerVersion: string, installationPath: string): JSX.Element;
569
-
570
- declare function describeNameText(name: string, indent?: number): JSX.Element;
571
-
572
- declare function diagnosticText(diagnostic: Diagnostic): JSX.Element;
573
-
574
- declare function fileStatusText(status: FileResultStatus, testFile: URL): JSX.Element;
575
-
576
- declare function fileViewText(lines: Array<JSX.Element>, addEmptyFinalLine: boolean): JSX.Element;
577
-
578
665
  interface LineProps {
579
666
  children?: JSX.ElementChildrenAttribute["children"];
580
667
  color?: Color;
@@ -586,34 +673,6 @@ declare class Line implements JSX.ElementClass {
586
673
  render(): JSX.Element;
587
674
  }
588
675
 
589
- declare function summaryText({ duration, expectCount, fileCount, onlyMatch, pathMatch, skipMatch, targetCount, testCount, }: {
590
- duration: number;
591
- expectCount: ResultCount;
592
- fileCount: ResultCount;
593
- onlyMatch: string | undefined;
594
- pathMatch: Array<string>;
595
- skipMatch: string | undefined;
596
- targetCount: ResultCount;
597
- testCount: ResultCount;
598
- }): JSX.Element;
599
-
600
- declare function testNameText(status: "fail" | "pass" | "skip" | "todo", name: string, indent?: number): JSX.Element;
601
-
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
- declare function usesCompilerStepText(compilerVersion: string, tsconfigFilePath: string | undefined, options?: {
614
- prependEmptyLine: boolean;
615
- }): JSX.Element;
616
-
617
676
  type ElementChildren = Array<ElementChildren> | JSX.Element | string | undefined;
618
677
  type ComponentConstructor = new (props: Record<string, unknown>) => JSX.ElementClass;
619
678
  declare global {
@@ -676,4 +735,15 @@ declare class Scribbler {
676
735
  render(element: JSX.Element | null): string;
677
736
  }
678
737
 
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 };
738
+ interface TextProps {
739
+ children?: JSX.ElementChildrenAttribute["children"];
740
+ color?: Color | undefined;
741
+ indent?: number | undefined;
742
+ }
743
+ declare class Text implements JSX.ElementClass {
744
+ readonly props: TextProps;
745
+ constructor(props: TextProps);
746
+ render(): JSX.Element;
747
+ }
748
+
749
+ export { Assertion, Cli, CollectService, Color, type CommandLineOptions, type ConfigFileOptions, ConfigService, DescribeResult, Diagnostic, DiagnosticCategory, type DiagnosticOrigin, Environment, type Event, EventEmitter, type EventHandler, Expect, ExpectResult, FileResult, type FileResultStatus, type ItemDefinition, Line, Logger, type LoggerOptions, type MatchResult, OptionBrand, type OptionDefinition, OptionDefinitionsMap, OptionGroup, Path, 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, formattedText, helpText, summaryText, testNameText, usesCompilerStepText };