-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a56f13
commit ff7371e
Showing
10 changed files
with
10,179 additions
and
2,871 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {RunOptions} from 'npm-check-updates'; | ||
|
||
export const ncuConfig: RunOptions = { | ||
color: true, | ||
upgrade: true, | ||
root: true, | ||
// exclude these | ||
reject: [], | ||
// include only these | ||
filter: [], | ||
}; |
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 |
---|---|---|
|
@@ -7,7 +7,5 @@ module.exports = { | |
], | ||
words: [ | ||
...baseConfig.words, | ||
'promisable', | ||
'jsonify', | ||
], | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import {itSnapshots} from './it-snapshots'; | ||
|
||
describe(itSnapshots.name, () => { | ||
it('should have correct types', () => { | ||
// @ts-expect-error the test function must return something | ||
itSnapshots(() => {}, '', [] as any[]); | ||
itSnapshots( | ||
() => { | ||
console.log('elo?'); | ||
return 5; | ||
}, | ||
'group key', | ||
[ | ||
{ | ||
it: 'should do a thing', | ||
}, | ||
], | ||
); | ||
itSnapshots( | ||
(b: number) => { | ||
return 5 + b; | ||
}, | ||
'group key', | ||
[ | ||
{ | ||
it: 'should do a thing', | ||
input: 32, | ||
}, | ||
], | ||
); | ||
}); | ||
|
||
itSnapshots( | ||
(a: number) => { | ||
return 10 + a; | ||
}, | ||
'itSnapshots', | ||
[ | ||
{ | ||
it: 'works with a single input', | ||
input: 42, | ||
}, | ||
], | ||
); | ||
|
||
itSnapshots( | ||
(a: string, b: number) => { | ||
return [ | ||
a, | ||
b, | ||
].join(','); | ||
}, | ||
'itSnapshots', | ||
[ | ||
{ | ||
it: 'works with multiple inputs', | ||
inputs: [ | ||
'a', | ||
42, | ||
], | ||
}, | ||
], | ||
); | ||
|
||
itSnapshots( | ||
() => { | ||
return 'worked'; | ||
}, | ||
'itSnapshots', | ||
[ | ||
{ | ||
it: 'works with no inputs', | ||
}, | ||
], | ||
); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { | ||
AnyFunction, | ||
assertRuntimeTypeOf, | ||
createDeferredPromiseWrapper, | ||
RequireNonVoid, | ||
TypedFunction, | ||
} from '@augment-vir/common'; | ||
import {assertExpectedOutput, CompareExpectationsOptions} from 'test-established-expectations'; | ||
|
||
type SnapshotTestBaseCase = { | ||
it: string; | ||
force?: true; | ||
}; | ||
|
||
type SnapshotTestCaseSingleInput<FunctionToTestGeneric extends AnyFunction> = { | ||
input: Parameters<FunctionToTestGeneric>[0]; | ||
} & SnapshotTestBaseCase; | ||
|
||
type SnapshotTestCaseMultiInput<FunctionToTestGeneric extends AnyFunction> = { | ||
inputs: Parameters<FunctionToTestGeneric>; | ||
} & SnapshotTestBaseCase; | ||
|
||
type SnapshotTestCase<FunctionToTestGeneric extends AnyFunction> = | ||
Parameters<FunctionToTestGeneric> extends [] | ||
? SnapshotTestBaseCase | ||
: Parameters<FunctionToTestGeneric> extends [any?] | ||
? SnapshotTestCaseSingleInput<FunctionToTestGeneric> | ||
: SnapshotTestCaseMultiInput<FunctionToTestGeneric>; | ||
|
||
type DoesNotAcceptEmptyString = 'this function does not accept empty strings'; | ||
|
||
export function itSnapshots<FunctionToTestGeneric extends AnyFunction, DescribeKey extends string>( | ||
functionToTest: FunctionToTestGeneric extends TypedFunction<any, infer ReturnValue> | ||
? RequireNonVoid<ReturnValue, FunctionToTestGeneric> | ||
: never, | ||
describeKey: '' extends DescribeKey | ||
? DoesNotAcceptEmptyString | ||
: DoesNotAcceptEmptyString extends DescribeKey | ||
? never | ||
: DescribeKey, | ||
snapshotCases: void extends ReturnType<FunctionToTestGeneric> | ||
? 'functionToTest must return something so its output can be tested.' | ||
: ReadonlyArray<SnapshotTestCase<FunctionToTestGeneric>>, | ||
options: Pick< | ||
CompareExpectationsOptions<any>, | ||
'cwd' | 'noOverwriteWhenDifferent' | 'showFullError' | 'expectationFile' | ||
> = {}, | ||
) { | ||
assertRuntimeTypeOf(functionToTest, 'function', 'functionToTest input'); | ||
assertRuntimeTypeOf(snapshotCases, 'array', 'snapshotCases input'); | ||
|
||
snapshotCases.reduce((previousPromises, snapshotCase) => { | ||
const newDeferredPromise = createDeferredPromiseWrapper<void>(); | ||
const currentPromises = [ | ||
...previousPromises, | ||
newDeferredPromise.promise, | ||
]; | ||
// add an empty error handler to prevent extraneous errors | ||
// cannot test for it cases that fail | ||
// istanbul ignore next | ||
newDeferredPromise.promise.catch(() => null); | ||
it(snapshotCase.it, async () => { | ||
try { | ||
await Promise.all(previousPromises); | ||
} catch (error) { | ||
// ignore this error so that all tests try to run | ||
} | ||
try { | ||
const inputs: Parameters<FunctionToTestGeneric> = | ||
'input' in snapshotCase | ||
? ([snapshotCase.input] as Parameters<FunctionToTestGeneric>) | ||
: 'inputs' in snapshotCase | ||
? snapshotCase.inputs | ||
: ([] as unknown as Parameters<FunctionToTestGeneric>); | ||
await assertExpectedOutput( | ||
functionToTest, | ||
{ | ||
key: { | ||
topKey: describeKey, | ||
subKey: snapshotCase.it, | ||
}, | ||
...options, | ||
}, | ||
...inputs, | ||
); | ||
newDeferredPromise.resolve(); | ||
} catch (error) { | ||
// cannot test for it cases that fail | ||
// istanbul ignore next | ||
newDeferredPromise.reject(error); | ||
// istanbul ignore next | ||
throw error; | ||
} | ||
}); | ||
|
||
return currentPromises; | ||
}, [] as ReadonlyArray<Promise<void>>); | ||
} |
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