-
-
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
[jest-each] Migrate to Typescript #8007
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4a9a7fe
Add ts setup files
mattphillips e5469ce
Migrate js src to ts
mattphillips aed760d
Migrate jest-each tests to ts;
mattphillips 141ff99
Add changelog entry
mattphillips b99365a
Remove jest-each ts-ignore in jest-circus
mattphillips File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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 | ||||
---|---|---|---|---|---|---|
|
@@ -4,7 +4,6 @@ | |||||
* This source code is licensed under the MIT license found in the | ||||||
* LICENSE file in the root directory of this source tree. | ||||||
* | ||||||
* @flow | ||||||
*/ | ||||||
|
||||||
import util from 'util'; | ||||||
|
@@ -15,8 +14,8 @@ import {ErrorWithStack} from 'jest-util'; | |||||
|
||||||
type Table = Array<Array<any>>; | ||||||
type PrettyArgs = { | ||||||
args: Array<mixed>, | ||||||
title: string, | ||||||
args: Array<any>; | ||||||
title: string; | ||||||
}; | ||||||
|
||||||
const EXPECTED_COLOR = chalk.green; | ||||||
|
@@ -26,7 +25,7 @@ const PRETTY_PLACEHOLDER = '%p'; | |||||
const INDEX_PLACEHOLDER = '%#'; | ||||||
|
||||||
export default (cb: Function, supportsDone: boolean = true) => (...args: any) => | ||||||
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.
Suggested change
or at least |
||||||
function eachBind(title: string, test: Function, timeout: number): void { | ||||||
function eachBind(title: string, test: Function, timeout?: number): void { | ||||||
if (args.length === 1) { | ||||||
const [tableArg] = args; | ||||||
|
||||||
|
@@ -122,19 +121,20 @@ export default (cb: Function, supportsDone: boolean = true) => (...args: any) => | |||||
); | ||||||
}; | ||||||
|
||||||
const isTaggedTemplateLiteral = array => array.raw !== undefined; | ||||||
const isEmptyTable = table => table.length === 0; | ||||||
const isEmptyString = str => typeof str === 'string' && str.trim() === ''; | ||||||
const isTaggedTemplateLiteral = (array: any) => array.raw !== undefined; | ||||||
const isEmptyTable = (table: Array<any>) => table.length === 0; | ||||||
const isEmptyString = (str: string) => | ||||||
typeof str === 'string' && str.trim() === ''; | ||||||
|
||||||
const getPrettyIndexes = placeholders => | ||||||
placeholders.reduce((indexes, placeholder, index) => { | ||||||
const getPrettyIndexes = (placeholders: RegExpMatchArray) => | ||||||
placeholders.reduce((indexes: Array<number>, placeholder, index) => { | ||||||
if (placeholder === PRETTY_PLACEHOLDER) { | ||||||
indexes.push(index); | ||||||
} | ||||||
return indexes; | ||||||
}, []); | ||||||
|
||||||
const arrayFormat = (title, rowIndex, ...args) => { | ||||||
const arrayFormat = (title: string, rowIndex: number, ...args: Array<any>) => { | ||||||
const placeholders = title.match(SUPPORTED_PLACEHOLDERS) || []; | ||||||
const prettyIndexes = getPrettyIndexes(placeholders); | ||||||
|
||||||
|
@@ -164,13 +164,15 @@ const arrayFormat = (title, rowIndex, ...args) => { | |||||
); | ||||||
}; | ||||||
|
||||||
type Done = () => {}; | ||||||
|
||||||
const applyRestParams = ( | ||||||
supportsDone: boolean, | ||||||
params: Array<any>, | ||||||
test: Function, | ||||||
) => | ||||||
supportsDone && params.length < test.length | ||||||
? done => test(...params, done) | ||||||
? (done: Done) => test(...params, done) | ||||||
: () => test(...params); | ||||||
|
||||||
const getHeadingKeys = (headings: string): Array<string> => | ||||||
|
@@ -190,10 +192,15 @@ const buildTable = ( | |||||
), | ||||||
); | ||||||
|
||||||
const getMatchingKeyPaths = title => (matches, key) => | ||||||
matches.concat(title.match(new RegExp(`\\$${key}[\\.\\w]*`, 'g')) || []); | ||||||
const getMatchingKeyPaths = (title: string) => ( | ||||||
matches: Array<string>, | ||||||
key: string, | ||||||
) => matches.concat(title.match(new RegExp(`\\$${key}[\\.\\w]*`, 'g')) || []); | ||||||
|
||||||
const replaceKeyPathWithValue = data => (title, match) => { | ||||||
const replaceKeyPathWithValue = (data: any) => ( | ||||||
title: string, | ||||||
match: string, | ||||||
) => { | ||||||
const keyPath = match.replace('$', '').split('.'); | ||||||
const value = getPath(data, keyPath); | ||||||
|
||||||
|
@@ -209,12 +216,17 @@ const interpolate = (title: string, data: any) => | |||||
.reduce(replaceKeyPathWithValue(data), title); | ||||||
|
||||||
const applyObjectParams = (supportsDone: boolean, obj: any, test: Function) => | ||||||
supportsDone && test.length > 1 ? done => test(obj, done) : () => test(obj); | ||||||
supportsDone && test.length > 1 | ||||||
? (done: Done) => test(obj, done) | ||||||
: () => test(obj); | ||||||
|
||||||
const pluralize = (word: string, count: number) => | ||||||
word + (count === 1 ? '' : 's'); | ||||||
|
||||||
const getPath = (o: Object, [head, ...tail]: Array<string>) => { | ||||||
const getPath = ( | ||||||
o: {[key: string]: any}, | ||||||
[head, ...tail]: Array<string>, | ||||||
): any => { | ||||||
if (!head || !o.hasOwnProperty || !o.hasOwnProperty(head)) return o; | ||||||
return getPath(o[head], tail); | ||||||
}; |
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 | ||||
---|---|---|---|---|---|---|
|
@@ -4,29 +4,19 @@ | |||||
* This source code is licensed under the MIT license found in the | ||||||
* LICENSE file in the root directory of this source tree. | ||||||
* | ||||||
* @flow | ||||||
*/ | ||||||
|
||||||
import bind from './bind'; | ||||||
type Global = NodeJS.Global; | ||||||
|
||||||
type GlobalCallbacks = { | ||||||
test(title: string, test: Function): void, | ||||||
xtest(title: string, test: Function): void, | ||||||
it(title: string, test: Function): void, | ||||||
fit(title: string, test: Function): void, | ||||||
xit(title: string, test: Function): void, | ||||||
describe(title: string, test: Function): void, | ||||||
fdescribe(title: string, test: Function): void, | ||||||
xdescribe(title: string, test: Function): void, | ||||||
}; | ||||||
import bind from './bind'; | ||||||
|
||||||
const install = (g: GlobalCallbacks, ...args: Array<mixed>) => { | ||||||
const test = (title: string, test: Function, timeout: number) => | ||||||
const install = (g: Global, ...args: Array<any>) => { | ||||||
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.
Suggested change
|
||||||
const test = (title: string, test: Function, timeout?: number) => | ||||||
bind(g.test)(...args)(title, test, timeout); | ||||||
test.skip = bind(g.test.skip)(...args); | ||||||
test.only = bind(g.test.only)(...args); | ||||||
|
||||||
const it = (title: string, test: Function, timeout: number) => | ||||||
const it = (title: string, test: Function, timeout?: number) => | ||||||
bind(g.it)(...args)(title, test, timeout); | ||||||
it.skip = bind(g.it.skip)(...args); | ||||||
it.only = bind(g.it.only)(...args); | ||||||
|
@@ -35,7 +25,7 @@ const install = (g: GlobalCallbacks, ...args: Array<mixed>) => { | |||||
const fit = bind(g.fit)(...args); | ||||||
const xtest = bind(g.xtest)(...args); | ||||||
|
||||||
const describe = (title: string, suite: Function, timeout: number) => | ||||||
const describe = (title: string, suite: Function, timeout?: number) => | ||||||
bind(g.describe, false)(...args)(title, suite, timeout); | ||||||
describe.skip = bind(g.describe.skip, false)(...args); | ||||||
describe.only = bind(g.describe.only, false)(...args); | ||||||
|
@@ -45,10 +35,9 @@ const install = (g: GlobalCallbacks, ...args: Array<mixed>) => { | |||||
return {describe, fdescribe, fit, it, test, xdescribe, xit, xtest}; | ||||||
}; | ||||||
|
||||||
const each = (...args: Array<mixed>) => install(global, ...args); | ||||||
const each = (...args: Array<any>) => install(global, ...args); | ||||||
|
||||||
each.withGlobal = (g: GlobalCallbacks) => (...args: Array<mixed>) => | ||||||
install(g, ...args); | ||||||
each.withGlobal = (g: Global) => (...args: Array<any>) => install(g, ...args); | ||||||
|
||||||
export {bind}; | ||||||
|
||||||
|
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,13 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "build" | ||
}, | ||
"references": [ | ||
{"path": "../jest-get-type"}, | ||
{"path": "../jest-types"}, | ||
{"path": "../jest-util"}, | ||
{"path": "../pretty-format"} | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
if it doesn't cause huge issues 🙂