-
Notifications
You must be signed in to change notification settings - Fork 356
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
Enable typescript for jest tests #3440
Conversation
@karelhala Cannot apply the following label because they are not recognized: build |
8ff9176
to
9c96429
Compare
Restarting tests |
config/jest.setup.js
Outdated
@@ -0,0 +1,10 @@ | |||
window.angular = require('angular'); | |||
window.Rx = require('rxjs'); | |||
window.$ = require('../vendor/assets/bower/bower_components/jquery/dist/jquery'); |
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.
require('jquery')
now :) (#3450 got merged)
jest.config.js
Outdated
@@ -5,5 +5,14 @@ module.exports = { | |||
__testing__: true | |||
}, | |||
roots: ['app/javascript'], | |||
testMatch: ['**/*.test.js'] | |||
setupFiles: ['./config/jest.setup.js'], | |||
testRegex: '(/__tests__/.*|(\\.|/)(test))\\.(js?|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.
Would it make sense to name the dir specs/
as with old js? Or is this a new convention to use __tests__/
?
(I'm fine with either.)
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.
Also, we may want to support *.spec.js
since that's what SUI does.
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.
You can either put it into new folder __tests__
or leave them in any folder, that is jus optional. However you have to name your file ${whatever}.test.[js|ts]
this is because there might be clash between jasmine old tests and new one's written in jest.
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.
Or no, there is root directory, I'll add option to use spec or test as part of file.
9c96429
to
903c282
Compare
jest.config.js
Outdated
@@ -5,5 +5,14 @@ module.exports = { | |||
__testing__: true | |||
}, | |||
roots: ['app/javascript'], | |||
testMatch: ['**/*.test.js'] | |||
setupFiles: ['./config/jest.setup.js'], | |||
testRegex: '(/__tests__/.*|(\\.|_|/)(test|spec))\\.(js?|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.
\.(js?|ts?)$
will match .j
and .js
but not .jsx
;)
I guess you wanted \.(jsx?|tsx?)$
?
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.
You are totally right.
903c282
to
2565873
Compare
Checked commit karelhala@2565873 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 |
LGTM, waiting for green :). Tested the regex, looks like it currently matches only
.. so perfect :) (It would also match |
Adds support for typescript files for Jest
As we support typescript for writing packs we should support jest to work with TS files as well. This PR enables such thing with adding
ts-jest
package and changing jest config to work with both TS and JS files.babel-jest
ts-jest