@augment-vir/test 30.8.2 → 30.8.4
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
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
A universal testing suite that works with Mocha style test runners _and_ Node.js's built-in test runner with the following main exports:
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
5
|
+
- [`describe`](https://electrovir.github.io/augment-vir/functions/describe.html): the normal describe test suite function, automatically imported based on the current environment.
|
|
6
|
+
- [`it`](https://electrovir.github.io/augment-vir/functions/it.html): the normal it test function, automatically imported based on the current environment.
|
|
7
|
+
- [`itCases`](https://electrovir.github.io/augment-vir/functions/itCases.html): a succinct way to test lots of inputs and outputs to a single function.
|
|
8
|
+
- [`testWeb`](https://electrovir.github.io/augment-vir/variables/testWeb.html): a API of web-testing utilities, only available in browser environments.
|
|
9
9
|
|
|
10
10
|
See the docs under `Test`, or `Package: @augment-vir/test` here: https://electrovir.github.io/augment-vir
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { check } from '@augment-vir/assert';
|
|
2
|
-
import { extractErrorMessage,
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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.savedSnapshot}\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
|
-
|
|
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
|
-
|
|
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?:
|
|
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.
|
|
3
|
+
"version": "30.8.4",
|
|
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,14 +42,14 @@
|
|
|
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.
|
|
46
|
-
"@augment-vir/common": "^30.8.
|
|
45
|
+
"@augment-vir/assert": "^30.8.4",
|
|
46
|
+
"@augment-vir/common": "^30.8.4",
|
|
47
47
|
"@open-wc/testing-helpers": "^3.0.1",
|
|
48
|
-
"@virmator/test": "^13.
|
|
49
|
-
"type-fest": "^4.
|
|
48
|
+
"@virmator/test": "^13.10.3",
|
|
49
|
+
"type-fest": "^4.29.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@types/node": "^22.
|
|
52
|
+
"@types/node": "^22.10.0",
|
|
53
53
|
"@web/dev-server-esbuild": "^1.0.3",
|
|
54
54
|
"@web/test-runner": "^0.19.0",
|
|
55
55
|
"@web/test-runner-commands": "^0.9.0",
|