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

fix: allow selecting tests and files containing regexp special characters #32

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Nov 7, 2019

This issue was quite annoying :p Jest interprets pattern as regexp so if we select a test name containing a special character this gets (currently) interpreted in a wrong way by jest. This fixes the problem

@thymikee thymikee requested review from rogeliog and SimenB and removed request for rogeliog November 7, 2019 13:11
@SimenB
Copy link
Member

SimenB commented Nov 7, 2019

Is this an issue in jest itself? Also, just for test name not file name?

@Andarist
Copy link
Contributor Author

Andarist commented Nov 7, 2019

I'm going to answer based on my limited knowledge about jest

Is this an issue in jest itself?

I don't think so, from what I understand what gets passed to that jest's callback could actually be a regexp~ pattern and would be interpreted as regexp by jest. We call it in here after selecting from the list though and this is already "resolved" string which we don't want to actually be interpreted as regexp (but it will, so we need to provide a regexp pattern with special characters escaped).

just for test name not file name?

When preparing this I thought about this briefly but concluded that file patterns contain seperator (/) which is a special regexp character so it has to be handled already by jest. But when I think about it now - the problem must be the same, but maybe separators are somehow special-cased by jest? Not sure - gonna investigate this in a moment. Thanks for mentioning this!

@Andarist Andarist force-pushed the fix/selecting-test-name-with-regexp-special-character branch from 1506d0f to 72c9e62 Compare November 7, 2019 23:25
@Andarist
Copy link
Contributor Author

Andarist commented Nov 7, 2019

Ok, I've found out that path separator is indeed special-cased by jest here - https://github.com/facebook/jest/blob/70bed722d6b68456ffcb7df70d4a9b59bcea3d8a/packages/jest-core/src/lib/update_global_config.ts#L34-L37

I've implemented this fix for selecting file names as well. It's past midnight right now and I'm not sure if I will have time to write tests for this tomorrow, but I'd appreciate a code review on the logic when you get time. Maybe something else will come to your mind while I will be working on tests.

@Andarist Andarist force-pushed the fix/selecting-test-name-with-regexp-special-character branch from 72c9e62 to 0c50cc5 Compare November 7, 2019 23:28
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful, thank you! Just a test and this should be good. Thanks for taking the time to investigate 👍

yarn.lock Outdated Show resolved Hide resolved
const stdout = { columns: 80, write: jest.fn() };
const pluginTester = (Plugin, options = {}) => {
const stdout = {
columns: (options.stdout || {}).columns || 80,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional chaining plz 😉


expect(updateConfigAndRun).toHaveBeenCalledWith({
mode: 'watch',
testPathPattern: 'ing\\.js',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should have included more - width is set to 40 after all. But this is a separate issue that could be investigated.

@Andarist
Copy link
Contributor Author

Andarist commented Nov 9, 2019

@SimenB I've added more tests and made some minor changes - so a re-review would be appreciated.

@Andarist Andarist requested a review from SimenB November 9, 2019 12:03
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonderful, thank you! I'd like @rogeliog to take a look as well

@Andarist
Copy link
Contributor Author

Andarist commented Nov 9, 2019

Sure, no problem.

Copy link
Member

@rogeliog rogeliog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this

@SimenB SimenB changed the title Fix issue with not being able to select a test name containing regexp special character fix: allow selecting tests and files containing regexp special characters Nov 9, 2019
@SimenB SimenB merged commit e6f4851 into jest-community:master Nov 9, 2019
@Andarist Andarist deleted the fix/selecting-test-name-with-regexp-special-character branch November 9, 2019 16:17
@SimenB
Copy link
Member

SimenB commented Nov 9, 2019

Published as 0.4.1

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 this pull request may close these issues.

None yet

3 participants