Skip to content

Commit

Permalink
fix(vest): clear cache before each test
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Dec 18, 2024
1 parent 8cfa4a6 commit 4854ab2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/vest/src/core/VestBus/VestBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@ export function useInitVestBus() {
const VestBus = Bus.useBus();

on('TEST_COMPLETED', () => {});
// on("TEST_RUN_STARTED", () => {});

on('TEST_RUN_STARTED', () => {
// Bringin this back due to https://github.com/ealush/vest/issues/1157
// This is a very pecluiar bug in which we're seeing vest behaving differently between
// runs when suite.get() is called.
// In the bug we experienced that failing tests were skipped in the second run.
// The reason: suite.get() built the failures cache. Calling suite.get() before the test run
// made Vest think that the field already had failing tests (even though it was the same test!)
// and it skipped the test.
// A better solution is to be able to identify each failure to its actual position in the suite
// but this requires some rearchitecting within Vest.
// This is an easy enough solution - we just reset the cache before the test run, let's hope we don't see
// any performance issues.
});

VestBus.on(RuntimeEvents.ISOLATE_PENDING, (isolate: TIsolate) => {
if (VestTest.is(isolate)) {
Expand Down
23 changes: 23 additions & 0 deletions packages/vest/src/suite/__tests__/subscribe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,26 @@ describe('suite.subscribe', () => {
});
});
});

describe('#1157 (@codrin-iftimie) suite.get() in subscribe() skips the first validation of the field', () => {
it('Should fail for the first field in both runs', () => {
const suite = vest.create(data => {
vest.test('a', 'Enter a value', () => {
enforce(data.a).isNotEmpty();
});

vest.test('a', 'Enter a value 2', () => {
enforce(data.a).isNotEmpty();
});
});

suite.subscribe(() => {
suite.get();
});

suite({ a: '' });
expect(suite.getErrors('a')).toEqual(['Enter a value']);
suite({ a: '' });
expect(suite.getErrors('a')).toEqual(['Enter a value']);
});
});

0 comments on commit 4854ab2

Please sign in to comment.