@augment-vir/test 30.8.1 → 30.8.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.
@@ -72,5 +72,7 @@ export type MochaTestContext = Readonly<{
72
72
  test: MochaTest;
73
73
  }> & {
74
74
  /** Added for use by `assertSnapshot`. */
75
- snapshotCount?: number;
75
+ snapshotCount?: {
76
+ [TestName in string]: number;
77
+ };
76
78
  };
@@ -1,5 +1,5 @@
1
1
  import { check } from '@augment-vir/assert';
2
- import { extractErrorMessage, log, RuntimeEnv } from '@augment-vir/common';
2
+ import { extractErrorMessage, getOrSet, RuntimeEnv } from '@augment-vir/common';
3
3
  import { isTestContext } from './universal-test-context.js';
4
4
  /**
5
5
  * An error that is thrown from {@link assertSnapshot} when the snapshot comparison fails due to the
@@ -31,9 +31,6 @@ export async function assertSnapshot(testContext, data) {
31
31
  const serializedData = check.isString(data) ? data : JSON.stringify(data);
32
32
  if (isTestContext(testContext, RuntimeEnv.Node)) {
33
33
  try {
34
- testContext.snapshotCount = testContext.snapshotCount
35
- ? testContext.snapshotCount + 1
36
- : 1;
37
34
  testContext.assert.snapshot(serializedData);
38
35
  }
39
36
  catch (error) {
@@ -52,14 +49,13 @@ export async function assertSnapshot(testContext, data) {
52
49
  content: serializedData,
53
50
  name: snapshotName,
54
51
  });
55
- if (result.updated) {
56
- log.info(`Snapshot updated at '${result.snapshotPath}'`);
57
- }
58
- else if (!result.exists) {
59
- throw new SnapshotFileMissingError(testName);
60
- }
61
- else if (!result.matches) {
62
- throw new Error(`Snapshot mismatch at '${testName}':\n\nActual: ${serializedData}\n\nExpected: ${result.savedContent}\n`);
52
+ if (!result.updated) {
53
+ if (!result.exists) {
54
+ throw new SnapshotFileMissingError(testName);
55
+ }
56
+ else if (!result.matches) {
57
+ throw new Error(`Snapshot mismatch at '${testName}':\n\nActual: ${serializedData}\n\nExpected: ${result.savedContent}\n`);
58
+ }
63
59
  }
64
60
  }
65
61
  }
@@ -78,10 +74,15 @@ function getTestName(testContext) {
78
74
  const testName = isTestContext(testContext, RuntimeEnv.Node)
79
75
  ? testContext.fullName
80
76
  : flattenMochaParentTitles(testContext.test).join(' > ');
81
- testContext.snapshotCount = testContext.snapshotCount ? testContext.snapshotCount + 1 : 1;
77
+ const snapshotCountObject = getOrSet(testContext, 'snapshotCount', () => {
78
+ return {};
79
+ });
80
+ const currentSnapshotCount = getOrSet(snapshotCountObject, testName, () => 0);
81
+ const newSnapshotCount = currentSnapshotCount + 1;
82
+ snapshotCountObject[testName] = newSnapshotCount;
82
83
  const snapshotName = [
83
84
  testName,
84
- testContext.snapshotCount,
85
+ newSnapshotCount,
85
86
  ].join(' ');
86
87
  return {
87
88
  snapshotName,
@@ -10,7 +10,9 @@ import { MochaTestContext } from './mocha-types.js';
10
10
  */
11
11
  export type NodeTestContext = Readonly<NodeTestContextImport> & {
12
12
  /** Added for use by `assertSnapshot`. */
13
- snapshotCount?: number;
13
+ snapshotCount?: {
14
+ [TestName in string]: number;
15
+ };
14
16
  };
15
17
  /**
16
18
  * Test context provided by `it`'s callback.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/test",
3
- "version": "30.8.1",
3
+ "version": "30.8.3",
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",
@@ -42,8 +42,8 @@
42
42
  "test:web": "virmator test --no-deps web 'src/test-web/**/*.test.ts' 'src/augments/universal-testing-suite/**/*.test.ts'"
43
43
  },
44
44
  "dependencies": {
45
- "@augment-vir/assert": "^30.8.1",
46
- "@augment-vir/common": "^30.8.1",
45
+ "@augment-vir/assert": "^30.8.3",
46
+ "@augment-vir/common": "^30.8.3",
47
47
  "@open-wc/testing-helpers": "^3.0.1",
48
48
  "@virmator/test": "^13.8.0",
49
49
  "type-fest": "^4.26.1"