tstyche 3.0.0-beta.2 → 3.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.
package/README.md CHANGED
@@ -56,7 +56,7 @@ test("handles numbers", () => {
56
56
 
57
57
  Here is the list of all matchers:
58
58
 
59
- - `.toBe()`, `.toBeAssignableTo()`, `.toBeAssignableWith()`, `.toMatch()` compare types or types of expression,
59
+ - `.toBe()`, `.toBeAssignableTo()`, `.toBeAssignableWith()` compare types or types of expression,
60
60
  - `.toAcceptProps()` checks types of JSX component's props,
61
61
  - `.toHaveProperty()` looks up keys on an object type,
62
62
  - `.toRaiseError()` captures the type error message or code,
package/build/index.cjs CHANGED
@@ -14,4 +14,6 @@ const noopChain = new Proxy(doNothing, {
14
14
  exports.describe = noopChain;
15
15
  exports.expect = noopChain;
16
16
  exports.it = noopChain;
17
+ exports.omit = doNothing;
18
+ exports.pick = doNothing;
17
19
  exports.test = noopChain;
package/build/index.d.cts CHANGED
@@ -97,28 +97,6 @@ interface Matchers {
97
97
  */
98
98
  (target: unknown): void;
99
99
  };
100
- /**
101
- * Checks if the source type is assignable with the target type.
102
- *
103
- * @deprecated Use `.toBeAssignableWith()` or `.toBeAssignableTo()` instead. This matcher will be removed in TSTyche 3.
104
- * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
105
- */
106
- toBeAssignable: {
107
- /**
108
- * Checks if the source type is assignable with the target type.
109
- *
110
- * @deprecated Use `.toBeAssignableWith()` or `.toBeAssignableTo()` instead. This matcher will be removed in TSTyche 3.
111
- * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
112
- */
113
- <Target>(): void;
114
- /**
115
- * Checks if the source type is assignable with type of the target expression.
116
- *
117
- * @deprecated Use `.toBeAssignableWith()` or `.toBeAssignableTo()` instead. This matcher will be removed in TSTyche 3.
118
- * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
119
- */
120
- (target: unknown): void;
121
- };
122
100
  /**
123
101
  * Checks if the source type is assignable to the target type.
124
102
  */
@@ -145,42 +123,26 @@ interface Matchers {
145
123
  */
146
124
  (target: unknown): void;
147
125
  };
148
- /**
149
- * Checks if the source type is identical to the target type.
150
- *
151
- * @deprecated Use `.toBe()` instead. This matcher will be removed in TSTyche 3.
152
- * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
153
- */
154
- toEqual: {
155
- /**
156
- * Checks if the source type is identical to the target type.
157
- *
158
- * @deprecated Use `.toBe()` instead. This matcher will be removed in TSTyche 3.
159
- * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
160
- */
161
- <Target>(): void;
162
- /**
163
- * Checks if the source type is identical to type of the target expression.
164
- *
165
- * @deprecated This matcher will be removed in TSTyche 3.
166
- * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
167
- */
168
- (target: unknown): void;
169
- };
170
126
  /**
171
127
  * Checks if a property key exists on the source type.
172
128
  */
173
129
  toHaveProperty: (key: string | number | symbol) => void;
174
130
  /**
175
131
  * Checks if the source type matches the target type.
132
+ *
133
+ * @deprecated This matcher will be removed in TSTyche 4. To learn more, visit https://tstyche.org/release-notes/tstyche-3.
176
134
  */
177
135
  toMatch: {
178
136
  /**
179
137
  * Checks if the source type matches the target type.
138
+ *
139
+ * @deprecated This matcher will be removed in TSTyche 4. To learn more, visit https://tstyche.org/release-notes/tstyche-3.
180
140
  */
181
141
  <Target>(): void;
182
142
  /**
183
143
  * Checks if the source type matches type of the target expression.
144
+ *
145
+ * @deprecated This matcher will be removed in TSTyche 4. To learn more, visit https://tstyche.org/release-notes/tstyche-3.
184
146
  */
185
147
  (target: unknown): void;
186
148
  };
@@ -340,6 +302,18 @@ interface Expect {
340
302
  };
341
303
  };
342
304
  }
305
+ /**
306
+ * Builds an assertion.
307
+ */
308
+ declare const expect: Expect;
309
+ /**
310
+ * Reshapes type of the given object by removing the specified keys.
311
+ */
312
+ declare function omit<T, K extends PropertyKey>(object: T, ...keys: [K, ...Array<K>]): Omit<T, K>;
313
+ /**
314
+ * Reshapes type of the given object by keeping only the specified keys.
315
+ */
316
+ declare function pick<T, K extends keyof T>(object: T, ...keys: [K, ...Array<K>]): Pick<T, K>;
343
317
  /**
344
318
  * Defines a test group.
345
319
  */
@@ -352,9 +326,5 @@ declare const test: Test;
352
326
  * Defines a single test.
353
327
  */
354
328
  declare const it: Test;
355
- /**
356
- * Builds an assertion.
357
- */
358
- declare const expect: Expect;
359
329
 
360
- export { describe, expect, it, test };
330
+ export { describe, expect, it, omit, pick, test };
package/build/index.d.ts CHANGED
@@ -97,28 +97,6 @@ interface Matchers {
97
97
  */
98
98
  (target: unknown): void;
99
99
  };
100
- /**
101
- * Checks if the source type is assignable with the target type.
102
- *
103
- * @deprecated Use `.toBeAssignableWith()` or `.toBeAssignableTo()` instead. This matcher will be removed in TSTyche 3.
104
- * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
105
- */
106
- toBeAssignable: {
107
- /**
108
- * Checks if the source type is assignable with the target type.
109
- *
110
- * @deprecated Use `.toBeAssignableWith()` or `.toBeAssignableTo()` instead. This matcher will be removed in TSTyche 3.
111
- * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
112
- */
113
- <Target>(): void;
114
- /**
115
- * Checks if the source type is assignable with type of the target expression.
116
- *
117
- * @deprecated Use `.toBeAssignableWith()` or `.toBeAssignableTo()` instead. This matcher will be removed in TSTyche 3.
118
- * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
119
- */
120
- (target: unknown): void;
121
- };
122
100
  /**
123
101
  * Checks if the source type is assignable to the target type.
124
102
  */
@@ -145,42 +123,26 @@ interface Matchers {
145
123
  */
146
124
  (target: unknown): void;
147
125
  };
148
- /**
149
- * Checks if the source type is identical to the target type.
150
- *
151
- * @deprecated Use `.toBe()` instead. This matcher will be removed in TSTyche 3.
152
- * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
153
- */
154
- toEqual: {
155
- /**
156
- * Checks if the source type is identical to the target type.
157
- *
158
- * @deprecated Use `.toBe()` instead. This matcher will be removed in TSTyche 3.
159
- * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
160
- */
161
- <Target>(): void;
162
- /**
163
- * Checks if the source type is identical to type of the target expression.
164
- *
165
- * @deprecated This matcher will be removed in TSTyche 3.
166
- * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
167
- */
168
- (target: unknown): void;
169
- };
170
126
  /**
171
127
  * Checks if a property key exists on the source type.
172
128
  */
173
129
  toHaveProperty: (key: string | number | symbol) => void;
174
130
  /**
175
131
  * Checks if the source type matches the target type.
132
+ *
133
+ * @deprecated This matcher will be removed in TSTyche 4. To learn more, visit https://tstyche.org/release-notes/tstyche-3.
176
134
  */
177
135
  toMatch: {
178
136
  /**
179
137
  * Checks if the source type matches the target type.
138
+ *
139
+ * @deprecated This matcher will be removed in TSTyche 4. To learn more, visit https://tstyche.org/release-notes/tstyche-3.
180
140
  */
181
141
  <Target>(): void;
182
142
  /**
183
143
  * Checks if the source type matches type of the target expression.
144
+ *
145
+ * @deprecated This matcher will be removed in TSTyche 4. To learn more, visit https://tstyche.org/release-notes/tstyche-3.
184
146
  */
185
147
  (target: unknown): void;
186
148
  };
@@ -340,6 +302,18 @@ interface Expect {
340
302
  };
341
303
  };
342
304
  }
305
+ /**
306
+ * Builds an assertion.
307
+ */
308
+ declare const expect: Expect;
309
+ /**
310
+ * Reshapes type of the given object by removing the specified keys.
311
+ */
312
+ declare function omit<T, K extends PropertyKey>(object: T, ...keys: [K, ...Array<K>]): Omit<T, K>;
313
+ /**
314
+ * Reshapes type of the given object by keeping only the specified keys.
315
+ */
316
+ declare function pick<T, K extends keyof T>(object: T, ...keys: [K, ...Array<K>]): Pick<T, K>;
343
317
  /**
344
318
  * Defines a test group.
345
319
  */
@@ -352,9 +326,5 @@ declare const test: Test;
352
326
  * Defines a single test.
353
327
  */
354
328
  declare const it: Test;
355
- /**
356
- * Builds an assertion.
357
- */
358
- declare const expect: Expect;
359
329
 
360
- export { describe, expect, it, test };
330
+ export { describe, expect, it, omit, pick, test };
package/build/index.js CHANGED
@@ -9,4 +9,4 @@ const noopChain = new Proxy(doNothing, {
9
9
  },
10
10
  });
11
11
 
12
- export { noopChain as describe, noopChain as expect, noopChain as it, noopChain as test };
12
+ export { noopChain as describe, noopChain as expect, noopChain as it, doNothing as omit, doNothing as pick, noopChain as test };
@@ -539,6 +539,8 @@ declare class Cli {
539
539
 
540
540
  type Event = ["config:error", {
541
541
  diagnostics: Array<Diagnostic>;
542
+ }] | ["deprecation:info", {
543
+ diagnostics: Array<Diagnostic>;
542
544
  }] | ["select:error", {
543
545
  diagnostics: Array<Diagnostic>;
544
546
  }] | ["run:start", {
@@ -665,6 +667,7 @@ declare class ExpectDiagnosticText {
665
667
  static argumentMustBeProvided(argumentNameText: string): string;
666
668
  static componentAcceptsProps(isTypeNode: boolean): string;
667
669
  static componentDoesNotAcceptProps(isTypeNode: boolean): string;
670
+ static matcherIsDeprecated(matcherNameText: string): Array<string>;
668
671
  static matcherIsNotSupported(matcherNameText: string): string;
669
672
  static overloadGaveTheFollowingError(index: number, count: number, signatureText: string): string;
670
673
  static raisedTypeError(count?: number): string;
package/build/tstyche.js CHANGED
@@ -481,11 +481,11 @@ class Path {
481
481
  return Path.normalizeSlashes(path.join(...filePaths));
482
482
  }
483
483
  static relative(from, to) {
484
- let relativePath = path.relative(from, to);
485
- if (!relativePath.startsWith("./")) {
486
- relativePath = `./${relativePath}`;
484
+ const relativePath = Path.normalizeSlashes(path.relative(from, to));
485
+ if (/^\.\.?\//.test(relativePath)) {
486
+ return relativePath;
487
487
  }
488
- return Path.normalizeSlashes(relativePath);
488
+ return `./${relativePath}`;
489
489
  }
490
490
  static resolve(...filePaths) {
491
491
  return Path.normalizeSlashes(path.resolve(...filePaths));
@@ -1251,18 +1251,28 @@ class JsonScanner {
1251
1251
  }
1252
1252
  read() {
1253
1253
  this.#skipTrivia();
1254
- if (/[:\]}]/.test(this.#peekCharacter())) {
1254
+ this.#previousPosition = this.#currentPosition;
1255
+ if (/[\s,:\]}]/.test(this.#peekCharacter())) {
1255
1256
  return new JsonNode(undefined, this.#getOrigin());
1256
1257
  }
1257
- let quoteCharacter = "";
1258
1258
  let text = "";
1259
- this.#previousPosition = this.#currentPosition;
1260
- if (/['"]/.test(this.#peekCharacter())) {
1261
- quoteCharacter = text += this.#readCharacter();
1259
+ let closingTokenText = "";
1260
+ if (/[[{'"]/.test(this.#peekCharacter())) {
1261
+ text += this.#readCharacter();
1262
+ switch (text) {
1263
+ case "[":
1264
+ closingTokenText = "]";
1265
+ break;
1266
+ case "{":
1267
+ closingTokenText = "}";
1268
+ break;
1269
+ default:
1270
+ closingTokenText = text;
1271
+ }
1262
1272
  }
1263
1273
  while (!this.isRead()) {
1264
1274
  text += this.#readCharacter();
1265
- if (text.slice(-1) === quoteCharacter || (!quoteCharacter && /[\s,:\]}]/.test(this.#peekCharacter()))) {
1275
+ if (text.slice(-1) === closingTokenText || (!closingTokenText && /[\s,:\]}]/.test(this.#peekCharacter()))) {
1266
1276
  break;
1267
1277
  }
1268
1278
  }
@@ -1280,35 +1290,6 @@ class JsonScanner {
1280
1290
  }
1281
1291
  return new JsonNode(undefined, this.#getOrigin());
1282
1292
  }
1283
- skip() {
1284
- this.#skipTrivia();
1285
- this.#previousPosition = this.#currentPosition;
1286
- if (/[\s,:\]}]/.test(this.#peekCharacter())) {
1287
- return new JsonNode(undefined, this.#getOrigin());
1288
- }
1289
- let text = "";
1290
- let closingCharacter = "";
1291
- if (/[[{'"]/.test(this.#peekCharacter())) {
1292
- text += this.#readCharacter();
1293
- switch (text) {
1294
- case "[":
1295
- closingCharacter = "]";
1296
- break;
1297
- case "{":
1298
- closingCharacter = "}";
1299
- break;
1300
- default:
1301
- closingCharacter = text;
1302
- }
1303
- }
1304
- while (!this.isRead()) {
1305
- text += this.#readCharacter();
1306
- if (text.slice(-1) === closingCharacter || (!closingCharacter && /[\s,:\]}]/.test(this.#peekCharacter()))) {
1307
- break;
1308
- }
1309
- }
1310
- return new JsonNode(text, this.#getOrigin());
1311
- }
1312
1293
  #skipTrivia() {
1313
1294
  while (!this.isRead()) {
1314
1295
  if (/\s/.test(this.#peekCharacter())) {
@@ -1396,7 +1377,7 @@ class ConfigFileOptionsWorker {
1396
1377
  case "list": {
1397
1378
  const leftBracketToken = this.#jsonScanner.readToken("[");
1398
1379
  if (!leftBracketToken.text) {
1399
- jsonNode = this.#jsonScanner.skip();
1380
+ jsonNode = this.#jsonScanner.read();
1400
1381
  this.#onRequiresValue(optionDefinition, jsonNode, isListItem);
1401
1382
  break;
1402
1383
  }
@@ -1454,7 +1435,7 @@ class ConfigFileOptionsWorker {
1454
1435
  const text = ConfigDiagnosticText.unknownOption(optionName);
1455
1436
  this.#onDiagnostics(Diagnostic.error(text, optionNameNode.origin));
1456
1437
  if (this.#jsonScanner.readToken(":")) {
1457
- this.#jsonScanner.skip();
1438
+ this.#jsonScanner.read();
1458
1439
  }
1459
1440
  const commaToken = this.#jsonScanner.readToken(",");
1460
1441
  if (!commaToken.text) {
@@ -1723,6 +1704,7 @@ class RunReporter extends Reporter {
1723
1704
  #hasReportedError = false;
1724
1705
  #isFileViewExpanded = false;
1725
1706
  #resolvedConfig;
1707
+ #seenDeprecations = new Set();
1726
1708
  constructor(resolvedConfig, outputService) {
1727
1709
  super(outputService);
1728
1710
  this.#resolvedConfig = resolvedConfig;
@@ -1732,6 +1714,15 @@ class RunReporter extends Reporter {
1732
1714
  }
1733
1715
  handleEvent([eventName, payload]) {
1734
1716
  switch (eventName) {
1717
+ case "deprecation:info": {
1718
+ for (const diagnostic of payload.diagnostics) {
1719
+ if (!this.#seenDeprecations.has(diagnostic.text.toString())) {
1720
+ this.#fileView.addMessage(diagnosticText(diagnostic));
1721
+ this.#seenDeprecations.add(diagnostic.text.toString());
1722
+ }
1723
+ }
1724
+ break;
1725
+ }
1735
1726
  case "run:start":
1736
1727
  this.#isFileViewExpanded = payload.result.tasks.length === 1 && this.#resolvedConfig.watch !== true;
1737
1728
  break;
@@ -1790,6 +1781,7 @@ class RunReporter extends Reporter {
1790
1781
  this.#hasReportedError = true;
1791
1782
  }
1792
1783
  this.#fileView.clear();
1784
+ this.#seenDeprecations.clear();
1793
1785
  break;
1794
1786
  case "describe:start":
1795
1787
  if (this.#isFileViewExpanded) {
@@ -2656,6 +2648,12 @@ class ExpectDiagnosticText {
2656
2648
  static componentDoesNotAcceptProps(isTypeNode) {
2657
2649
  return `${isTypeNode ? "Component type" : "Component"} does not accept props of the given type.`;
2658
2650
  }
2651
+ static matcherIsDeprecated(matcherNameText) {
2652
+ return [
2653
+ `The '.${matcherNameText}()' matcher is deprecated and will be removed in TSTyche 4.`,
2654
+ "To learn more, visit https://tstyche.org/releases/tstyche-3",
2655
+ ];
2656
+ }
2659
2657
  static matcherIsNotSupported(matcherNameText) {
2660
2658
  return `The '.${matcherNameText}()' matcher is not supported.`;
2661
2659
  }
@@ -3270,6 +3268,11 @@ class ExpectService {
3270
3268
  }
3271
3269
  match(assertion, onDiagnostics) {
3272
3270
  const matcherNameText = assertion.matcherName.getText();
3271
+ if (matcherNameText === "toMatch") {
3272
+ const text = ExpectDiagnosticText.matcherIsDeprecated(matcherNameText);
3273
+ const origin = DiagnosticOrigin.fromNode(assertion.matcherName);
3274
+ EventEmitter.dispatch(["deprecation:info", { diagnostics: [Diagnostic.warning(text, origin)] }]);
3275
+ }
3273
3276
  if (!assertion.source[0]) {
3274
3277
  this.#onSourceArgumentOrTypeArgumentMustBeProvided(assertion, onDiagnostics);
3275
3278
  return;
@@ -3615,7 +3618,7 @@ class TSTyche {
3615
3618
  #runner;
3616
3619
  #selectService;
3617
3620
  #storeService;
3618
- static version = "3.0.0-beta.2";
3621
+ static version = "3.0.0-beta.3";
3619
3622
  constructor(resolvedConfig, outputService, selectService, storeService) {
3620
3623
  this.#resolvedConfig = resolvedConfig;
3621
3624
  this.#outputService = outputService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tstyche",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-beta.3",
4
4
  "description": "The Essential Type Testing Tool.",
5
5
  "keywords": [
6
6
  "typescript",