Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Jest implementation and test on counter example #324

Closed
wants to merge 9 commits into from
Closed

Conversation

LucasPerso
Copy link
Contributor

@LucasPerso LucasPerso commented Apr 4, 2017

Should solve #324

@LucasPerso LucasPerso force-pushed the add-jest branch 3 times, most recently from a46c1e4 to 573fa1f Compare April 4, 2017 15:34
@LucasPerso LucasPerso modified the milestone: 2.0 Apr 4, 2017
@@ -28,6 +29,7 @@ export default (env, options) => ({
plugins: [
// Make optional the explicit import of React in JSX files
pluginReactRequire,
pluginTransformRuntime,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why ?

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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';
Copy link
Contributor

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 ?

Copy link
Contributor Author

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)

Copy link
Contributor

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 ?

},
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',
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

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 ?

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',
Copy link
Member

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

Copy link
Contributor

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 :)

Copy link
Contributor Author

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",
Copy link
Member

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'),
Copy link
Contributor

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",
Copy link
Contributor

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

Copy link
Member

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

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 :)

Copy link
Contributor

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

Copy link
Member

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 ^^

Copy link
Contributor

@johangirod johangirod Apr 5, 2017

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
Copy link
Contributor

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 ?

Copy link
Contributor

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.

Copy link
Member

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'),
Copy link
Contributor

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.

Copy link
Contributor

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

@christophehurpeau ?

Copy link
Contributor

@christophehurpeau christophehurpeau Apr 5, 2017

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

Copy link
Contributor Author

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.

Copy link
Member

@alepee alepee Apr 5, 2017

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 of vitamin.
  • 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

Copy link
Contributor

@johangirod johangirod Apr 5, 2017

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.

Copy link
Member

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",
Copy link
Contributor Author

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.

Copy link
Contributor

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 :)

Copy link
Contributor Author

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 ;)

Copy link
Contributor

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...

Copy link
Member

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?

@johangirod
Copy link
Contributor

Todo :

  • Remove breaking
  • Add a vitaminjs-jest package which acts as a feature flag
  • Add a plugin key which can contains vitaminjs-plugin-jest

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",
Copy link
Contributor Author

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
Copy link
Contributor Author

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

Copy link
Contributor

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 :)

@LucasPerso
Copy link
Contributor Author

Moved to #364

@LucasPerso LucasPerso closed this May 11, 2017
@LucasPerso LucasPerso deleted the add-jest branch May 12, 2017 09:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants