Skip to content

Commit

Permalink
Static suite is awaitable
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jul 12, 2024
1 parent b2330f7 commit e8515a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
7 changes: 3 additions & 4 deletions packages/vest/src/suite/__tests__/staticSuite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('runStatic', () => {
expect(suite2.hasErrors('t4')).toBe(false);
});

describe('runStatic.resolve', () => {
describe('runStatic (promise)', () => {
it("Should resolve with the suite's result", async () => {
const suite = vest.create(() => {
vest.test('t1', async () => {
Expand All @@ -153,8 +153,7 @@ describe('runStatic', () => {

const res = suite.runStatic();
expect(res.errorCount).toBe(0);
expect(res).toHaveProperty('resolve');
const result = await res.resolve();
const result = await res;
expect(result.errorCount).toBe(1);
});

Expand All @@ -167,7 +166,7 @@ describe('runStatic', () => {
});

const res = suite.runStatic();
const result = await res.resolve();
const result = await res;
expect(result).toHaveProperty('dump');
expect(result.dump()).toHaveProperty('$type', VestIsolateType.Suite);
});
Expand Down
23 changes: 8 additions & 15 deletions packages/vest/src/suite/createSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,13 @@ function staticSuite<

const result = suite(...args);

const resolve = new Promise<SuiteWithDump<F, G>>(resolve => {
result.done(res => {
resolve(withDump(res) as SuiteWithDump<F, G>);
});
});

return freezeAssign<StaticSuiteRunResult<F, G>>(
withDump({
resolve: () => resolve,
return assign(
new Promise<SuiteWithDump<F, G>>(resolve => {
result.done(res => {
resolve(withDump(res) as SuiteWithDump<F, G>);
});
}),
result,
withDump(result),
);

function withDump(o: any) {
Expand All @@ -187,11 +183,8 @@ export type StaticSuite<
export type StaticSuiteRunResult<
F extends TFieldName = string,
G extends TGroupName = string,
> = WithDump<
SuiteRunResult<F, G> & {
resolve: () => Promise<SuiteWithDump<F, G>>;
} & TTypedMethods<F, G>
>;
> = Promise<SuiteWithDump<F, G>> &
WithDump<SuiteRunResult<F, G> & TTypedMethods<F, G>>;

type WithDump<T> = T & { dump: CB<TIsolateSuite> };
type SuiteWithDump<F extends TFieldName, G extends TGroupName> = WithDump<
Expand Down

0 comments on commit e8515a5

Please sign in to comment.