Skip to content

Commit

Permalink
tests(vest): Remove most itWithContext instances from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed May 28, 2022
1 parent 1944122 commit 870a2ed
Show file tree
Hide file tree
Showing 4 changed files with 381 additions and 329 deletions.
207 changes: 106 additions & 101 deletions packages/vest/src/core/suite/__tests__/hasRemainingTests.test.ts
Original file line number Diff line number Diff line change
@@ -1,123 +1,128 @@
import faker from 'faker';
import _ from 'lodash';
import wait from 'wait';

import itWithContext from '../../../../testUtils/itWithContext';
import runCreateRef from '../../../../testUtils/runCreateRef';
import { addTestObject } from '../../../../testUtils/testObjects';

import VestTest from 'VestTest';
import context from 'ctx';
import hasRemainingTests from 'hasRemainingTests';

let stateRef;
const getCtx = () => ({ stateRef });

const addPending = (fieldName?: string) => {
context.run({ stateRef }, () => {
const added = Array.from(
{ length: _.random(1, 3) },
() => new VestTest(fieldName ?? faker.random.word(), jest.fn())
);

addTestObject(added);
added.forEach(testObject => testObject.setPending());
});
};
import * as vest from 'vest';

describe('hasRemainingTests', () => {
let hasRemaining = null;
let count = 0;

beforeEach(() => {
stateRef = runCreateRef();
hasRemaining = null;
count = 0;
});

describe('When no field specified', () => {
describe('When no remaining tests', () => {
itWithContext(
'should return false',
() => {
expect(hasRemainingTests()).toBe(false);
},
getCtx
);
it('should return false', () => {
vest.create(() => {
hasRemaining = hasRemainingTests();
})();
expect(hasRemaining).toBe(false);
});
});

describe('When there are remaining tests', () => {
itWithContext(
'pending tests return true',
() => {
addPending();

expect(hasRemainingTests()).toBe(true);
},
getCtx
);

itWithContext(
'lagging tests return true',
() => {
addPending();

expect(hasRemainingTests()).toBe(true);
},
getCtx
);

itWithContext(
'lagging and pending tests return true',
() => {
addPending();
addPending();

expect(hasRemainingTests()).toBe(true);
},
getCtx
);
it('pending tests return true', () => {
vest.create(() => {
vest.test('f1', async () => {
await wait(100);
});
hasRemaining = hasRemainingTests();
})();

expect(hasRemaining).toBe(true);
});

it('lagging tests return true', () => {
const suite = vest.create(() => {
if (count) vest.skip('f1');
vest.test('f1', async () => {
await wait(100);
});
count++;
hasRemaining = hasRemainingTests();
});
suite();
suite();

expect(hasRemaining).toBe(true);
});

it('lagging and pending tests return true', () => {
const suite = vest.create(() => {
if (count) vest.skip('f1');
vest.test('f1', async () => {
await wait(100);
});
vest.test('f2', async () => {
await wait(100);
});
count++;
hasRemaining = hasRemainingTests();
});

suite();
suite();

expect(hasRemaining).toBe(true);
});
});
});

describe('When field specified', () => {
let fieldName;

beforeEach(() => {
fieldName = faker.lorem.word();
});
describe('When no remaining tests', () => {
itWithContext(
'Should return false',
() => {
expect(hasRemainingTests(fieldName)).toBe(false);
},
getCtx
);
it('Should return false', () => {
vest.create(() => {
hasRemaining = hasRemainingTests('f1');
})();
expect(hasRemaining).toBe(false);
});
});

describe('When remaining tests', () => {
itWithContext(
'pending tests return true',
() => {
addPending(fieldName);
expect(hasRemainingTests()).toBe(true);
},
getCtx
);

itWithContext(
'lagging tests return true',
() => {
addPending(fieldName);
expect(hasRemainingTests()).toBe(true);
},
getCtx
);

itWithContext(
'lagging and pending tests return true',
() => {
addPending(fieldName);
addPending(fieldName);
expect(hasRemainingTests()).toBe(true);
},
getCtx
);
it('pending tests return true', () => {
vest.create(() => {
vest.test('f1', async () => {
await wait(100);
});
hasRemaining = hasRemainingTests('f1');
})();
expect(hasRemaining).toBe(true);
});

it('lagging tests return true', () => {
const suite = vest.create(() => {
if (count) vest.skip('f1');
vest.test('f1', async () => {
await wait(100);
});
count++;
hasRemaining = hasRemainingTests('f1');
});
suite();
suite();

expect(hasRemaining).toBe(true);
});

it('lagging and pending tests return true', () => {
const suite = vest.create(() => {
if (count) vest.skip('f1');
vest.test('f1', async () => {
await wait(100);
});
vest.test('f2', async () => {
await wait(100);
});
count++;
hasRemaining = hasRemainingTests('f1') && hasRemainingTests('f2');
});

suite();
suite();

expect(hasRemaining).toBe(true);
});
});
});
});
Loading

1 comment on commit 870a2ed

@vercel
Copy link

@vercel vercel bot commented on 870a2ed May 28, 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-next.vercel.app
vest-website.vercel.app
vest-next-git-latest-ealush.vercel.app
vest-next-ealush.vercel.app

Please sign in to comment.