@augment-vir/test 31.55.0 → 31.57.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,18 @@
1
+ import { type AnyFunction } from '@augment-vir/core';
1
2
  import { type BaseFunctionWithContext, type FunctionWithContextTestCase } from './it-cases-with-context.js';
3
+ /**
4
+ * Test case for {@link snapshotCasesWithContext}.
5
+ *
6
+ * @category Test
7
+ * @category Package : @augment-vir/test
8
+ */
9
+ export type SnapshotTestCaseWithContext<FunctionToTest extends AnyFunction> = Omit<FunctionWithContextTestCase<NoInfer<FunctionToTest>>, 'expect' | 'throws'> & {
10
+ /**
11
+ * If true, allows errors to be thrown and snapshotted. Otherwise thrown errors will fail the
12
+ * test.
13
+ */
14
+ fails?: boolean;
15
+ };
2
16
  /**
3
17
  * Same as `snapshotCases` but passes the test context as the first parameter to the function under
4
18
  * test.
@@ -52,4 +66,4 @@ import { type BaseFunctionWithContext, type FunctionWithContextTestCase } from '
52
66
  *
53
67
  * @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
54
68
  */
55
- export declare function snapshotCasesWithContext<const FunctionToTest extends BaseFunctionWithContext>(this: void, functionToTest: FunctionToTest, testCases: ReadonlyArray<Omit<FunctionWithContextTestCase<NoInfer<FunctionToTest>>, 'expect' | 'throws'>>): void[];
69
+ export declare function snapshotCasesWithContext<const FunctionToTest extends BaseFunctionWithContext>(this: void, functionToTest: FunctionToTest, testCases: ReadonlyArray<SnapshotTestCaseWithContext<NoInfer<FunctionToTest>>>): void[];
@@ -69,11 +69,16 @@ export function snapshotCasesWithContext(functionToTest, testCases) {
69
69
  return await functionToTest(testContext, ...functionInputs);
70
70
  }, {
71
71
  handleError(caught) {
72
- const error = ensureError(caught);
73
- const errorClassName = error.constructor.name;
74
- return {
75
- [errorClassName]: extractErrorMessage(error),
76
- };
72
+ if (testCase.fails) {
73
+ const error = ensureError(caught);
74
+ const errorClassName = error.constructor.name;
75
+ return {
76
+ [errorClassName]: extractErrorMessage(error),
77
+ };
78
+ }
79
+ else {
80
+ throw caught;
81
+ }
77
82
  },
78
83
  });
79
84
  await assertSnapshot(testContext, snapshotData);
@@ -1,5 +1,18 @@
1
1
  import { type AnyFunction } from '@augment-vir/core';
2
2
  import { type FunctionTestCase } from './it-cases.js';
3
+ /**
4
+ * Test case for {@link snapshotCases}.
5
+ *
6
+ * @category Test
7
+ * @category Package : @augment-vir/test
8
+ */
9
+ export type SnapshotTestCase<FunctionToTest extends AnyFunction> = Omit<FunctionTestCase<NoInfer<FunctionToTest>>, 'expect' | 'throws'> & {
10
+ /**
11
+ * If true, allows errors to be thrown and snapshotted. Otherwise thrown errors will fail the
12
+ * test.
13
+ */
14
+ fails?: boolean;
15
+ };
3
16
  /**
4
17
  * Similar to `itCases` but instead of defining expectation in each test case, each test case is a
5
18
  * snapshot test.
@@ -46,4 +59,4 @@ import { type FunctionTestCase } from './it-cases.js';
46
59
  *
47
60
  * @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
48
61
  */
49
- export declare function snapshotCases<const FunctionToTest extends AnyFunction>(this: void, functionToTest: FunctionToTest, testCases: ReadonlyArray<Omit<FunctionTestCase<NoInfer<FunctionToTest>>, 'expect' | 'throws'>>): void[];
62
+ export declare function snapshotCases<const FunctionToTest extends AnyFunction>(this: void, functionToTest: FunctionToTest, testCases: ReadonlyArray<SnapshotTestCase<NoInfer<FunctionToTest>>>): void[];
@@ -62,11 +62,16 @@ export function snapshotCases(functionToTest, testCases) {
62
62
  return await functionToTest(...functionInputs);
63
63
  }, {
64
64
  handleError(caught) {
65
- const error = ensureError(caught);
66
- const errorClassName = error.constructor.name;
67
- return {
68
- [errorClassName]: extractErrorMessage(error),
69
- };
65
+ if (testCase.fails) {
66
+ const error = ensureError(caught);
67
+ const errorClassName = error.constructor.name;
68
+ return {
69
+ [errorClassName]: extractErrorMessage(error),
70
+ };
71
+ }
72
+ else {
73
+ throw caught;
74
+ }
70
75
  },
71
76
  });
72
77
  await assertSnapshot(testContext, snapshotData);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/test",
3
- "version": "31.55.0",
3
+ "version": "31.57.0",
4
4
  "description": "A universal testing suite that works with Mocha style test runners _and_ Node.js's built-in test runner.",
5
5
  "keywords": [
6
6
  "test",
@@ -44,8 +44,8 @@
44
44
  "test:web": "virmator test --no-deps web 'src/test-web/**/*.test.ts' 'src/augments/universal-testing-suite/**/*.test.ts'"
45
45
  },
46
46
  "dependencies": {
47
- "@augment-vir/assert": "^31.55.0",
48
- "@augment-vir/common": "^31.55.0",
47
+ "@augment-vir/assert": "^31.57.0",
48
+ "@augment-vir/common": "^31.57.0",
49
49
  "@date-vir/duration": "^8.1.0",
50
50
  "@virmator/test": "^14.3.5",
51
51
  "type-fest": "^5.3.1"