vest 5.0.0-dev-781e21 → 5.0.2-dev-d315d9
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/LICENSE +2 -2
- package/README.md +2 -57
- package/dist/cjs/classnames.development.js +18 -16
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/enforce/compose.development.js +5 -54
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/enforce/compounds.development.js +20 -83
- package/dist/cjs/enforce/compounds.production.js +1 -1
- package/dist/cjs/enforce/schema.development.js +19 -82
- package/dist/cjs/enforce/schema.production.js +1 -1
- package/dist/cjs/parser.development.js +12 -9
- package/dist/cjs/parser.production.js +1 -1
- package/dist/cjs/promisify.development.js +4 -8
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/vest.development.js +1287 -1153
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +20 -18
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/enforce/compose.development.js +1 -58
- package/dist/es/enforce/compose.production.js +1 -1
- package/dist/es/enforce/compounds.development.js +2 -90
- package/dist/es/enforce/compounds.production.js +1 -1
- package/dist/es/enforce/schema.development.js +2 -88
- package/dist/es/enforce/schema.production.js +1 -1
- package/dist/es/parser.development.js +12 -9
- package/dist/es/parser.production.js +1 -1
- package/dist/es/promisify.development.js +5 -9
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +1286 -1148
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +21 -19
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +9 -57
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +32 -94
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +32 -94
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +16 -13
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/promisify.development.js +7 -11
- package/dist/umd/promisify.production.js +1 -1
- package/dist/umd/vest.development.js +1289 -1155
- package/dist/umd/vest.production.js +1 -1
- package/package.json +12 -16
- package/src/__tests__/__snapshots__/integration.async-tests.test.ts.snap +71 -0
- package/src/__tests__/__snapshots__/integration.base.test.ts.snap +71 -0
- package/src/__tests__/__snapshots__/integration.stateful-async.test.ts.snap +243 -0
- package/src/__tests__/__snapshots__/integration.stateful-tests.test.ts.snap +376 -0
- package/src/__tests__/integration.async-tests.test.ts +90 -0
- package/src/__tests__/integration.base.test.ts +45 -0
- package/src/__tests__/integration.exclusive.test.ts +88 -0
- package/src/__tests__/integration.stateful-async.test.ts +137 -0
- package/src/__tests__/integration.stateful-tests.test.ts +155 -0
- package/src/__tests__/isolate.test.ts +288 -0
- package/src/__tests__/state_refill.test.ts +41 -0
- package/src/core/SuiteWalker/SuiteWalker.ts +64 -0
- package/src/core/SuiteWalker/__tests__/hasRemainingTests.test.ts +130 -0
- package/src/core/VestBus/VestBus.ts +78 -0
- package/src/core/context/PersistedContext.ts +243 -0
- package/src/core/context/SuiteContext.ts +74 -0
- package/src/core/isolate/IsolateTest/IsolateTest.ts +213 -0
- package/src/core/isolate/IsolateTest/IsolateTestReconciler.ts +156 -0
- package/src/core/isolate/IsolateTest/IsolateTestStateMachine.ts +69 -0
- package/src/core/isolate/IsolateTest/SimpleStateMachine.ts +43 -0
- package/src/core/isolate/IsolateTest/TestWalker.ts +77 -0
- package/src/core/isolate/IsolateTypes.ts +10 -0
- package/src/core/isolate/isIsolate.ts +6 -0
- package/src/core/isolate/isolate.ts +110 -0
- package/src/core/isolate/reconciler/Reconciler/Reconciler.ts +123 -0
- package/src/core/isolate/reconciler/cancelOverriddenPendingTest.ts +15 -0
- package/src/core/isolate/reconciler/isSameProfileTest.ts +12 -0
- package/src/core/isolate/walker.ts +127 -0
- package/src/core/test/TestTypes.ts +3 -0
- package/src/core/test/__tests__/IsolateTest.test.ts +152 -0
- package/src/core/test/__tests__/__snapshots__/IsolateTest.test.ts.snap +39 -0
- package/src/core/test/__tests__/__snapshots__/memo.test.ts.snap +101 -0
- package/src/core/test/__tests__/__snapshots__/test.test.ts.snap +231 -0
- package/src/core/test/__tests__/key.test.ts +195 -0
- package/src/core/test/__tests__/memo.test.ts +218 -0
- package/src/core/test/__tests__/merging_of_previous_test_runs.test.ts +341 -0
- package/src/core/test/__tests__/runAsyncTest.test.ts +175 -0
- package/src/core/test/__tests__/test.test.ts +226 -0
- package/src/core/test/helpers/__tests__/nonMatchingSeverityProfile.test.ts +52 -0
- package/src/core/test/helpers/asVestTest.ts +9 -0
- package/src/core/test/helpers/matchingFieldName.ts +16 -0
- package/src/core/test/helpers/matchingGroupName.ts +12 -0
- package/src/core/test/helpers/nonMatchingSeverityProfile.ts +14 -0
- package/src/core/test/helpers/shouldUseErrorMessage.ts +9 -0
- package/src/core/test/test.memo.ts +81 -0
- package/src/core/test/test.ts +64 -0
- package/src/core/test/testLevelFlowControl/runTest.ts +86 -0
- package/src/core/test/testLevelFlowControl/verifyTestRun.ts +32 -0
- package/src/core/test/testObjectIsolate.ts +11 -0
- package/src/errors/ErrorStrings.ts +4 -0
- package/src/exports/__tests__/classnames.test.ts +92 -0
- package/src/exports/__tests__/parser.test.ts +441 -0
- package/src/exports/__tests__/promisify.test.ts +77 -0
- package/src/exports/classnames.ts +35 -0
- package/src/exports/enforce@compose.ts +1 -0
- package/src/exports/enforce@compounds.ts +1 -0
- package/src/exports/enforce@schema.ts +1 -0
- package/src/exports/parser.ts +63 -0
- package/src/exports/promisify.ts +18 -0
- package/src/hooks/__tests__/__snapshots__/include.test.ts.snap +794 -0
- package/src/hooks/__tests__/eager.test.ts +130 -0
- package/src/hooks/__tests__/exclusive.test.ts +578 -0
- package/src/hooks/__tests__/include.test.ts +431 -0
- package/src/hooks/__tests__/optional.test.ts +83 -0
- package/src/hooks/__tests__/warn.test.ts +42 -0
- package/src/hooks/exclusive.ts +179 -0
- package/src/hooks/include.ts +54 -0
- package/src/hooks/mode.ts +47 -0
- package/src/hooks/optional/OptionalTypes.ts +31 -0
- package/src/hooks/optional/optional.ts +69 -0
- package/src/hooks/warn.ts +19 -0
- package/src/isolates/__tests__/__snapshots__/each.test.ts.snap +3 -0
- package/src/isolates/__tests__/__snapshots__/group.test.ts.snap +114 -0
- package/src/isolates/__tests__/__snapshots__/omitWhen.test.ts.snap +443 -0
- package/src/isolates/__tests__/__snapshots__/skipWhen.test.ts.snap +99 -0
- package/src/isolates/__tests__/each.test.ts +35 -0
- package/src/isolates/__tests__/group.test.ts +362 -0
- package/src/isolates/__tests__/omitWhen.test.ts +246 -0
- package/src/isolates/__tests__/skipWhen.test.ts +163 -0
- package/src/isolates/each.ts +30 -0
- package/src/isolates/group.ts +9 -0
- package/src/isolates/omitWhen.ts +41 -0
- package/src/isolates/skipWhen.ts +42 -0
- package/src/suite/__tests__/__snapshots__/create.test.ts.snap +67 -0
- package/src/suite/__tests__/create.test.ts +109 -0
- package/src/suite/__tests__/remove.test.ts +50 -0
- package/src/suite/__tests__/resetField.test.ts +74 -0
- package/src/suite/createSuite.ts +94 -0
- package/src/suite/runCallbacks.ts +28 -0
- package/src/suiteResult/Severity.ts +15 -0
- package/src/suiteResult/SuiteResultTypes.ts +42 -0
- package/src/suiteResult/__tests__/done.test.ts +334 -0
- package/src/suiteResult/__tests__/produce.test.ts +163 -0
- package/src/suiteResult/done/deferDoneCallback.ts +28 -0
- package/src/suiteResult/done/shouldSkipDoneRegistration.ts +20 -0
- package/src/suiteResult/selectors/__tests__/__snapshots__/collectFailureMessages.test.ts.snap +89 -0
- package/src/suiteResult/selectors/__tests__/collectFailureMessages.test.ts +124 -0
- package/src/suiteResult/selectors/__tests__/getFailures.test.ts +158 -0
- package/src/suiteResult/selectors/__tests__/getFailuresByGroup.test.ts +199 -0
- package/src/suiteResult/selectors/__tests__/hasFailures.test.ts +141 -0
- package/src/suiteResult/selectors/__tests__/hasFailuresByGroup.test.ts +185 -0
- package/src/suiteResult/selectors/__tests__/hasFailuresByTestObject.test.ts +88 -0
- package/src/suiteResult/selectors/__tests__/isValid.test.ts +359 -0
- package/src/suiteResult/selectors/__tests__/isValidByGroup.test.ts +480 -0
- package/src/suiteResult/selectors/collectFailures.ts +43 -0
- package/src/suiteResult/selectors/hasFailuresByTestObjects.ts +62 -0
- package/src/suiteResult/selectors/produceSuiteSummary.ts +135 -0
- package/src/suiteResult/selectors/shouldAddValidProperty.ts +148 -0
- package/src/suiteResult/selectors/suiteSelectors.ts +199 -0
- package/src/suiteResult/suiteResult.ts +15 -0
- package/src/suiteResult/suiteRunResult.ts +43 -0
- package/src/vest.ts +36 -0
- package/testUtils/TVestMock.ts +5 -0
- package/testUtils/__tests__/partition.test.ts +4 -4
- package/testUtils/mockThrowError.ts +4 -2
- package/testUtils/suiteDummy.ts +2 -1
- package/testUtils/testDummy.ts +12 -10
- package/testUtils/testPromise.ts +3 -0
- package/tsconfig.json +84 -2
- package/types/classnames.d.ts +39 -4
- package/types/classnames.d.ts.map +1 -0
- package/types/enforce/compose.d.ts +2 -126
- package/types/enforce/compose.d.ts.map +1 -0
- package/types/enforce/compounds.d.ts +2 -136
- package/types/enforce/compounds.d.ts.map +1 -0
- package/types/enforce/schema.d.ts +2 -144
- package/types/enforce/schema.d.ts.map +1 -0
- package/types/parser.d.ts +45 -10
- package/types/parser.d.ts.map +1 -0
- package/types/promisify.d.ts +36 -34
- package/types/promisify.d.ts.map +1 -0
- package/types/vest.d.ts +169 -224
- package/types/vest.d.ts.map +1 -0
- package/CHANGELOG.md +0 -87
- package/testUtils/expandStateRef.ts +0 -8
- package/testUtils/runCreateRef.ts +0 -10
- package/testUtils/testObjects.ts +0 -6
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { CB, invariant, isNullish } from 'vest-utils';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useHistoryKey,
|
|
5
|
+
useSetIsolateKey,
|
|
6
|
+
useHistoryNode,
|
|
7
|
+
useIsolate,
|
|
8
|
+
useCurrentCursor,
|
|
9
|
+
PersistedContext,
|
|
10
|
+
useRuntimeRoot,
|
|
11
|
+
} from 'PersistedContext';
|
|
12
|
+
import type { Isolate } from 'isolate';
|
|
13
|
+
|
|
14
|
+
export class Reconciler {
|
|
15
|
+
static reconciler(
|
|
16
|
+
currentNode: Isolate,
|
|
17
|
+
historicNode: Isolate | null
|
|
18
|
+
): Isolate {
|
|
19
|
+
if (isNullish(historicNode)) {
|
|
20
|
+
return currentNode;
|
|
21
|
+
}
|
|
22
|
+
return currentNode;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static reconcile<Callback extends CB = CB>(
|
|
26
|
+
node: Isolate,
|
|
27
|
+
callback: Callback
|
|
28
|
+
): [Isolate, ReturnType<Callback>] {
|
|
29
|
+
const parent = useIsolate();
|
|
30
|
+
|
|
31
|
+
const historyNode = useHistoryNode();
|
|
32
|
+
let localHistoryNode = historyNode;
|
|
33
|
+
|
|
34
|
+
if (parent) {
|
|
35
|
+
// If we have a parent, we need to get the history node from the parent's children
|
|
36
|
+
// We take the history node from the cursor of the active node's children
|
|
37
|
+
localHistoryNode = historyNode?.at(useCurrentCursor()) ?? null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const nextNode = this.reconciler(node, localHistoryNode);
|
|
41
|
+
|
|
42
|
+
invariant(nextNode);
|
|
43
|
+
|
|
44
|
+
if (Object.is(nextNode, node)) {
|
|
45
|
+
return [node, runAsNew(localHistoryNode, node, callback)];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return [nextNode, nextNode.output];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static removeAllNextNodesInIsolate() {
|
|
52
|
+
const testIsolate = useIsolate();
|
|
53
|
+
const historyNode = useHistoryNode();
|
|
54
|
+
|
|
55
|
+
if (!historyNode || !testIsolate) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
historyNode.slice(useCurrentCursor());
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static handleCollision(newNode: Isolate, prevNode: Isolate): Isolate {
|
|
63
|
+
// we should base our calculation on the key property
|
|
64
|
+
if (newNode.usesKey()) {
|
|
65
|
+
return this.handleIsolateNodeWithKey(newNode);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (this.nodeReorderDetected(newNode, prevNode)) {
|
|
69
|
+
this.onNodeReorder(newNode, prevNode);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return prevNode ? prevNode : newNode;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static nodeReorderDetected(newNode: Isolate, prevNode: Isolate): boolean {
|
|
76
|
+
// This is a dummy return just to satisfy the linter. Overrides will supply the real implementation.
|
|
77
|
+
return !(newNode ?? prevNode);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static onNodeReorder(newNode: Isolate, prevNode: Isolate): Isolate {
|
|
81
|
+
this.removeAllNextNodesInIsolate();
|
|
82
|
+
// This is a dummy return just to satisfy the linter. Overrides will supply the real implementation.
|
|
83
|
+
return newNode ?? prevNode;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static handleIsolateNodeWithKey(node: Isolate): Isolate {
|
|
87
|
+
invariant(node.usesKey());
|
|
88
|
+
|
|
89
|
+
const prevNodeByKey = useHistoryKey(node.key);
|
|
90
|
+
|
|
91
|
+
let nextNode = node;
|
|
92
|
+
|
|
93
|
+
if (!isNullish(prevNodeByKey)) {
|
|
94
|
+
nextNode = prevNodeByKey;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
useSetIsolateKey(node.key, node);
|
|
98
|
+
|
|
99
|
+
return nextNode;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function runAsNew<Callback extends CB = CB>(
|
|
104
|
+
localHistoryNode: Isolate | null,
|
|
105
|
+
current: Isolate,
|
|
106
|
+
callback: CB
|
|
107
|
+
): ReturnType<Callback> {
|
|
108
|
+
const runtimeRoot = useRuntimeRoot();
|
|
109
|
+
|
|
110
|
+
// We're creating a new child isolate context where the local history node
|
|
111
|
+
// is the current history node, thus advancing the history cursor.
|
|
112
|
+
const output = PersistedContext.run(
|
|
113
|
+
{
|
|
114
|
+
historyNode: localHistoryNode,
|
|
115
|
+
runtimeNode: current,
|
|
116
|
+
...(!runtimeRoot && { runtimeRoot: current }),
|
|
117
|
+
},
|
|
118
|
+
() => callback(current)
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
current.output = output;
|
|
122
|
+
return output;
|
|
123
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IsolateTest } from 'IsolateTest';
|
|
2
|
+
import { isSameProfileTest } from 'isSameProfileTest';
|
|
3
|
+
|
|
4
|
+
export default function cancelOverriddenPendingTest(
|
|
5
|
+
prevRunTestObject: IsolateTest,
|
|
6
|
+
currentRunTestObject: IsolateTest
|
|
7
|
+
): void {
|
|
8
|
+
if (
|
|
9
|
+
currentRunTestObject !== prevRunTestObject &&
|
|
10
|
+
isSameProfileTest(prevRunTestObject, currentRunTestObject) &&
|
|
11
|
+
prevRunTestObject.isPending()
|
|
12
|
+
) {
|
|
13
|
+
prevRunTestObject.cancel();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IsolateTest } from 'IsolateTest';
|
|
2
|
+
|
|
3
|
+
export function isSameProfileTest(
|
|
4
|
+
testObject1: IsolateTest,
|
|
5
|
+
testObject2: IsolateTest
|
|
6
|
+
): boolean {
|
|
7
|
+
return (
|
|
8
|
+
testObject1.fieldName === testObject2.fieldName &&
|
|
9
|
+
testObject1.groupName === testObject2.groupName &&
|
|
10
|
+
testObject1.key === testObject2.key
|
|
11
|
+
);
|
|
12
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { isNullish, optionalFunctionValue } from 'vest-utils';
|
|
2
|
+
|
|
3
|
+
import type { Isolate } from 'isolate';
|
|
4
|
+
|
|
5
|
+
export type VisitOnlyPredicate = (isolate: Isolate) => boolean;
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line complexity, max-statements
|
|
8
|
+
export function walk(
|
|
9
|
+
startNode: Isolate,
|
|
10
|
+
callback: (isolate: Isolate, breakout: () => void) => void,
|
|
11
|
+
visitOnly?: VisitOnlyPredicate
|
|
12
|
+
): void {
|
|
13
|
+
if (isNullish(startNode.children)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let broke = false;
|
|
18
|
+
|
|
19
|
+
for (const isolate of startNode.children) {
|
|
20
|
+
if (broke) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (isNullish(visitOnly) || optionalFunctionValue(visitOnly, isolate)) {
|
|
25
|
+
callback(isolate, breakout);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (broke) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
walk(
|
|
33
|
+
isolate,
|
|
34
|
+
(child, innerBreakout) => {
|
|
35
|
+
callback(child, () => {
|
|
36
|
+
innerBreakout();
|
|
37
|
+
breakout();
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
visitOnly
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function breakout() {
|
|
45
|
+
broke = true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function some(
|
|
50
|
+
startNode: Isolate,
|
|
51
|
+
predicate: (node: Isolate) => boolean,
|
|
52
|
+
visitOnly?: VisitOnlyPredicate
|
|
53
|
+
): boolean {
|
|
54
|
+
let hasMatch = false;
|
|
55
|
+
walk(
|
|
56
|
+
startNode,
|
|
57
|
+
(node, breakout) => {
|
|
58
|
+
if (predicate(node)) {
|
|
59
|
+
breakout();
|
|
60
|
+
hasMatch = true;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
visitOnly
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return hasMatch;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function has(startNode: Isolate, match: VisitOnlyPredicate): boolean {
|
|
70
|
+
return some(startNode, () => true, match);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function find(
|
|
74
|
+
startNode: Isolate,
|
|
75
|
+
predicate: (node: Isolate) => boolean,
|
|
76
|
+
visitOnly?: VisitOnlyPredicate
|
|
77
|
+
): Isolate | null {
|
|
78
|
+
let found = null;
|
|
79
|
+
walk(
|
|
80
|
+
startNode,
|
|
81
|
+
(node, breakout) => {
|
|
82
|
+
if (predicate(node)) {
|
|
83
|
+
breakout();
|
|
84
|
+
found = node;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
visitOnly
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return found;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function every(
|
|
94
|
+
startNode: Isolate,
|
|
95
|
+
predicate: (node: Isolate) => boolean,
|
|
96
|
+
visitOnly?: VisitOnlyPredicate
|
|
97
|
+
): boolean {
|
|
98
|
+
let hasMatch = true;
|
|
99
|
+
walk(
|
|
100
|
+
startNode,
|
|
101
|
+
(node, breakout) => {
|
|
102
|
+
if (!predicate(node)) {
|
|
103
|
+
breakout();
|
|
104
|
+
hasMatch = false;
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
visitOnly
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
return hasMatch;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function pluck(
|
|
114
|
+
startNode: Isolate,
|
|
115
|
+
predicate: (node: Isolate) => boolean,
|
|
116
|
+
visitOnly?: VisitOnlyPredicate
|
|
117
|
+
): void {
|
|
118
|
+
walk(
|
|
119
|
+
startNode,
|
|
120
|
+
node => {
|
|
121
|
+
if (predicate(node) && node.parent) {
|
|
122
|
+
node.parent.removeChild(node);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
visitOnly
|
|
126
|
+
);
|
|
127
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import wait from 'wait';
|
|
2
|
+
|
|
3
|
+
import { TestPromise } from '../../../../testUtils/testPromise';
|
|
4
|
+
|
|
5
|
+
import { IsolateTest } from 'IsolateTest';
|
|
6
|
+
import { IsolateTypes } from 'IsolateTypes';
|
|
7
|
+
import * as vest from 'vest';
|
|
8
|
+
|
|
9
|
+
const fieldName = 'unicycle';
|
|
10
|
+
const message = 'I am Root.';
|
|
11
|
+
|
|
12
|
+
describe('IsolateTest', () => {
|
|
13
|
+
let testObject: IsolateTest;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
testObject = new IsolateTest(IsolateTypes.TEST, {
|
|
17
|
+
fieldName,
|
|
18
|
+
testFn: jest.fn(),
|
|
19
|
+
message,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('TestObject constructor', () => {
|
|
24
|
+
expect(testObject).toMatchSnapshot();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('Should have a unique id', () => {
|
|
28
|
+
Array.from(
|
|
29
|
+
{ length: 100 },
|
|
30
|
+
() =>
|
|
31
|
+
new IsolateTest(IsolateTypes.TEST, {
|
|
32
|
+
fieldName,
|
|
33
|
+
testFn: jest.fn(),
|
|
34
|
+
message,
|
|
35
|
+
})
|
|
36
|
+
).reduce((existing, { id }) => {
|
|
37
|
+
expect(existing.has(id)).toBe(false);
|
|
38
|
+
existing.add(id);
|
|
39
|
+
return existing;
|
|
40
|
+
}, new Set<string>());
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('testObject.warn', () => {
|
|
44
|
+
it('Should mark the test as warning', () => {
|
|
45
|
+
expect(testObject.warns()).toBe(false);
|
|
46
|
+
testObject.warn();
|
|
47
|
+
expect(testObject.warns()).toBe(true);
|
|
48
|
+
expect(testObject).toMatchSnapshot();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('testObject.fail', () => {
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
jest.resetModules();
|
|
55
|
+
|
|
56
|
+
const { IsolateTest } = require('IsolateTest'); // eslint-disable-line @typescript-eslint/no-var-requires
|
|
57
|
+
testObject = new IsolateTest(fieldName, jest.fn(), { message });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
afterEach(() => {
|
|
61
|
+
jest.resetAllMocks();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('Should set status to failed', () => {
|
|
65
|
+
expect(testObject.isFailing()).toBe(false);
|
|
66
|
+
testObject.fail();
|
|
67
|
+
expect(testObject.isFailing()).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('testObject.valueOf', () => {
|
|
72
|
+
test('When test did not fail', () => {
|
|
73
|
+
expect(testObject.valueOf()).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('When test failed', () => {
|
|
77
|
+
testObject.fail();
|
|
78
|
+
expect(testObject.valueOf()).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('testObject.cancel', () => {
|
|
83
|
+
it('Should set the testObject to cancel', () => {
|
|
84
|
+
let testObject: IsolateTest;
|
|
85
|
+
return TestPromise(done => {
|
|
86
|
+
const suite = vest.create(() => {
|
|
87
|
+
testObject = vest.test('f1', async () => {
|
|
88
|
+
await wait(100);
|
|
89
|
+
});
|
|
90
|
+
vest.test('f2', async () => {
|
|
91
|
+
await wait(100);
|
|
92
|
+
});
|
|
93
|
+
testObject.cancel();
|
|
94
|
+
});
|
|
95
|
+
suite();
|
|
96
|
+
|
|
97
|
+
expect(testObject.isCanceled()).toBe(true);
|
|
98
|
+
done();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('final statuses', () => {
|
|
103
|
+
let control = jest.fn();
|
|
104
|
+
beforeEach(() => {
|
|
105
|
+
control = jest.fn();
|
|
106
|
+
});
|
|
107
|
+
it('keep status unchanged when `failed`', () => {
|
|
108
|
+
vest.create(() => {
|
|
109
|
+
// async so it is not a final status
|
|
110
|
+
const testObject = vest.test('f1', async () => {
|
|
111
|
+
await wait(100);
|
|
112
|
+
});
|
|
113
|
+
testObject.fail();
|
|
114
|
+
expect(testObject.isFailing()).toBe(true);
|
|
115
|
+
testObject.skip();
|
|
116
|
+
expect(testObject.isSkipped()).toBe(false);
|
|
117
|
+
expect(testObject.isFailing()).toBe(true);
|
|
118
|
+
testObject.cancel();
|
|
119
|
+
expect(testObject.isCanceled()).toBe(false);
|
|
120
|
+
expect(testObject.isFailing()).toBe(true);
|
|
121
|
+
testObject.setPending();
|
|
122
|
+
expect(testObject.isPending()).toBe(false);
|
|
123
|
+
expect(testObject.isFailing()).toBe(true);
|
|
124
|
+
control();
|
|
125
|
+
})();
|
|
126
|
+
expect(control).toHaveBeenCalledTimes(1);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('keep status unchanged when `canceled`', () => {
|
|
130
|
+
vest.create(() => {
|
|
131
|
+
// async so it is not a final status
|
|
132
|
+
const testObject = vest.test('f1', async () => {
|
|
133
|
+
await wait(100);
|
|
134
|
+
});
|
|
135
|
+
testObject.cancel();
|
|
136
|
+
expect(testObject.isCanceled()).toBe(true);
|
|
137
|
+
testObject.fail();
|
|
138
|
+
expect(testObject.isCanceled()).toBe(true);
|
|
139
|
+
expect(testObject.isFailing()).toBe(false);
|
|
140
|
+
testObject.skip();
|
|
141
|
+
expect(testObject.isSkipped()).toBe(false);
|
|
142
|
+
expect(testObject.isCanceled()).toBe(true);
|
|
143
|
+
testObject.setPending();
|
|
144
|
+
expect(testObject.isPending()).toBe(false);
|
|
145
|
+
expect(testObject.isCanceled()).toBe(true);
|
|
146
|
+
control();
|
|
147
|
+
})();
|
|
148
|
+
expect(control).toHaveBeenCalledTimes(1);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`IsolateTest TestObject constructor 1`] = `
|
|
4
|
+
IsolateTest {
|
|
5
|
+
"children": null,
|
|
6
|
+
"fieldName": "unicycle",
|
|
7
|
+
"id": "0",
|
|
8
|
+
"key": null,
|
|
9
|
+
"keys": {},
|
|
10
|
+
"message": "I am Root.",
|
|
11
|
+
"parent": null,
|
|
12
|
+
"severity": "error",
|
|
13
|
+
"stateMachine": {
|
|
14
|
+
"getState": [Function],
|
|
15
|
+
"transition": [Function],
|
|
16
|
+
},
|
|
17
|
+
"testFn": [MockFunction],
|
|
18
|
+
"type": "TEST",
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
exports[`IsolateTest testObject.warn Should mark the test as warning 1`] = `
|
|
23
|
+
IsolateTest {
|
|
24
|
+
"children": null,
|
|
25
|
+
"fieldName": "unicycle",
|
|
26
|
+
"id": "102",
|
|
27
|
+
"key": null,
|
|
28
|
+
"keys": {},
|
|
29
|
+
"message": "I am Root.",
|
|
30
|
+
"parent": null,
|
|
31
|
+
"severity": "warning",
|
|
32
|
+
"stateMachine": {
|
|
33
|
+
"getState": [Function],
|
|
34
|
+
"transition": [Function],
|
|
35
|
+
},
|
|
36
|
+
"testFn": [MockFunction],
|
|
37
|
+
"type": "TEST",
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`test.memo cache hit Should produce correct initial result 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"done": [Function],
|
|
6
|
+
"errorCount": 1,
|
|
7
|
+
"getErrors": [Function],
|
|
8
|
+
"getErrorsByGroup": [Function],
|
|
9
|
+
"getWarnings": [Function],
|
|
10
|
+
"getWarningsByGroup": [Function],
|
|
11
|
+
"groups": {},
|
|
12
|
+
"hasErrors": [Function],
|
|
13
|
+
"hasErrorsByGroup": [Function],
|
|
14
|
+
"hasWarnings": [Function],
|
|
15
|
+
"hasWarningsByGroup": [Function],
|
|
16
|
+
"isValid": [Function],
|
|
17
|
+
"isValidByGroup": [Function],
|
|
18
|
+
"suiteName": undefined,
|
|
19
|
+
"testCount": 4,
|
|
20
|
+
"tests": {
|
|
21
|
+
"field1": {
|
|
22
|
+
"errorCount": 1,
|
|
23
|
+
"errors": [
|
|
24
|
+
"msg1",
|
|
25
|
+
],
|
|
26
|
+
"testCount": 2,
|
|
27
|
+
"valid": false,
|
|
28
|
+
"warnCount": 0,
|
|
29
|
+
"warnings": [],
|
|
30
|
+
},
|
|
31
|
+
"field2": {
|
|
32
|
+
"errorCount": 0,
|
|
33
|
+
"errors": [],
|
|
34
|
+
"testCount": 1,
|
|
35
|
+
"valid": true,
|
|
36
|
+
"warnCount": 0,
|
|
37
|
+
"warnings": [],
|
|
38
|
+
},
|
|
39
|
+
"field3": {
|
|
40
|
+
"errorCount": 0,
|
|
41
|
+
"errors": [],
|
|
42
|
+
"testCount": 1,
|
|
43
|
+
"valid": true,
|
|
44
|
+
"warnCount": 1,
|
|
45
|
+
"warnings": [],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
"valid": false,
|
|
49
|
+
"warnCount": 1,
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
exports[`test.memo cache hit sync Should restore previous result on re-run 1`] = `
|
|
54
|
+
{
|
|
55
|
+
"done": [Function],
|
|
56
|
+
"errorCount": 1,
|
|
57
|
+
"getErrors": [Function],
|
|
58
|
+
"getErrorsByGroup": [Function],
|
|
59
|
+
"getWarnings": [Function],
|
|
60
|
+
"getWarningsByGroup": [Function],
|
|
61
|
+
"groups": {},
|
|
62
|
+
"hasErrors": [Function],
|
|
63
|
+
"hasErrorsByGroup": [Function],
|
|
64
|
+
"hasWarnings": [Function],
|
|
65
|
+
"hasWarningsByGroup": [Function],
|
|
66
|
+
"isValid": [Function],
|
|
67
|
+
"isValidByGroup": [Function],
|
|
68
|
+
"suiteName": undefined,
|
|
69
|
+
"testCount": 4,
|
|
70
|
+
"tests": {
|
|
71
|
+
"field1": {
|
|
72
|
+
"errorCount": 1,
|
|
73
|
+
"errors": [
|
|
74
|
+
"msg1",
|
|
75
|
+
],
|
|
76
|
+
"testCount": 2,
|
|
77
|
+
"valid": false,
|
|
78
|
+
"warnCount": 0,
|
|
79
|
+
"warnings": [],
|
|
80
|
+
},
|
|
81
|
+
"field2": {
|
|
82
|
+
"errorCount": 0,
|
|
83
|
+
"errors": [],
|
|
84
|
+
"testCount": 1,
|
|
85
|
+
"valid": true,
|
|
86
|
+
"warnCount": 0,
|
|
87
|
+
"warnings": [],
|
|
88
|
+
},
|
|
89
|
+
"field3": {
|
|
90
|
+
"errorCount": 0,
|
|
91
|
+
"errors": [],
|
|
92
|
+
"testCount": 1,
|
|
93
|
+
"valid": true,
|
|
94
|
+
"warnCount": 1,
|
|
95
|
+
"warnings": [],
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
"valid": false,
|
|
99
|
+
"warnCount": 1,
|
|
100
|
+
}
|
|
101
|
+
`;
|