tstyche 5.0.0-beta.2 → 5.0.0-beta.3

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.
@@ -615,6 +615,8 @@ declare class OutputService {
615
615
  static writeWarning(element: ScribblerJsx.Element | Array<ScribblerJsx.Element>): void;
616
616
  }
617
617
 
618
+ declare function prologueText(runnerVersion: string, rootPath: string): ScribblerJsx.Element;
619
+
618
620
  interface SummaryTextOptions {
619
621
  targetCounts: ResultCounts;
620
622
  fileCounts: ResultCounts;
@@ -731,5 +733,5 @@ declare class Version {
731
733
  static isSatisfiedWith(source: string, target: string): boolean;
732
734
  }
733
735
 
734
- export { BaseReporter, CancellationReason, CancellationToken, Cli, Color, Config, ConfigDiagnosticText, DescribeResult, Diagnostic, DiagnosticCategory, DiagnosticOrigin, Directive, EventEmitter, ExpectResult, FileLocation, FileResult, Line, ListReporter, OptionBrand, OptionGroup, Options, OutputService, Path, PluginService, ProjectResult, Result, ResultStatus, Runner, Scribbler, ScribblerJsx, Select, SelectDiagnosticText, SetupReporter, Store, SummaryReporter, SuppressedResult, TargetResult, TestResult, Text, Version, WatchReporter, addsPackageText, defaultOptions, describeNameText, diagnosticBelongsToNode, diagnosticText, environmentOptions, fileStatusText, fileViewText, formattedText, getDiagnosticMessageText, getTextSpanEnd, helpText, isDiagnosticWithLocation, summaryText, testNameText, usesCompilerText, waitingForFileChangesText, watchUsageText };
736
+ export { BaseReporter, CancellationReason, CancellationToken, Cli, Color, Config, ConfigDiagnosticText, DescribeResult, Diagnostic, DiagnosticCategory, DiagnosticOrigin, Directive, EventEmitter, ExpectResult, FileLocation, FileResult, Line, ListReporter, OptionBrand, OptionGroup, Options, OutputService, Path, PluginService, ProjectResult, Result, ResultStatus, Runner, Scribbler, ScribblerJsx, Select, SelectDiagnosticText, SetupReporter, Store, SummaryReporter, SuppressedResult, TargetResult, TestResult, Text, Version, WatchReporter, addsPackageText, defaultOptions, describeNameText, diagnosticBelongsToNode, diagnosticText, environmentOptions, fileStatusText, fileViewText, formattedText, getDiagnosticMessageText, getTextSpanEnd, helpText, isDiagnosticWithLocation, prologueText, summaryText, testNameText, usesCompilerText, waitingForFileChangesText, watchUsageText };
735
737
  export type { AssertionCounts, AssertionResultStatus, CodeFrameOptions, CommandLineOptions, ConfigFileOptions, DiagnosticsHandler, DirectiveRange, EnvironmentOptions, Event, EventHandler, FileCounts, FileResultStatus, InlineConfig, ItemDefinition, OptionDefinition, Plugin, Reporter, ReporterEvent, ResolvedConfig, ResultCounts, ResultTiming, ScribblerOptions, SelectHookContext, SuppressedCounts, SuppressedResultStatus, TargetCounts, TargetResultStatus, TestCounts, TestResultStatus, TextRange };
package/build/tstyche.js CHANGED
@@ -968,7 +968,7 @@ class Store {
968
968
  modulePath = Path.resolve(modulePath, "../tsserverlibrary.js");
969
969
  }
970
970
  const sourceText = await fs.readFile(modulePath, { encoding: "utf8" });
971
- const toExpose = ["isApplicableIndexType", "isTypeIdenticalTo"];
971
+ const toExpose = ["isTypeIdenticalTo"];
972
972
  const modifiedSourceText = sourceText.replace("return checker;", `return { ...checker, ${toExpose.join(", ")} };`);
973
973
  const compiledWrapper = vm.compileFunction(modifiedSourceText, ["exports", "require", "module", "__filename", "__dirname"], { filename: modulePath });
974
974
  compiledWrapper(exports, createRequire(modulePath), module, modulePath, Path.dirname(modulePath));
@@ -2491,6 +2491,10 @@ class OutputService {
2491
2491
  }
2492
2492
  }
2493
2493
 
2494
+ function prologueText(runnerVersion, rootPath) {
2495
+ return (jsx(Text, { children: [jsx(Line, { children: [jsx(Text, { color: "90", children: "····" }), " TSTyche ", runnerVersion, jsx(Text, { color: "90", children: [" at ", rootPath] })] }), jsx(Line, {})] }));
2496
+ }
2497
+
2494
2498
  function RowText({ label, text }) {
2495
2499
  return (jsx(Line, { children: [`${label}:`.padEnd(12), text] }));
2496
2500
  }
@@ -3305,6 +3309,7 @@ class AbilityLayer {
3305
3309
  const expectExpressionEnd = expect.node.expression.getEnd();
3306
3310
  const expectEnd = expect.node.getEnd();
3307
3311
  const matcherNameEnd = expect.matcherNameNode.getEnd();
3312
+ const matcherNodeEnd = expect.matcherNode.getEnd();
3308
3313
  switch (expect.matcherNameNode.name.text) {
3309
3314
  case "toBeApplicable":
3310
3315
  this.#nodes.push(expect);
@@ -3344,18 +3349,71 @@ class AbilityLayer {
3344
3349
  }
3345
3350
  break;
3346
3351
  }
3347
- case "toBeConstructableWith":
3352
+ case "toBeConstructableWith": {
3348
3353
  this.#nodes.push(expect);
3349
- this.#editor.eraseTrailingComma(expect.source);
3350
- this.#editor.replaceRanges([
3351
- [
3352
- expectStart,
3353
- expectExpressionEnd,
3354
- nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode) ? "; new" : "new",
3355
- ],
3356
- [expectEnd, matcherNameEnd],
3357
- ]);
3354
+ const sourceNode = expect.source[0];
3355
+ if (!sourceNode) {
3356
+ return;
3357
+ }
3358
+ if (nodeBelongsToArgumentList(this.#compiler, sourceNode)) {
3359
+ this.#editor.eraseTrailingComma(expect.source);
3360
+ this.#editor.replaceRanges([
3361
+ [
3362
+ expectStart,
3363
+ expectExpressionEnd,
3364
+ nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode) ? "; new" : "new",
3365
+ ],
3366
+ [expectEnd, matcherNameEnd],
3367
+ ]);
3368
+ }
3369
+ else {
3370
+ const sourceText = sourceNode.getFullText();
3371
+ this.#editor.replaceRanges([
3372
+ [
3373
+ expectStart,
3374
+ matcherNameEnd,
3375
+ nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode)
3376
+ ? `;new (undefined as any as ${sourceText})`
3377
+ : `new (undefined as any as ${sourceText})`,
3378
+ ],
3379
+ ]);
3380
+ }
3358
3381
  break;
3382
+ }
3383
+ case "toHaveProperty": {
3384
+ this.#nodes.push(expect);
3385
+ const sourceNode = expect.source[0];
3386
+ const targetNode = expect.target?.[0];
3387
+ if (!sourceNode || !targetNode) {
3388
+ return;
3389
+ }
3390
+ const sourceText = sourceNode.getFullText();
3391
+ const targetText = targetNode.getFullText();
3392
+ if (nodeBelongsToArgumentList(this.#compiler, sourceNode)) {
3393
+ this.#editor.eraseTrailingComma(expect.source);
3394
+ this.#editor.replaceRanges([
3395
+ [
3396
+ expectStart,
3397
+ matcherNodeEnd,
3398
+ nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode)
3399
+ ? `;(${sourceText})[${targetText}]`
3400
+ : `(${sourceText})[${targetText}]`,
3401
+ ],
3402
+ ]);
3403
+ }
3404
+ else {
3405
+ this.#editor.replaceRanges([
3406
+ [
3407
+ expectStart,
3408
+ matcherNodeEnd,
3409
+ nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode)
3410
+ ? `;(undefined as any as ${sourceText})[${targetText}]`
3411
+ : `(undefined as any as ${sourceText})[${targetText}]`,
3412
+ ],
3413
+ ]);
3414
+ }
3415
+ break;
3416
+ }
3359
3417
  }
3360
3418
  }
3361
3419
  visitWhen(when) {
@@ -4303,19 +4361,6 @@ class MatchWorker {
4303
4361
  this.typeChecker = typeChecker;
4304
4362
  this.assertionNode = assertionNode;
4305
4363
  }
4306
- checkHasApplicableIndexType(sourceNode, targetNode) {
4307
- const sourceType = this.getType(sourceNode);
4308
- const targetType = this.getType(targetNode);
4309
- return this.typeChecker
4310
- .getIndexInfosOfType(sourceType)
4311
- .some(({ keyType }) => this.typeChecker.isApplicableIndexType(targetType, keyType));
4312
- }
4313
- checkHasProperty(sourceNode, propertyNameText) {
4314
- const sourceType = this.getType(sourceNode);
4315
- return sourceType
4316
- .getProperties()
4317
- .some((property) => this.#compiler.unescapeLeadingUnderscores(property.escapedName) === propertyNameText);
4318
- }
4319
4364
  checkIsAssignableTo(sourceNode, targetNode) {
4320
4365
  return this.#checkIsRelatedTo(sourceNode, targetNode, "assignable");
4321
4366
  }
@@ -4771,16 +4816,8 @@ class ToBeConstructableWith extends AbilityMatcherBase {
4771
4816
  explainText = ExpectDiagnosticText.isConstructable;
4772
4817
  explainNotText = ExpectDiagnosticText.isNotConstructable;
4773
4818
  match(matchWorker, sourceNode, targetNodes, onDiagnostics) {
4774
- let type;
4775
- if (this.compiler.isCallExpression(sourceNode)) {
4776
- type = matchWorker.typeChecker.getResolvedSignature(sourceNode)?.getReturnType();
4777
- }
4778
- if (this.compiler.isExpressionWithTypeArguments(sourceNode) ||
4779
- this.compiler.isIdentifier(sourceNode) ||
4780
- this.compiler.isPropertyAccessExpression(sourceNode)) {
4781
- type = matchWorker.getType(sourceNode);
4782
- }
4783
- if (!type || type.getConstructSignatures().length === 0) {
4819
+ const sourceType = matchWorker.getType(sourceNode);
4820
+ if (sourceType.getConstructSignatures().length === 0) {
4784
4821
  const text = [];
4785
4822
  if (nodeBelongsToArgumentList(this.compiler, sourceNode)) {
4786
4823
  text.push(ExpectDiagnosticText.argumentMustBe("source", "a constructable expression"));
@@ -4788,7 +4825,7 @@ class ToBeConstructableWith extends AbilityMatcherBase {
4788
4825
  else {
4789
4826
  text.push(ExpectDiagnosticText.typeArgumentMustBe("Source", "a constructable type"));
4790
4827
  }
4791
- if (type != null && type.getCallSignatures().length > 0) {
4828
+ if (sourceType.getCallSignatures().length > 0) {
4792
4829
  text.push(ExpectDiagnosticText.didYouMeanToUse("the '.toBeCallableWith()' matcher"));
4793
4830
  }
4794
4831
  const origin = DiagnosticOrigin.fromNode(sourceNode);
@@ -4835,14 +4872,7 @@ class ToHaveProperty {
4835
4872
  diagnostics.push(Diagnostic.error(text, origin));
4836
4873
  }
4837
4874
  const targetType = matchWorker.getType(targetNode);
4838
- let propertyNameText = "";
4839
- if (isStringOrNumberLiteralType(this.#compiler, targetType)) {
4840
- propertyNameText = targetType.value.toString();
4841
- }
4842
- else if (isUniqueSymbolType(this.#compiler, targetType)) {
4843
- propertyNameText = this.#compiler.unescapeLeadingUnderscores(targetType.escapedName);
4844
- }
4845
- else {
4875
+ if (!(isStringOrNumberLiteralType(this.#compiler, targetType) || isUniqueSymbolType(this.#compiler, targetType))) {
4846
4876
  const expectedText = "of type 'string | number | symbol'";
4847
4877
  const text = ExpectDiagnosticText.argumentMustBe("key", expectedText);
4848
4878
  const origin = DiagnosticOrigin.fromNode(targetNode);
@@ -4852,11 +4882,9 @@ class ToHaveProperty {
4852
4882
  onDiagnostics(diagnostics);
4853
4883
  return;
4854
4884
  }
4855
- const isMatch = matchWorker.checkHasProperty(sourceNode, propertyNameText) ||
4856
- matchWorker.checkHasApplicableIndexType(sourceNode, targetNode);
4857
4885
  return {
4858
4886
  explain: () => this.#explain(matchWorker, sourceNode, targetNode),
4859
- isMatch,
4887
+ isMatch: matchWorker.assertionNode.abilityDiagnostics.size === 0,
4860
4888
  };
4861
4889
  }
4862
4890
  }
@@ -5241,7 +5269,7 @@ class TestTreeWalker {
5241
5269
  }
5242
5270
  const fixmeDirective = Directive.getDirectiveRange(this.#compiler, node, "fixme");
5243
5271
  if (fixmeDirective) {
5244
- FixmeService.start(fixmeDirective, node);
5272
+ await FixmeService.start(fixmeDirective, node);
5245
5273
  }
5246
5274
  switch (node.brand) {
5247
5275
  case "describe":
@@ -5454,7 +5482,7 @@ class FileRunner {
5454
5482
  class Runner {
5455
5483
  #eventEmitter = new EventEmitter();
5456
5484
  #resolvedConfig;
5457
- static version = "5.0.0-beta.2";
5485
+ static version = "5.0.0-beta.3";
5458
5486
  constructor(resolvedConfig) {
5459
5487
  this.#resolvedConfig = resolvedConfig;
5460
5488
  }
@@ -5492,6 +5520,9 @@ class Runner {
5492
5520
  }
5493
5521
  }
5494
5522
  async run(files, cancellationToken = new CancellationToken()) {
5523
+ if (!this.#resolvedConfig.watch) {
5524
+ OutputService.writeMessage(prologueText(Runner.version, this.#resolvedConfig.rootPath));
5525
+ }
5495
5526
  const fileLocations = files.map((file) => (file instanceof FileLocation ? file : new FileLocation(file)));
5496
5527
  this.#addHandlers(cancellationToken);
5497
5528
  await this.#addReporters();
@@ -5654,4 +5685,4 @@ class Cli {
5654
5685
  }
5655
5686
  }
5656
5687
 
5657
- export { BaseReporter, CancellationReason, CancellationToken, Cli, Color, Config, ConfigDiagnosticText, DescribeResult, Diagnostic, DiagnosticCategory, DiagnosticOrigin, Directive, EventEmitter, ExpectResult, FileLocation, FileResult, Line, ListReporter, OptionBrand, OptionGroup, Options, OutputService, Path, PluginService, ProjectResult, Result, ResultStatus, Runner, Scribbler, Select, SelectDiagnosticText, SetupReporter, Store, SummaryReporter, SuppressedResult, TargetResult, TestResult, Text, Version, WatchReporter, addsPackageText, defaultOptions, describeNameText, diagnosticBelongsToNode, diagnosticText, environmentOptions, fileStatusText, fileViewText, formattedText, getDiagnosticMessageText, getTextSpanEnd, helpText, isDiagnosticWithLocation, summaryText, testNameText, usesCompilerText, waitingForFileChangesText, watchUsageText };
5688
+ export { BaseReporter, CancellationReason, CancellationToken, Cli, Color, Config, ConfigDiagnosticText, DescribeResult, Diagnostic, DiagnosticCategory, DiagnosticOrigin, Directive, EventEmitter, ExpectResult, FileLocation, FileResult, Line, ListReporter, OptionBrand, OptionGroup, Options, OutputService, Path, PluginService, ProjectResult, Result, ResultStatus, Runner, Scribbler, Select, SelectDiagnosticText, SetupReporter, Store, SummaryReporter, SuppressedResult, TargetResult, TestResult, Text, Version, WatchReporter, addsPackageText, defaultOptions, describeNameText, diagnosticBelongsToNode, diagnosticText, environmentOptions, fileStatusText, fileViewText, formattedText, getDiagnosticMessageText, getTextSpanEnd, helpText, isDiagnosticWithLocation, prologueText, summaryText, testNameText, usesCompilerText, waitingForFileChangesText, watchUsageText };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tstyche",
3
- "version": "5.0.0-beta.2",
3
+ "version": "5.0.0-beta.3",
4
4
  "description": "Everything You Need for Type Testing.",
5
5
  "keywords": [
6
6
  "typescript",