Skip to content

Commit

Permalink
patch(vest): move suite selectors out into their own module for easie…
Browse files Browse the repository at this point in the history
…r consumption by external sources (#906)
  • Loading branch information
ealush authored Jul 14, 2022
1 parent eed736a commit e8dbbc9
Show file tree
Hide file tree
Showing 21 changed files with 274 additions and 295 deletions.
2 changes: 1 addition & 1 deletion packages/vest/src/core/ctx/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { assign } from 'vest-utils';

import { Isolate, IsolateTypes } from 'IsolateTypes';
import { Modes } from 'Modes';
import { SuiteSummary } from 'SuiteSummaryTypes';
import VestTest from 'VestTest';
import type { StateRef } from 'createStateRef';
import { SuiteSummary } from 'genTestsSummary';
import { generateIsolate } from 'generateIsolate';

export default createContext<CTXType>((ctxRef, parentContext) =>
Expand Down
37 changes: 3 additions & 34 deletions packages/vest/src/core/suite/produce/produceSuiteResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import { cache as createCache, assign } from 'vest-utils';

import ctx from 'ctx';
import genTestsSummary from 'genTestsSummary';
import { getErrors, getWarnings } from 'getFailures';
import { getErrorsByGroup, getWarningsByGroup } from 'getFailuresByGroup';
import { hasErrors, hasWarnings } from 'hasFailures';
import { hasErrorsByGroup, hasWarningsByGroup } from 'hasFailuresByGroup';
import { isValid, isValidByGroup } from 'isValid';
import { useStateRef, useTestsFlat, useSuiteName } from 'stateHooks';
import { SuiteSelectors, suiteSelectors } from 'suiteSelectors';

const cache = createCache(1);

Expand All @@ -21,38 +17,11 @@ export function produceSuiteResult(): SuiteResult {
ctx.bind(ctxRef, () => {
const summary = genTestsSummary();
const suiteName = useSuiteName();
const ref = { summary };
return assign(summary, {
getErrors: ctx.bind(ref, getErrors),
getErrorsByGroup: ctx.bind(ref, getErrorsByGroup),
getWarnings: ctx.bind(ref, getWarnings),
getWarningsByGroup: ctx.bind(ref, getWarningsByGroup),
hasErrors: ctx.bind(ref, hasErrors),
hasErrorsByGroup: ctx.bind(ref, hasErrorsByGroup),
hasWarnings: ctx.bind(ref, hasWarnings),
hasWarningsByGroup: ctx.bind(ref, hasWarningsByGroup),
isValid: ctx.bind(ref, isValid),
isValidByGroup: ctx.bind(ref, isValidByGroup),
return assign(summary, suiteSelectors(summary), {
suiteName,
});
})
);
}

export type SuiteResult = ReturnType<typeof genTestsSummary> & {
/**
* Returns whether the suite as a whole is valid.
* Determined if there are no errors, and if no
* required fields are skipped.
*/
isValid: typeof isValid;
isValidByGroup: typeof isValidByGroup;
hasErrors: typeof hasErrors;
hasWarnings: typeof hasWarnings;
getErrors: typeof getErrors;
getWarnings: typeof getWarnings;
hasErrorsByGroup: typeof hasErrorsByGroup;
hasWarningsByGroup: typeof hasWarningsByGroup;
getErrorsByGroup: typeof getErrorsByGroup;
getWarningsByGroup: typeof getWarningsByGroup;
};
export type SuiteResult = ReturnType<typeof genTestsSummary> & SuiteSelectors;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export type SuiteSummary = {
groups: Groups;
tests: Tests;
valid: boolean;
} & SummaryBase;

export type TestsContainer = Group | Tests;
export type GroupTestSummary = SingleTestSummary;

export type Groups = Record<string, Group>;
export type Group = Record<string, GroupTestSummary>;
export type Tests = Record<string, SingleTestSummary>;

export type SingleTestSummary = SummaryBase & {
errors: string[];
warnings: string[];
valid: boolean;
};

type SummaryBase = {
errorCount: number;
warnCount: number;
testCount: number;
};

export type GetFailuresResponse = FailureMessages | string[];

export type FailureMessages = Record<string, string[]>;
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { assign, invariant } from 'vest-utils';

import { countKeyBySeverity, Severity } from 'Severity';
import {
Group,
Groups,
SingleTestSummary,
SuiteSummary,
Tests,
TestsContainer,
} from 'SuiteSummaryTypes';
import VestTest from 'VestTest';
import ctx from 'ctx';
import {
Expand Down Expand Up @@ -140,28 +148,3 @@ function baseTestStats() {
warnings: [],
});
}

export type SuiteSummary = {
groups: Groups;
tests: Tests;
valid: boolean;
} & SummaryBase;

export type TestsContainer = Group | Tests;
export type GroupTestSummary = SingleTestSummary;

type Groups = Record<string, Group>;
type Group = Record<string, GroupTestSummary>;
type Tests = Record<string, SingleTestSummary>;

type SingleTestSummary = SummaryBase & {
errors: string[];
warnings: string[];
valid: boolean;
};

type SummaryBase = {
errorCount: number;
warnCount: number;
testCount: number;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO: Verify this test file is not needed and delete it
import { dummyTest } from '../../../../../../../testUtils/testDummy';
import { dummyTest } from '../../../../../../testUtils/testDummy';

import create from 'create';
import group from 'group';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dummyTest } from '../../../../../../../testUtils/testDummy';
import { dummyTest } from '../../../../../../testUtils/testDummy';

import * as vest from 'vest';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dummyTest } from '../../../../../../../testUtils/testDummy';
import { dummyTest } from '../../../../../../testUtils/testDummy';

import group from 'group';
import { create } from 'vest';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import faker from 'faker';

import { dummyTest } from '../../../../../../../testUtils/testDummy';
import { dummyTest } from '../../../../../../testUtils/testDummy';

import * as vest from 'vest';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import faker from 'faker';

import { dummyTest } from '../../../../../../../testUtils/testDummy';
import { dummyTest } from '../../../../../../testUtils/testDummy';

import * as vest from 'vest';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isPositive } from 'vest-utils';

import { countKeyBySeverity, Severity } from 'Severity';
import { TestsContainer } from 'genTestsSummary';
import { FailureMessages, TestsContainer } from 'SuiteSummaryTypes';

// calls collectAll or getByFieldName depending on whether fieldName is provided

Expand Down Expand Up @@ -41,5 +41,3 @@ function collectAll(

return output;
}

export type FailureMessages = Record<string, string[]>;

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

38 changes: 0 additions & 38 deletions packages/vest/src/core/suite/produce/summarySelectors/isValid.ts

This file was deleted.

Loading

1 comment on commit e8dbbc9

@vercel
Copy link

@vercel vercel bot commented on e8dbbc9 Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest-next – ./website

vest-website.vercel.app
vest-next.vercel.app
vest-next-git-latest-ealush.vercel.app
vest-next-ealush.vercel.app

Please sign in to comment.