-
Notifications
You must be signed in to change notification settings - Fork 8
Jest implementation and test on counter example #324
Conversation
a46c1e4
to
573fa1f
Compare
config/babelrc.js
Outdated
@@ -28,6 +29,7 @@ export default (env, options) => ({ | |||
plugins: [ | |||
// Make optional the explicit import of React in JSX files | |||
pluginReactRequire, | |||
pluginTransformRuntime, |
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.
Why ?
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.
That's a good question. It should work without it @LucasPerso
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.
@johangirod We tried to remove it and it did not transpile tests written in ES6
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.
Can we test it again ? Maybe it was for another reason ? And in any case, we should at least add it only for the test environment.
@@ -6,15 +6,17 @@ import path from 'path'; | |||
import rimraf from 'rimraf'; | |||
import { spawn } from 'child_process'; | |||
import fs from 'fs'; | |||
import { spawn as npmRunSpawn } from 'npm-run'; |
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.
Why not use yarn run with process_child.spawn ?
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.
Using npm-run guarantees us that it will run jest from vitamin's node_modules. If we don't use it, it can causes issues when jest is called from another place (such as linked dependencies or global install)
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.
Well, I wasn't a big fan of using a test
script inside the package.json
of vitaminjs, because, in this context, we are not using it for testing vitaminjs but for testing the application itself.
But, now that you're pointing it, I realised that we could use the yarn jest
command, that comes directly with yarn, without needing to modify the package.json
, and with no extra dependencies.
What do you think, @LucasPerso @christophehurpeau ?
config/jest/jestrc.js
Outdated
}, | ||
transformIgnorePatterns: ['/node_modules/(?!vitaminjs).*'], | ||
moduleNameMapper: { | ||
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/__mocks__/fileMock.js', |
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.
Is it the same than url-loader
extensions?
https://github.com/Evaneos/vitaminjs/blob/master/config/build/webpack.config.common.js#L71
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.
Yeup, it should be the same as url loader. Maybe we can extract them into a variable and import it into the url-loader and here ?
config/jest/jestrc.js
Outdated
transformIgnorePatterns: ['/node_modules/(?!vitaminjs).*'], | ||
moduleNameMapper: { | ||
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/__mocks__/fileMock.js', | ||
'\\.(css|less)$': 'identity-obj-proxy', |
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.
Why do we support less
there OR why do we support only css
and less
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.
That's a pretty good question :)
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.
Since we do not support others stylesheets than CSS, I suggest we keep CSS only.
package.json
Outdated
@@ -4,7 +4,7 @@ | |||
"description": "The build toolchain against JavaScript Fatigue", | |||
"main": "./src/shared/index.js", | |||
"scripts": { | |||
"test": "yarn run lint", | |||
"test": "yarn run 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.
so yarn
is a dependence of vitamin
?
wouldn't be better to start test with ./node_modules/.bin/jest …
bin/vitamin.js
Outdated
commonBuild(webpackConfigTest, 'tests', { hot, dev: DEV }, launchTest); | ||
const test = (args) => { | ||
spawn( | ||
vitaminResolve('node_modules', '.bin', '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.
should be appResolve, no?
package.json
Outdated
"isomorphic-style-loader": "^1.1.0", | ||
"jest": "^19.0.2", |
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.
jest must be a peer dependency, else it won't be in .bin
if I remember right
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.
dependencies binaries are included in ./node_modules/.bin
as well.
@LucasPerso @johangirod confirmation?
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.
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.
But we can consider going to node_modules/jest/bin/jest.js
instead :)
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 installing jest-cli
with node_modules/jest-cli/bin/jest.js
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.
ok you mean in my_project/node_modules/.bin
i thought to resolve it directly from my_project/node_modules/vitaminsjs/node_modules/.bin
with vitaminResolve
but we already having this conversation ^^
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.
@christophehurpeau, correct me if I'm mistaken, but the issue explicitely state that
[CLI dependencies] will be stored inside {A}/node_modules/B/node_modules/.bin/*
If we use npmRun
, the issue is already taking care of, as we are going to search in vitaminjs/node_modules
, and if not found resolve to the next parent directory.
.eslintrc.json
Outdated
@@ -2,7 +2,8 @@ | |||
"extends": "airbnb", | |||
"parser": "babel-eslint", | |||
"env": { | |||
"es6": true | |||
"es6": true, | |||
"jest": true |
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.
perhaps you can only say you're in a jest env in the test directory ?
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.
👍
I think it should be removed from here, and added at the discretion of the test files. Either by adding a .eslintrc.json inside the test
folder, or simply by adding
/* eslint env jest */
at the beginning of the test file.
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.
👍 let's do that, it will make more sense since env:jest
is not true most of the time
bin/vitamin.js
Outdated
npmRunSpawn( | ||
'jest', | ||
spawn( | ||
vitaminResolve('node_modules', '.bin', '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.
Mmmmh, it's not guaranteed to work, and it should not work if jest is not installed inside vitaminJS.
It's better to use just spawn(yarn jest
), and then, add
'--' before the list of arguments.
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.
But in the same time, I'm not sure it needs to be changed.
The advantage of npmRunSpawn
over yarn jest
beeing:
- It does not require yarn to be globally installed to work
- It spawn only one child process, unlike yarn, who will spawn one for itself and one for the command
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.
running (yarn || npm) run jest
requires the user to add "jest": "jest"
in its scripts. It's better to call node_modules/.bin/jest
I think
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.
In any case, yarn jest
does not seem to work even if yarn is installed globally.
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.
- 👍
yarn
should not be required to use any part ofvitamin
. - and i agree with you @christophehurpeau, seems better to use directly vitamin's
node_modules/.bin/jest
since we ship with it. (i don't know why yet, but it seems to have some drawbacks
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.
node_modules/.bin/jest
The problem is that jest
can be installed inside vitaminJS node_modules (in the case of a link, or when the user also installed jest with another version), or inside the app node_modules (in case of standard installation).
If we call node_modules/.bin/jest
we should resolve "à la" npm, in order to prevent issues with that.
That's exactly what npmRun.spawn
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.
when you resolve it with npmRun
what is the sequence with local, global and dependencies?
package.json
Outdated
@@ -4,7 +4,6 @@ | |||
"description": "The build toolchain against JavaScript Fatigue", | |||
"main": "./src/shared/index.js", | |||
"scripts": { | |||
"test": "yarn run lint", |
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.
This script should be use in the future for running test on vitaminJS.
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.
Yes, but it will be something like
"test": "yarn run lint && yarn jest",
So no need to remove it, especially since it's use by circleci :)
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.
My bad then ! I'll add it again ;)
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.
I'm not sure if it's a good practice to lint when you run test...
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.
should be circleci to invoke the first one then the second no?
Todo :
|
package.json
Outdated
"babel-eslint": "^7.2.1", | ||
"eslint": "^3.19.0", | ||
"eslint-config-airbnb": "^14.1.0", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-jsx-a11y": "^4.0.0", | ||
"eslint-plugin-react": "^6.10.3", | ||
"lerna": "^2.0.0-rc.4", |
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.
Y a deux fois Lerna :)
|
||
There you go. You can launch jest with | ||
``` | ||
vitaminjs test |
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.
C'est sensé être vitamin test
si je ne m'abuse
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.
Nop, pour l'instant vitamin cli est installé sous vitaminjs :(
https://github.com/Evaneos/vitaminjs-cli/blob/master/package.json#L7
Ca va changer, mais en attendant, je met ça comme ça :)
Moved to #364 |
Should solve #324