Repository URL to install this package:
|
Version:
5.0.0 ▾
|
export interface SetupOptions {
shouldUseJsdom?: boolean
shouldUseExotic?: boolean
shouldUseEnzyme?: boolean
shouldUseReactTestingLibrary?: boolean
/* only ever true :P */
shouldUseTypeScript?: true
shouldUseSonarQube?: boolean
shouldUseStoryBook?: boolean
shouldExtendExpectWithDocumentObjectModel?: boolean
shouldUseRequestAnimationFrame?: boolean
}
// or could do `no-react`
const shouldUseReact = process.argv.slice(2).includes('--react')
export const DEFAULT_OPTIONS: SetupOptions = Object.freeze({
shouldUseJsdom: shouldUseReact,
shouldUseEnzyme: shouldUseReact,
shouldUseReactTestingLibrary: shouldUseReact,
shouldUseRequestAnimationFrame: shouldUseReact,
shouldExtendExpectWithDocumentObjectModel: shouldUseReact,
shouldUseExotic: true,
shouldUseSonarQube: false,
shouldUseStoryBook: false,
})
export function setupTestFrameworkScript(options: SetupOptions) {
const mergedOptions = { ...DEFAULT_OPTIONS, ...options }
// console.log({ mergedOptions })
if (mergedOptions.shouldUseRequestAnimationFrame === true) {
// console.debug('[tests] requiring raf')
// In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet.
// We don't polyfill it in the browser--this is user's responsibility.
require('raf').polyfill(global)
// console.debug('[tests] required raf')
}
if (mergedOptions.shouldUseEnzyme === true) {
// console.debug('[tests] requiring enzyme')
require('./enzyme')
// console.debug('[tests] required enzyme')
}
if (mergedOptions.shouldExtendExpectWithDocumentObjectModel === true) {
// console.debug('[tests] requiring extendDocumentObjectModel')
require('./extendDocumentObjectModel')
// console.debug('[tests] required extendDocumentObjectModel')
}
if (mergedOptions.shouldUseReactTestingLibrary === true) {
// console.debug('[tests] requiring reactTestingLibrary')
require('./reactTestingLibrary')
// console.debug('[tests] required reactTestingLibrary')
}
// has to be after test lib, since it is bad on window
if (mergedOptions.shouldUseJsdom === true) {
// console.debug('[tests] requiring jest')
require('./jsdom')
// console.debug('[tests] required jest')
}
if (mergedOptions.shouldUseExotic === true) {
// console.debug('[tests] requiring extendExotic')
require('./extendExotic')
// console.debug('[tests] required extendExotic')
}
if (mergedOptions.shouldUseStoryBook === true) {
console.warn('@todo shouldUseStoryBook was used, not implemented yet')
}
if (mergedOptions.shouldUseSonarQube === true) {
console.warn('shouldUseSonarQube was used, not implemented yet')
}
}