Skip to content
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

Custom Jest matchers causing issues with Jest upgrade #2671

Closed
spalger opened this issue Dec 15, 2019 · 4 comments · Fixed by #2673
Closed

Custom Jest matchers causing issues with Jest upgrade #2671

spalger opened this issue Dec 15, 2019 · 4 comments · Fixed by #2673
Assignees

Comments

@spalger
Copy link
Contributor

spalger commented Dec 15, 2019

We're unable to upgrade jest because the custom jest matcher types in EUI are conflicting with the version of Jest we're trying to install. I don't think there's a good reason for these extensions personally, and would prefer if they could just be implemented as helper functions so that the types could be removed. Thoughts?

Kibana Jest upgrade: elastic/kibana#53079
Error from https://kibana-ci.elastic.co/job/elastic+kibana+pipeline-pull-request/15622/execution/node/128/log/

03:42:42  kibana: node_modules/@elastic/eui/eui.d.ts(5656,20): error TS2428: All declarations of 'Matchers' must have identical type parameters.
03:42:42  kibana: node_modules/@types/jest/index.d.ts(729,15): error TS2428: All declarations of 'Matchers' must have identical type parameters.

Problematic module:

declare module '@elastic/eui/src/components/datagrid/data_grid.test' {
	 global {
	    namespace jest {
	        interface Matchers<R> {
	            toBeEuiPopover(): R;
	            euiPopoverToBeOpen(): R;
	        }
	    }
	}
	export {};
}
@chandlerprall
Copy link
Contributor

Indeed. Ideally, EUI should not be shipping any test-related code (except for helper utilities which don't exist yet). This includes the .test. files themselves, and their current inclusion in the eui.d.ts - as described above - which is an artifact of our dts generation. There's likely a small configuration change to avoid bundling these definitions.

I'll address this tomorrow (Monday), but likely won't be able to get that change into Kibana until later in the week as we've got one EUI upgrade already pending elastic/kibana#52688

@chandlerprall chandlerprall self-assigned this Dec 15, 2019
@spalger
Copy link
Contributor Author

spalger commented Dec 16, 2019

It's possible that a simple config change will fix this, but I'd be kind of surprised. I think it would be much simpler to remove these as extensions of Jest's expect object and instead have helper functions that test if something is an EuiPopover or that the EuiPopover is open. These helpers would only be imported into the files that they're needed in rather than being attached to the expect global, and all would be right in the world 😉

@chandlerprall
Copy link
Contributor

@spalger looks like a config change does solve the immediate issue - #2673

We use dts-generator (with some post-processing) to generate our typescript definitions file. That package scans the filesystem for typescript files from which it extracts the types. This included data_grid.test.tsx which provides the jest namespace, conflicting in Kibana.

@spalger
Copy link
Contributor Author

spalger commented Dec 22, 2019

Thanks @chandlerprall!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants