-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Consider stripping a leading and trailing slash from configuration property keys #6910
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
Comments
Definitely! Right now we have quite a bit of Wanna send a PR for it? |
For what it's worth: I've written a failing test for the master...alexanderbird:support-regexp-configuration-keys Not sure when I'll be able to come back to this, so if anyone else wants to run with it don't let me stop you :) Incidentally, that unit test I added to is looking pretty long, is there any reason I shouldn't split it up into separate tests for each expectation? |
Feel free to split it up into logical parts! |
@SimenB it looks like RegExp literals get I can update the documentation to warn about this, but before I continue I want to confirm that's an ok solution. I've written a minimal solution to normalize the strings: |
Can we change that? |
No,sorry, I thought this was clear. Object keys are always strings. The string representation of a So this: module.exports = {
moduleNameMapper: {
[/foo/]: 'bar',
}
} Equivalent to: module.exports = {
moduleNameMapper: {
'/foo/': 'bar',
}
} Would be interpreted as this: module.exports = {
moduleNameMapper: {
'foo': 'bar',
}
} |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days. |
This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🚀 Feature Proposal
Consider stripping a leading and trailing slash (
/
) from configuration property keys if the key represents a regular expression.Motivation
This would allow to use an actual regular expression in several configuration locations. This adds syntax highlighting and linting capabilities to regular expressions used in Jest configuration, and removes the need to use double backslashes.
Example
From the moduleNameMapper example configuration
In JavaScript, this could be written as
It would be great if the
.source
could simply be removedHowever, the last example won’t work currently, because
RegExp.prototype.toString()
adds a preceding and a trailing slash.Pitch
This implements a feature regarding the parsing of
jest.config.js
.The text was updated successfully, but these errors were encountered: