-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: migrate the Config
type test to TSTyche
#14687
Changes from all commits
0affbde
a7db2f3
c6764f3
b4c152d
0b2c18d
ae6e67b
d5c8aed
b9e336d
14d452b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,115 +5,126 @@ | |
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {expectAssignable, expectNotAssignable} from 'tsd-lite'; | ||
import type {Config} from '@jest/types'; | ||
import {describe, expect, test} from 'tstyche'; | ||
import type {Config} from 'jest'; | ||
mrazauskas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
expectAssignable<Config.InitialOptions>({}); | ||
const config: Config = {}; | ||
|
||
expectAssignable<Config.InitialOptions>({ | ||
coverageThreshold: { | ||
'./src/api/very-important-module.js': { | ||
branches: 100, | ||
functions: 100, | ||
lines: 100, | ||
statements: 100, | ||
}, | ||
'./src/components/': { | ||
branches: 40, | ||
statements: 40, | ||
}, | ||
'./src/reducers/**/*.js': { | ||
statements: 90, | ||
}, | ||
global: { | ||
branches: 50, | ||
functions: 50, | ||
lines: 50, | ||
statements: 50, | ||
}, | ||
}, | ||
projects: [ | ||
// projects can be globs or objects | ||
'./src/**', | ||
{ | ||
displayName: 'A Project', | ||
rootDir: './src/components', | ||
}, | ||
], | ||
}); | ||
describe('Config', () => { | ||
test('coverageThreshold', () => { | ||
expect(config).type.toBeAssignable({ | ||
coverageThreshold: { | ||
'./src/api/very-important-module.js': { | ||
branches: 100, | ||
functions: 100, | ||
lines: 100, | ||
statements: 100, | ||
}, | ||
'./src/components/': { | ||
branches: 40, | ||
statements: 40, | ||
}, | ||
'./src/reducers/**/*.js': { | ||
statements: 90, | ||
}, | ||
global: { | ||
branches: 50, | ||
functions: 50, | ||
lines: 50, | ||
statements: 50, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
const doNotFake: Array<Config.FakeableAPI> = [ | ||
'Date', | ||
'hrtime', | ||
'nextTick', | ||
'performance', | ||
'queueMicrotask', | ||
'requestAnimationFrame', | ||
'cancelAnimationFrame', | ||
'requestIdleCallback', | ||
'cancelIdleCallback', | ||
'setImmediate', | ||
'clearImmediate', | ||
'setInterval', | ||
'clearInterval', | ||
'setTimeout', | ||
'clearTimeout', | ||
]; | ||
test('fakeTimers', () => { | ||
const doNotFake = [ | ||
'Date' as const, | ||
'hrtime' as const, | ||
'nextTick' as const, | ||
'performance' as const, | ||
'queueMicrotask' as const, | ||
'requestAnimationFrame' as const, | ||
'cancelAnimationFrame' as const, | ||
'requestIdleCallback' as const, | ||
'cancelIdleCallback' as const, | ||
'setImmediate' as const, | ||
'clearImmediate' as const, | ||
'setInterval' as const, | ||
'clearInterval' as const, | ||
'setTimeout' as const, | ||
'clearTimeout' as const, | ||
Comment on lines
+42
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we have to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I work on one idea which could improve this in the future. For now this is an assignability test and that is how it currently works. I mean, it works and it tests the right thing! That is very good for the first release of TSTyche. And future will bring in improvements for sure. |
||
]; | ||
|
||
expectAssignable<Config.InitialOptions>({ | ||
fakeTimers: { | ||
advanceTimers: true, | ||
doNotFake, | ||
enableGlobally: true, | ||
now: 1_483_228_800_000, | ||
timerLimit: 1000, | ||
}, | ||
}); | ||
expect(config).type.toBeAssignable({ | ||
fakeTimers: { | ||
advanceTimers: true, | ||
Comment on lines
+59
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comparing inferred type with and inferred type. Looks simple, but that was not possible with |
||
doNotFake, | ||
enableGlobally: true, | ||
now: 1_483_228_800_000, | ||
timerLimit: 1000, | ||
}, | ||
}); | ||
|
||
expectAssignable<Config.InitialOptions>({ | ||
fakeTimers: { | ||
advanceTimers: 40, | ||
now: Date.now(), | ||
}, | ||
}); | ||
expect(config).type.toBeAssignable({ | ||
fakeTimers: { | ||
advanceTimers: 40, | ||
now: Date.now(), | ||
}, | ||
}); | ||
|
||
expectNotAssignable<Config.InitialOptions>({ | ||
fakeTimers: { | ||
now: new Date(), | ||
}, | ||
}); | ||
expect(config).type.not.toBeAssignable({ | ||
fakeTimers: { | ||
now: new Date(), | ||
}, | ||
}); | ||
|
||
expectAssignable<Config.InitialOptions>({ | ||
fakeTimers: { | ||
enableGlobally: true, | ||
legacyFakeTimers: true as const, | ||
}, | ||
}); | ||
expect(config).type.toBeAssignable({ | ||
fakeTimers: { | ||
enableGlobally: true, | ||
legacyFakeTimers: true as const, | ||
}, | ||
}); | ||
|
||
expectNotAssignable<Config.InitialOptions>({ | ||
fakeTimers: { | ||
advanceTimers: true, | ||
legacyFakeTimers: true as const, | ||
}, | ||
}); | ||
expect(config).type.not.toBeAssignable({ | ||
fakeTimers: { | ||
advanceTimers: true, | ||
legacyFakeTimers: true as const, | ||
}, | ||
}); | ||
|
||
expectNotAssignable<Config.InitialOptions>({ | ||
fakeTimers: { | ||
doNotFake, | ||
legacyFakeTimers: true as const, | ||
}, | ||
}); | ||
expect(config).type.not.toBeAssignable({ | ||
fakeTimers: { | ||
doNotFake, | ||
legacyFakeTimers: true as const, | ||
}, | ||
}); | ||
|
||
expectNotAssignable<Config.InitialOptions>({ | ||
fakeTimers: { | ||
legacyFakeTimers: true as const, | ||
now: 1_483_228_800_000, | ||
}, | ||
}); | ||
expect(config).type.not.toBeAssignable({ | ||
fakeTimers: { | ||
legacyFakeTimers: true as const, | ||
now: 1_483_228_800_000, | ||
}, | ||
}); | ||
|
||
expect(config).type.not.toBeAssignable({ | ||
fakeTimers: { | ||
legacyFakeTimers: true as const, | ||
timerLimit: 1000, | ||
}, | ||
}); | ||
}); | ||
|
||
expectNotAssignable<Config.InitialOptions>({ | ||
fakeTimers: { | ||
legacyFakeTimers: true as const, | ||
timerLimit: 1000, | ||
}, | ||
test('projects', () => { | ||
expect(config).type.toBeAssignable({ | ||
projects: [ | ||
// projects can be globs or objects | ||
'./src/**', | ||
{ | ||
displayName: 'A Project', | ||
rootDir: './src/components', | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"testFileMatch": ["**/packages/jest-types/__typetests__/config.test.ts"] | ||
} |
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.
This looks clumsy for now, but the diff is more readable.