Skip to content

Commit

Permalink
better
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jul 27, 2024
1 parent a779324 commit 44876a7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ruleReturn from '@/lib/ruleReturn';
import { enforce } from '@/runtime/enforce';
import '../../../exports/schema';
import '../../../exports/compounds';
import * as ruleReturn from '@/lib/ruleReturn';

describe('enforce.isArrayOf', () => {
describe('lazy interface', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/n4s/src/plugins/schema/__tests__/partial.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { partial } from '../partial';

import * as ruleReturn from '@/lib/ruleReturn';
import { enforce } from 'n4s';

import '../../../exports/schema';
import '../../../exports/compounds';
import { partial } from '../partial';

describe('partial', () => {
describe('Lazy Interface', () => {
Expand Down
76 changes: 15 additions & 61 deletions packages/vest/src/__tests__/isolate.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
import { CB } from 'vest-utils';
import { TDeferThrow } from 'vest-utils/src/deferThrow';
import { Isolate } from 'vestjs-runtime';

import { TVestMock } from '../testUtils/TVestMock';
import mockThrowError from '../testUtils/mockThrowError';
import { TDummyTest } from '../testUtils/testDummy';
import { dummyTest } from '@/testUtils/testDummy';
import * as vest from 'vest';

describe('isolate', () => {
let vest: TVestMock;
let firstRun = true;
vi.importActual('@/core/isolate/IsolateTest/IsolateTest');
vi.importActual('@/core/isolate/IsolateTest/IsolateEach');
let dummyTest: TDummyTest;
let deferThrow: TDeferThrow;

beforeEach(() => {
firstRun = true;
const mock = mockThrowError();
deferThrow = mock.deferThrow;

vi.importActual('@/core/isolate/IsolateTest/IsolateTest');
vi.importActual('@/core/isolate/IsolateTest/IsolateEach');
vest = mock.vest;
dummyTest = require('../testUtils/testDummy').dummyTest;
});

afterEach(() => {
vi.resetModules();
vi.resetAllMocks();
});

describe('Base behavior', () => {
it("Should throw an error if the callback isn't a function", () => {
// @ts-ignore - testing bad input
Expand All @@ -39,7 +13,8 @@ describe('isolate', () => {
it('Should retain test results between runs', () => {
const f1 = vi.fn(() => false);
const f2 = vi.fn(() => false);
const suite = genSuite(() => {
const firstRun = true;
const suite = vest.create(() => {
vest.skipWhen(!firstRun, () => {
vest.test('f1', f1);
vest.test('f2', f2);
Expand All @@ -61,7 +36,8 @@ describe('isolate', () => {

describe('When order changes within the isolate', () => {
it('Should contain test order changes within the isolate', () => {
const suite = genSuite(() => {
const firstRun = true;
const suite = vest.create(() => {
dummyTest.failing('f1');

vest.group(() => {
Expand Down Expand Up @@ -107,7 +83,8 @@ describe('isolate', () => {
});

it('Should only retain the state of the unmoved state before the order index', () => {
const suite = genSuite(() => {
const firstRun = true;
const suite = vest.create(() => {
vest.group(() => {
vest.skipWhen(!firstRun, () => {
dummyTest.failing('f1');
Expand Down Expand Up @@ -141,7 +118,8 @@ describe('isolate', () => {

describe('When test order changes before the isolate opens', () => {
it('Should clean up follow up tests. Reregister', () => {
const suite = genSuite(() => {
const firstRun = true;
const suite = vest.create(() => {
dummyTest.failing('f1');
if (!firstRun) {
dummyTest.failing('f6');
Expand Down Expand Up @@ -193,7 +171,8 @@ describe('isolate', () => {

describe('When an incorrect isolate is encountered', () => {
it('Should replace isolate completely', () => {
const suite = genSuite(() => {
const firstRun = true;
const suite = vest.create(() => {
if (firstRun) {
vest.group(() => {
dummyTest.failing('f1');
Expand All @@ -220,14 +199,16 @@ describe('isolate', () => {

describe('When an isolate is present when a test was expected', () => {
it('Should erase test history, and re-register', () => {
const suite = genSuite(() => {
let firstRun = true;
const suite = vest.create(() => {
if (firstRun) {
dummyTest.failing('f1');
} else {
vest.group(() => {
dummyTest.failing('f2');
});
}
firstRun = false;
});

suite();
Expand All @@ -241,32 +222,5 @@ describe('isolate', () => {
expect(suite.get().tests.f1).toBeUndefined();
expect(suite.get().tests.f2).toBeDefined();
});

describe('Errors', () => {
it('should throw a deferred error when the tests are out of order', () => {
const suite = genSuite(() => {
vest.group(() => {
dummyTest.failing(firstRun ? 'f1' : 'f2');
});
});

suite();
expect(deferThrow).toHaveBeenCalledTimes(0);
suite();
expect(deferThrow).toHaveBeenCalledTimes(1);
expect(deferThrow).toHaveBeenCalledWith(
expect.stringContaining(
'Vest Critical Error: Tests called in different order than previous run',
),
);
});
});
});

function genSuite(cb: CB) {
return vest.create(() => {
cb();
firstRun = false;
});
}
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CB, Maybe } from 'vest-utils';
import { CB } from 'vest-utils';

import { IsolateSerializer } from '../IsolateSerializer';

Expand Down Expand Up @@ -79,22 +79,6 @@ describe('IsolateSerializer', () => {
// @ts-ignore
root.children[1].status = 'failed';

const minimap = {
values: {
status: {
pending: 'p',
done: 'd',
failed: 'f',
},
$type: {
URoot: 'UR',
UChild_1: 'UC1',
UChild_2: 'UC2',
UChild_3: 'UC3',
},
},
};

const serialized = IsolateSerializer.serialize(root);
const inflated = IsolateSerializer.deserialize(serialized);

Expand Down Expand Up @@ -191,7 +175,7 @@ function withRunTime<T>(fn: CB<T>) {
});
}

function createRoot(miniMap?: Maybe<Record<string, any>>) {
function createRoot() {
let serialized: string, root: TIsolate;

withRunTime(() => {
Expand Down

0 comments on commit 44876a7

Please sign in to comment.