-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(vest): Remove most itWithContext instances from tests
- Loading branch information
Showing
4 changed files
with
381 additions
and
329 deletions.
There are no files selected for viewing
207 changes: 106 additions & 101 deletions
207
packages/vest/src/core/suite/__tests__/hasRemainingTests.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
870a2ed
There was a problem hiding this comment.
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