Skip to content

Commit

Permalink
Fix all failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jan 16, 2024
1 parent 5be9348 commit 6371439
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 42 deletions.
8 changes: 4 additions & 4 deletions packages/n4s/src/plugins/schema/__tests__/shape&loose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe.each(['loose', 'shape'])('enforce.%s', (methodName: string) => {
enforce[methodName]({
username: enforce.isString(),
age: enforce.isNumber().gt(18),
}).run({ username: 'ealush', age: 31 })
}).run({ username: 'ealush', age: 31 }),
).toEqual(ruleReturn.passing());
});

Expand All @@ -23,7 +23,7 @@ describe.each(['loose', 'shape'])('enforce.%s', (methodName: string) => {
enforce[methodName]({
username: enforce.isString(),
age: enforce.isNumber().gt(18),
}).run({ username: null, age: 0 })
}).run({ username: null, age: 0 }),
).toEqual(ruleReturn.failing());
});

Expand All @@ -48,7 +48,7 @@ describe.each(['loose', 'shape'])('enforce.%s', (methodName: string) => {
state: 'NY',
zip: 12345,
},
})
}),
).toEqual(ruleReturn.passing());
});
it('Should return a failing return when tests are invalid', () => {
Expand All @@ -69,7 +69,7 @@ describe.each(['loose', 'shape'])('enforce.%s', (methodName: string) => {
street: '123 Main St',
city: null,
},
})
}),
).toEqual(ruleReturn.failing());
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/vest/src/core/VestBus/VestBus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { SuiteWalker } from 'SuiteWalker';
import { CB, ValueOf } from 'vest-utils';
import { Bus, RuntimeEvents, TIsolate } from 'vestjs-runtime';

Expand All @@ -11,6 +10,7 @@ import {
useResetSuite,
} from 'Runtime';
import { TFieldName } from 'SuiteResultTypes';
import { SuiteWalker } from 'SuiteWalker';
import { TestWalker } from 'TestWalker';
import { VestTest } from 'VestTest';
import { useOmitOptionalFields } from 'omitOptionalFields';
Expand Down
1 change: 1 addition & 0 deletions packages/vest/src/core/__tests__/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('useLoadSuite', () => {

function genDump() {
const suite = vest.create(() => {
vest.mode(vest.Modes.ALL);
vest.skip('t5');

vest.test('t1', () => false);
Expand Down
3 changes: 1 addition & 2 deletions packages/vest/src/hooks/focused/useIsExcluded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useHasOnliedTests } from 'useHasOnliedTests';
//Checks whether a certain test profile excluded by any of the exclusion groups.

function useClosestMatchingFocus(
testObject: TIsolateTest
testObject: TIsolateTest,
): Nullable<TIsolateFocused> {
return Walker.findClosest(testObject, (child: TIsolate) => {
if (!FocusSelectors.isIsolateFocused(child)) return false;
Expand All @@ -21,7 +21,6 @@ function useClosestMatchingFocus(
});
}

// eslint-disable-next-line complexity, max-statements
export function useIsExcluded(testObject: TIsolateTest): boolean {
const { fieldName } = VestTest.getData(testObject);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { faker } from '@faker-js/faker';
import { VestTest } from 'VestTest';

import { TIsolateTest } from 'IsolateTest';
import { Severity } from 'Severity';
import { VestTest } from 'VestTest';
import { hasFailuresByTestObject } from 'hasFailuresByTestObjects';
import { mockIsolateTest } from 'vestMocks';

Expand All @@ -22,10 +22,10 @@ describe('hasFailuresByTestObject', () => {
it('Should return false', () => {
expect(hasFailuresByTestObject(testObject, Severity.ERRORS)).toBe(false);
expect(hasFailuresByTestObject(testObject, Severity.WARNINGS)).toBe(
false
false,
);
expect(
hasFailuresByTestObject(testObject, Severity.ERRORS, fieldName)
hasFailuresByTestObject(testObject, Severity.ERRORS, fieldName),
).toBe(false);
});
});
Expand All @@ -38,23 +38,23 @@ describe('hasFailuresByTestObject', () => {
describe('When non matching severity profile', () => {
it('should return false', () => {
expect(hasFailuresByTestObject(testObject, Severity.WARNINGS)).toBe(
false
false,
);
VestTest.warn(testObject);
expect(hasFailuresByTestObject(testObject, Severity.ERRORS)).toBe(
false
false,
);
});
});

describe('When matching severity profile', () => {
it('Should return true', () => {
expect(hasFailuresByTestObject(testObject, Severity.ERRORS)).toBe(
true
true,
);
VestTest.warn(testObject);
expect(hasFailuresByTestObject(testObject, Severity.WARNINGS)).toBe(
true
true,
);
});
});
Expand All @@ -63,23 +63,27 @@ describe('hasFailuresByTestObject', () => {
describe('When field name matches', () => {
it('should return false', () => {
expect(
hasFailuresByTestObject(testObject, Severity.ERRORS, 'non_matching')
hasFailuresByTestObject(
testObject,
Severity.ERRORS,
'non_matching',
),
).toBe(false);
});
});

describe('When field name matches', () => {
it('Should continue with normal flow', () => {
expect(hasFailuresByTestObject(testObject, Severity.WARNINGS)).toBe(
false
false,
);
VestTest.warn(testObject);
expect(hasFailuresByTestObject(testObject, Severity.ERRORS)).toBe(
false
false,
);
VestTest.fail(testObject);
expect(hasFailuresByTestObject(testObject, Severity.WARNINGS)).toBe(
true
true,
);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TTestSuite } from 'testUtils/TVestMock';

import * as vest from 'vest';

describe('summaryFailures', () => {
Expand Down Expand Up @@ -68,6 +69,7 @@ describe('summaryFailures', () => {

test('Should add the test group into the error object', () => {
suite = vest.create(() => {
vest.mode(vest.Modes.ALL);
vest.group('user', () => {
vest.test('username', 'uxsername is required', () => false);
vest.test('username', 'username is too short', () => false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { SuiteWalker } from 'SuiteWalker';
import { useIsOptionalFieldApplied } from 'optional';
import { Predicates } from 'vest-utils';
import { VestRuntime } from 'vestjs-runtime';
Expand All @@ -8,6 +7,7 @@ import { TIsolateTest } from 'IsolateTest';
import { OptionalFieldTypes } from 'OptionalTypes';
import { Severity } from 'Severity';
import { TFieldName, TGroupName } from 'SuiteResultTypes';
import { SuiteWalker } from 'SuiteWalker';
import { TestWalker } from 'TestWalker';
import { VestTest } from 'VestTest';
import {
Expand Down
3 changes: 1 addition & 2 deletions packages/vest/src/vest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { enforce } from 'n4s';

// eslint-disable-next-line import/order -- will handle this circular dep issue later.
import { optional } from 'optional';

import { Modes } from 'Modes';
import type {
SuiteResult,
Expand Down
11 changes: 3 additions & 8 deletions packages/vestjs-runtime/src/Isolate/Isolate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type UsedFeaturesOnly<P extends IsolatePayload> = Pick<
>;

export class Isolate {
// eslint-disable-next-line max-statements
static create<Payload extends IsolatePayload>(
type: string,
callback: CB,
Expand All @@ -49,15 +48,11 @@ export class Isolate {

const shouldRunNew = Object.is(nextIsolateChild, newCreatedNode);

let output: any;

VestRuntime.addNodeToHistory(nextIsolateChild);

if (shouldRunNew) {
output = useRunAsNew(localHistoryNode, newCreatedNode, callback);
} else {
output = nextIsolateChild.output;
}
const output = shouldRunNew
? useRunAsNew(localHistoryNode, newCreatedNode, callback)
: nextIsolateChild.output;

IsolateMutator.saveOutput(nextIsolateChild, output);

Expand Down
26 changes: 13 additions & 13 deletions packages/vestjs-runtime/src/IsolateWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type VisitOnlyPredicate = (isolate: TIsolate) => boolean;
export function walk(
startNode: TIsolate,
callback: (isolate: TIsolate, breakout: CB<void>) => void,
visitOnly?: VisitOnlyPredicate
visitOnly?: VisitOnlyPredicate,
): void {
// If the startNode has no children, there is nothing to walk.
if (isNullish(startNode.children)) {
Expand Down Expand Up @@ -43,7 +43,7 @@ export function walk(
breakout();
});
},
visitOnly
visitOnly,
);
}

Expand All @@ -57,7 +57,7 @@ export function walk(
export function some(
startNode: TIsolate,
predicate: (node: TIsolate) => boolean,
visitOnly?: VisitOnlyPredicate
visitOnly?: VisitOnlyPredicate,
): boolean {
let hasMatch = false;

Expand All @@ -70,7 +70,7 @@ export function some(
hasMatch = true;
}
},
visitOnly
visitOnly,
);

return hasMatch;
Expand All @@ -86,7 +86,7 @@ export function has(startNode: TIsolate, match: VisitOnlyPredicate): boolean {
// and returns the first direct descendant that satisfies the predicate
export function findClosest<I extends TIsolate = TIsolate>(
startNode: TIsolate,
predicate: (node: TIsolate) => boolean
predicate: (node: TIsolate) => boolean,
): Nullable<I> {
let found: Nullable<TIsolate> = null;
let current: Nullable<TIsolate> = startNode;
Expand All @@ -109,7 +109,7 @@ export function findClosest<I extends TIsolate = TIsolate>(
export function find(
startNode: TIsolate,
predicate: (node: TIsolate) => boolean,
visitOnly?: VisitOnlyPredicate
visitOnly?: VisitOnlyPredicate,
): Nullable<TIsolate> {
let found = null;

Expand All @@ -122,7 +122,7 @@ export function find(
found = node;
}
},
visitOnly
visitOnly,
);

return found;
Expand All @@ -133,7 +133,7 @@ export function find(
export function every(
startNode: TIsolate,
predicate: (node: TIsolate) => boolean,
visitOnly?: VisitOnlyPredicate
visitOnly?: VisitOnlyPredicate,
): boolean {
let hasMatch = true;
walk(
Expand All @@ -144,7 +144,7 @@ export function every(
hasMatch = false;
}
},
visitOnly
visitOnly,
);

return hasMatch;
Expand All @@ -156,7 +156,7 @@ export function every(
export function pluck(
startNode: TIsolate,
predicate: (node: TIsolate) => boolean,
visitOnly?: VisitOnlyPredicate
visitOnly?: VisitOnlyPredicate,
): void {
walk(
startNode,
Expand All @@ -165,15 +165,15 @@ export function pluck(
IsolateMutator.removeChild(node.parent, node);
}
},
visitOnly
visitOnly,
);
}

// Returns the closest ancestor Isolate object of the given
//startNode that satisfies the given predicate function.
export function closest(
startNode: TIsolate,
predicate: (node: TIsolate) => boolean
predicate: (node: TIsolate) => boolean,
): Nullable<TIsolate> {
let current: Nullable<TIsolate> = startNode;
do {
Expand All @@ -189,7 +189,7 @@ export function closest(
// given startNode that satisfies the given predicate function exists.
export function closestExists(
startNode: TIsolate,
predicate: (node: TIsolate) => boolean
predicate: (node: TIsolate) => boolean,
): boolean {
return !!closest(startNode, predicate);
}

0 comments on commit 6371439

Please sign in to comment.