@everyonesoftware/common 6.0.0 → 8.0.0

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.
@@ -1,4 +1,4 @@
1
- import { S as SyncResult, P as PromiseAsyncResult, k as Type, I as Iterable, f as JavascriptIterable, C as CharacterWriteStream } from './characterWriteStream-DUlG_bx_.js';
1
+ import { f as JavascriptIterable, S as SyncResult, P as PromiseAsyncResult, k as Type, I as Iterable, A as AsyncResult, C as CharacterWriteStream } from './characterWriteStream-ogvZec-U.js';
2
2
 
3
3
  /**
4
4
  * A type that can be used to make assertions during a test.
@@ -61,6 +61,12 @@ declare abstract class Test {
61
61
  * @param value The value to check.
62
62
  */
63
63
  static assertNotUndefinedAndNotNull<T>(test: Test, value: T): asserts value is NonNullable<T>;
64
+ /**
65
+ * Assert that the provided collection is not undefined, not null, and not empty.
66
+ * @param value The value to check.
67
+ */
68
+ assertNotEmpty(value: JavascriptIterable<unknown>): void;
69
+ static assertNotEmpty(test: Test, value: JavascriptIterable<unknown>): void;
64
70
  /**
65
71
  * Assert that the provided values point to the same object.
66
72
  * @param left The first value.
@@ -91,10 +97,6 @@ declare abstract class Test {
91
97
  * @param value The value to check.
92
98
  */
93
99
  assertFalse(value: boolean): asserts value is false;
94
- /**
95
- * Assert that the provided value is false.
96
- * @param value The value to check.
97
- */
98
100
  static assertFalse(test: Test, value: boolean): asserts value is false;
99
101
  /**
100
102
  * Assert that the provided value is true.
@@ -142,18 +144,18 @@ declare abstract class Test {
142
144
  * A {@link Test} type that uses the standard "assert" module to make assertions.
143
145
  */
144
146
  declare class AssertTest implements Test {
145
- private readonly name;
146
- protected constructor(name: string);
147
+ private constructor();
147
148
  /**
148
149
  * Create a new {@link AssertTest} object.
149
150
  */
150
- static create(name: string): AssertTest;
151
+ static create(): AssertTest;
151
152
  fail(message: string): never;
152
153
  assertUndefined(value: unknown): asserts value is undefined;
153
154
  assertNotUndefined<T>(value: T): asserts value is NonNullable<T>;
154
155
  assertNull(value: unknown): asserts value is null;
155
156
  assertNotNull<T>(value: T): asserts value is NonNullable<T>;
156
157
  assertNotUndefinedAndNotNull<T>(value: T): asserts value is NonNullable<T>;
158
+ assertNotEmpty(value: JavascriptIterable<unknown>): void;
157
159
  assertSame<T>(left: T, right: T): void;
158
160
  assertNotSame<T>(left: T, right: T): void;
159
161
  assertEqual<T>(left: T, right: T, message?: string): void;
@@ -228,61 +230,44 @@ declare abstract class TestRunner {
228
230
  * @param message The message that explains why the tests are being skipped.
229
231
  */
230
232
  static skip(_runner: TestRunner, shouldSkip?: boolean, message?: string): TestSkip;
231
- static runTestAction(runner: TestRunner, name: string, skip: TestSkip | undefined, testAction: (() => void) | ((test: Test) => void)): void;
232
233
  /**
233
234
  * Create a test group that will test the provided file.
234
235
  * @param fileName The name of the file that is being tested.
235
236
  * @param testAction The action that will run the tests.
236
237
  */
237
- testFile(fileName: string, testAction: (() => void) | ((test: Test) => void)): void;
238
+ abstract testFile(fileName: string, testAction: (() => void) | ((test: Test) => void)): void;
238
239
  /**
239
240
  * Create a test group that will test the provided file.
240
241
  * @param fileName The name of the file that is being tested.
241
242
  * @param skip A value that indicates whether these tests should be skipped.
242
243
  * @param testAction The action that will run the tests.
243
244
  */
244
- testFile(fileName: string, skip: TestSkip | undefined, testAction: (() => void) | ((test: Test) => void)): void;
245
- /**
246
- * Create a test group that will test the provided file.
247
- * @param runner The {@link TestRunner} that will run the tests.
248
- * @param fileName The name of the file that is being tested.
249
- * @param testAction The action that will run the tests.
250
- */
251
- static testFile(runner: TestRunner, fileName: string, skipOrTestAction: TestSkip | ((() => void) | ((test: Test) => void)) | undefined, testAction?: (() => void) | ((test: Test) => void)): void;
245
+ abstract testFile(fileName: string, skip: TestSkip | undefined, testAction: (() => void) | ((test: Test) => void)): void;
252
246
  /**
253
247
  * Create a test group that will test the provided type.
254
248
  * @param type The {@link Type} or name of the type that is being tested.
255
249
  * @param testAction The action that will run the tests.
256
250
  */
257
- testType(typeNameOrType: string | Type<unknown>, testAction: (() => void) | ((test: Test) => void)): void;
251
+ abstract testType(typeNameOrType: string | Type<unknown>, testAction: (() => void) | ((test: Test) => void)): void;
258
252
  /**
259
253
  * Create a test group that will test the provided type.
260
254
  * @param type The {@link Type} or name of the type that is being tested.
261
255
  * @param skip A value that indicates whether these tests should be skipped.
262
256
  * @param testAction The action that will run the tests.
263
257
  */
264
- testType(typeNameOrType: string | Type<unknown>, skip: TestSkip | undefined, testAction: (() => void) | ((test: Test) => void)): void;
265
- /**
266
- * Create a test group that will test the provided type.
267
- * @param runner The {@link TestRunner} that will run the tests.
268
- * @param type The {@link Type} or name of the type that is being tested.
269
- * @param testAction The action that will run the tests.
270
- */
271
- static testType(runner: TestRunner, typeNameOrType: string | Type<unknown>, skipOrTestAction: TestSkip | undefined | ((() => void) | ((test: Test) => void)), testAction: ((() => void) | ((test: Test) => void)) | undefined): void;
258
+ abstract testType(typeNameOrType: string | Type<unknown>, skip: TestSkip | undefined, testAction: (() => void) | ((test: Test) => void)): void;
272
259
  /**
273
260
  * Create a test group that will test the provided function.
274
261
  * @param functionSignature The signature of the function that is being tested.
275
262
  * @param testAction The action that will run the tests.
276
263
  */
277
- testFunction(functionSignature: string, testAction: (() => void) | ((test: Test) => void)): void;
278
- testFunction(functionSignature: string, skip: TestSkip | undefined, testAction: (() => void) | ((test: Test) => void)): void;
264
+ abstract testFunction(functionSignature: string, testAction: (() => void) | ((test: Test) => void)): void;
279
265
  /**
280
266
  * Create a test group that will test the provided function.
281
- * @param runner The {@link TestRunner} that will run the tests.
282
267
  * @param functionSignature The signature of the function that is being tested.
283
268
  * @param testAction The action that will run the tests.
284
269
  */
285
- static testFunction(runner: TestRunner, functionSignature: string, skipOrTestAction: TestSkip | undefined | ((() => void) | ((test: Test) => void)), testAction: ((() => void) | ((test: Test) => void)) | undefined): void;
270
+ abstract testFunction(functionSignature: string, skip: TestSkip | undefined, testAction: (() => void) | ((test: Test) => void)): void;
286
271
  /**
287
272
  * Create and run a test group with the provided name.
288
273
  * @param testGroupName The name of the test group to run.
@@ -330,71 +315,167 @@ declare class BasicTestSkip implements TestSkip {
330
315
  getMessage(): string;
331
316
  }
332
317
 
333
- declare class FailedTest {
334
- private readonly fullTestNameParts;
335
- private readonly error;
336
- private constructor();
337
- static create(fullTestNameParts: JavascriptIterable<string>, error: unknown): FailedTest;
338
- getFullTestNameParts(): JavascriptIterable<string>;
339
- getFullTestName(): string;
340
- getError(): unknown;
341
- getErrorMessage(): string;
342
- }
343
-
344
- declare class SkippedTest {
345
- private readonly skip;
346
- private readonly fullTestNameParts;
347
- private constructor();
348
- static create(skip: TestSkip, fullTestNameParts: JavascriptIterable<string>): SkippedTest;
349
- getSkipMessage(): string;
350
- getFullTestNameParts(): JavascriptIterable<string>;
351
- getFullTestName(): string;
352
- }
353
-
318
+ type TestActionType = "file" | "type" | "function" | "group" | "test";
354
319
  declare class TestAction {
355
320
  private readonly parent;
356
321
  private readonly name;
322
+ private readonly type;
357
323
  private readonly skip;
358
324
  private readonly action;
359
325
  private constructor();
360
- static create(parent: TestAction | undefined, name: string, skip: TestSkip | undefined, action: () => (void | Promise<void>)): TestAction;
326
+ static create(parent: TestAction | undefined, name: string, type: TestActionType, skip: TestSkip | undefined, action: () => (void | Promise<void>)): TestAction;
361
327
  getParent(): TestAction | undefined;
362
328
  getName(): string;
363
329
  getFullNameParts(): JavascriptIterable<string>;
364
330
  getFullName(): string;
331
+ getType(): TestActionType;
365
332
  getSkip(): TestSkip | undefined;
366
333
  shouldSkip(): boolean;
367
334
  getAction(): () => (void | Promise<void>);
368
335
  runAsync(): void | Promise<void>;
369
336
  }
370
337
 
338
+ /**
339
+ * Options that can be passed to {@link TestError.getErrorString()}.
340
+ */
341
+ interface GetErrorStringOptions {
342
+ /**
343
+ * Whether all of the file paths in the stack trace should be shortened to be relative to the
344
+ * current directory.
345
+ */
346
+ readonly relativeFilePaths?: boolean;
347
+ /**
348
+ * Remove any stack frames from code that is not part of the current project.
349
+ */
350
+ readonly removeNonProjectPaths?: boolean;
351
+ }
352
+ declare abstract class TestError {
353
+ protected constructor();
354
+ /**
355
+ * Get the error that caused the test or test group to fail.
356
+ */
357
+ abstract getError(): unknown;
358
+ /**
359
+ * Get the string representation of the error.
360
+ */
361
+ abstract getErrorString(options?: GetErrorStringOptions): string;
362
+ }
363
+
364
+ declare class FailedTest {
365
+ private readonly testAction;
366
+ private readonly error;
367
+ private constructor();
368
+ static create(testAction: TestAction, error: TestError): FailedTest;
369
+ getTestAction(): TestAction;
370
+ getTestError(): TestError;
371
+ }
372
+
373
+ declare class SkippedTest {
374
+ private readonly skip;
375
+ private readonly testAction;
376
+ private constructor();
377
+ static create(skip: TestSkip, testAction: TestAction): SkippedTest;
378
+ getSkipMessage(): string;
379
+ getTestAction(): TestAction;
380
+ }
381
+
382
+ type ConsoleTestRunnerStyle = TestActionType | "passed" | "skipped" | "failed";
383
+ declare abstract class ConsoleTestRunnerUI {
384
+ private writeStream?;
385
+ private readonly styles;
386
+ private getErrorStringOptions?;
387
+ protected constructor();
388
+ static flat(): FlatConsoleTestRunnerUI;
389
+ static tree(): TreeConsoleTestRunnerUI;
390
+ setWriteStream(writeStream: CharacterWriteStream): this;
391
+ setStyle(style: ConsoleTestRunnerStyle, styleFunction: (text: string) => string): this;
392
+ setStyles(styles: Partial<Record<ConsoleTestRunnerStyle, (text: string) => string>>): this;
393
+ private applyStyle;
394
+ protected addIndentation(): void;
395
+ protected removeIndentation(): void;
396
+ protected indent(action: () => number | void | PromiseLike<number | void>): AsyncResult<number>;
397
+ protected writeString(text: string): AsyncResult<number>;
398
+ protected writeLine(text?: string): AsyncResult<number>;
399
+ protected writeTestActionName(testAction: TestAction): AsyncResult<number>;
400
+ protected writeFullTestActionName(testAction: TestAction): AsyncResult<number>;
401
+ setGetErrorStringOptions(options: GetErrorStringOptions | undefined): this;
402
+ beforeTestGroup(testGroup: TestAction): AsyncResult<void>;
403
+ afterTestGroup(testGroup: TestAction): AsyncResult<void>;
404
+ beforeTest(testAction: TestAction): AsyncResult<void>;
405
+ afterPassedTest(testAction: TestAction): AsyncResult<void>;
406
+ afterSkippedTest(testAction: TestAction, skip: TestSkip): AsyncResult<void>;
407
+ afterFailedTest(currentTestAction: TestAction, error: TestError): AsyncResult<void>;
408
+ writeSummary(passedTestCount: number, skippedTests: Iterable<SkippedTest>, failedTests: Iterable<FailedTest>): AsyncResult<void>;
409
+ }
410
+ declare class FlatConsoleTestRunnerUI extends ConsoleTestRunnerUI {
411
+ protected constructor();
412
+ static create(): FlatConsoleTestRunnerUI;
413
+ beforeTest(testAction: TestAction): AsyncResult<void>;
414
+ }
415
+ declare class TreeConsoleTestRunnerUI extends ConsoleTestRunnerUI {
416
+ private testActions;
417
+ private testActionWrittenDepth;
418
+ protected constructor();
419
+ static create(): TreeConsoleTestRunnerUI;
420
+ beforeTestGroup(testGroup: TestAction): AsyncResult<void>;
421
+ afterTestGroup(testGroup: TestAction): AsyncResult<void>;
422
+ beforeTest(testAction: TestAction): AsyncResult<void>;
423
+ }
424
+
425
+ /**
426
+ * A type that can create new {@link Test} objects.
427
+ */
428
+ declare abstract class TestCreator {
429
+ /**
430
+ * Create the default {@link TestCreator}.
431
+ */
432
+ static create(): TestCreator;
433
+ /**
434
+ * Create a new {@link Test} object.
435
+ */
436
+ abstract createTest(): Test;
437
+ }
438
+
439
+ declare abstract class TestErrorCreator {
440
+ static create(): TestErrorCreator;
441
+ abstract createTestError(error: unknown): TestError;
442
+ }
443
+
371
444
  type ConsoleTestFunction = (runner: ConsoleTestRunner) => (void | Promise<void>);
372
445
  type ConsoleTestFunctionContainer = {
373
446
  test: ConsoleTestFunction;
374
447
  };
375
- declare class ConsoleTestRunner extends TestRunner {
448
+ declare class ConsoleTestRunner implements TestRunner {
376
449
  private writeStream;
377
- private readonly pendingActions;
378
- private pendingActionsInsertIndex;
450
+ private readonly testActions;
451
+ private testActionInsertIndex;
379
452
  private currentTestAction;
380
453
  private currentTest;
381
454
  private passedTestCount;
382
455
  private readonly skippedTests;
383
456
  private readonly testFailures;
384
- constructor();
385
- static create(): ConsoleTestRunner;
457
+ private readonly testCreator;
458
+ private readonly testErrorCreator;
459
+ private readonly ui;
460
+ constructor(testCreator?: TestCreator, testErrorCreator?: TestErrorCreator, ui?: ConsoleTestRunnerUI);
461
+ static create(testCreator?: TestCreator, testErrorCreator?: TestErrorCreator, ui?: ConsoleTestRunnerUI): ConsoleTestRunner;
386
462
  static run(testFunction: ConsoleTestFunction | ConsoleTestFunctionContainer): Promise<void>;
387
463
  static run(testFunctions: JavascriptIterable<ConsoleTestFunction | ConsoleTestFunctionContainer>): Promise<void>;
388
464
  setWriteStream(writeStream: CharacterWriteStream): this;
465
+ setStyle(style: ConsoleTestRunnerStyle, styleFunction: (text: string) => string): this;
466
+ setStyles(styles: Partial<Record<ConsoleTestRunnerStyle, (text: string) => string>>): this;
467
+ setGetErrorStringOptions(options: GetErrorStringOptions): this;
389
468
  /**
390
469
  * Get the number of {@link TestAction}s that have yet to be executed.
391
470
  */
392
- getPendingTestActionsCount(): number;
471
+ getTestActionCount(): number;
393
472
  /**
394
- * Get the index in the pending-{@link TestAction} stack that new {@link TestAction}s will be
473
+ * Get the index in the {@link TestAction} list that new {@link TestAction}s will be
395
474
  * inserted at.
396
475
  */
397
- getPendingTestActionsInsertIndex(): number;
476
+ getTestActionInsertIndex(): number;
477
+ private resetTestActionInsertIndex;
478
+ private insertTestAction;
398
479
  /**
399
480
  * Get the number of tests that have been skipped.
400
481
  */
@@ -413,16 +494,31 @@ declare class ConsoleTestRunner extends TestRunner {
413
494
  getCurrentTestAction(): TestAction | undefined;
414
495
  getCurrentTest(): Test | undefined;
415
496
  private assertNoCurrentTest;
416
- beforeTest(fullTestNameParts: JavascriptIterable<string>): PromiseAsyncResult<void>;
417
- afterPassedTest(): PromiseAsyncResult<void>;
418
- afterSkippedTest(fullTestNameParts: JavascriptIterable<string>, skip: TestSkip | undefined): PromiseAsyncResult<void>;
419
- afterFailedTest(fullTestNameParts: JavascriptIterable<string>, error: unknown): PromiseAsyncResult<void>;
497
+ beforeTestGroup(testAction: TestAction): AsyncResult<void>;
498
+ afterTestGroup(testAction: TestAction): AsyncResult<void>;
499
+ beforeTest(testAction: TestAction): AsyncResult<void>;
500
+ afterPassedTest(testAction: TestAction): AsyncResult<void>;
501
+ afterSkippedTest(testAction: TestAction, skip: TestSkip): AsyncResult<void>;
502
+ afterFailedTest(testAction: TestAction, error: TestError): AsyncResult<void>;
503
+ andList(values: unknown[] | Iterable<unknown>): string;
504
+ toString(value: unknown): string;
505
+ skip(message?: string): TestSkip;
506
+ skip(shouldSkip: boolean, message?: string): TestSkip;
507
+ testFile(fileName: string, testAction: (() => void) | ((test: Test) => void)): void;
508
+ testFile(fileName: string, skip: TestSkip | undefined, testAction: (() => void) | ((test: Test) => void)): void;
509
+ testType(typeNameOrType: string | Type<unknown>, testAction: (() => void) | ((test: Test) => void)): void;
510
+ testType(typeNameOrType: string | Type<unknown>, skip: TestSkip | undefined, testAction: (() => void) | ((test: Test) => void)): void;
511
+ testFunction(functionSignature: string, testAction: (() => void) | ((test: Test) => void)): void;
512
+ testFunction(functionSignature: string, skip: TestSkip | undefined, testAction: (() => void) | ((test: Test) => void)): void;
420
513
  testGroup(testGroupName: string, testAction: () => (void | Promise<void>)): void;
421
514
  testGroup(testGroupName: string, skip: TestSkip | undefined, testAction: () => (void | Promise<void>)): void;
422
515
  test(testName: string, testAction: (test: Test) => (void | Promise<void>)): void;
423
516
  test(testName: string, skip: TestSkip | undefined, testAction: (test: Test) => (void | Promise<void>)): void;
517
+ private innerTestGroup;
518
+ private innerTest;
519
+ private testGroupOrTest;
424
520
  runAsync(): Promise<void>;
425
- printSummary(): PromiseAsyncResult<void>;
521
+ printSummary(): AsyncResult<void>;
426
522
  }
427
523
 
428
- export { AssertTest, BasicTestSkip, type ConsoleTestFunction, type ConsoleTestFunctionContainer, ConsoleTestRunner, FailedTest, SkippedTest, Test, TestAction, TestRunner, TestSkip, test };
524
+ export { AssertTest, BasicTestSkip, type ConsoleTestFunction, type ConsoleTestFunctionContainer, ConsoleTestRunner, FailedTest, SkippedTest, Test, TestAction, type TestActionType, TestRunner, TestSkip, test };
@@ -9,8 +9,8 @@ import {
9
9
  TestRunner,
10
10
  TestSkip,
11
11
  test
12
- } from "./chunk-CHBOMCYM.js";
13
- import "./chunk-5Z677JON.js";
12
+ } from "./chunk-FEQPKLDH.js";
13
+ import "./chunk-OYMWB5SX.js";
14
14
  export {
15
15
  AssertTest,
16
16
  BasicTestSkip,