-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Replace Karma + Mocha with Jest #824
Conversation
I support this PR, however the coverage report is very poor. I also tried to implement Jest here johnsardine/vue-jest and the coverage is a little better, however not perfect. I would like you to take a look, if you can. I have a fork of jest-vue-preprocessor which provides babel sourcemap to jest-transform. I think the coverage should be fixed before this is accepted. On my test, the coverage is off by one line, and this affects the sourcemap on the browser as well. I think the issue must come from the map that babel generates from the extracted .vue file script. Example of coverage in pure js file vs .vue file You can see the coverage execution count is off by one line. It should be one line above. I have put some hours into this without any progress other than the one I report here. I'll have to continue trying. |
Yeah you're right, we should get correct source mapping before merging. As you said, jest-vue-preprocessor doesn't return a map or have any logic to produce one. I'm going to play around with the vueify code and jest. |
@eddyerburgh Take a look at my fork of jest-vue-preprocessor, I've added (not in the best way, I admit) support for sourcemaps from babel. The thing is, the sourcemap is alright, but the coverage report is one line off, and it affects the source map on the web as well (So maybe the sourcemap is not alright after all) |
Is jest's license the same as the React's license? If it is, what is the implication? |
Great idea @eddyerburgh I was about to prepare the same PR :D It's a great step forward, @rit This so called React's license main purpose is to protect themselves from patent trolls that are suing them for crazy amounts of money each month. Dan explained it recently on twitter and I don't think we should consider it a blocker.. |
Before we merge we need to create a vue jest preprocessor that adds correct source mapping. There are plans for an official preprocessor, but I'm not sure how long it will be until it is published |
@johnsardine I've created a vue jest preprocessor that adds source maps - https://github.com/eddyerburgh/jest-vue. I tried to add to vire's existing library, but found it easier to create a fresh repo. In light of the patent drama, are we still happy to go ahead with replacing Karma and mocha with Jest? |
@eddyerburgh This is great, thanks a lot. I was testing it in my vue-jest sample project and so far seems to be working great. Will update a bigger project this week, if I encounter any issues I'll give you more feedback. |
Are people happy for me to fix conflicts and get this branch merged? @LinusBorg |
yes! |
conflicts fixed 👷 |
I think this PR is ready to merged. If anyone would like to test and give feedback it would be really useful 😀 |
I justed re-inited my project with the updated template and it looks like the issues I encountered the first time around are all solved 👏 Thanks @eddyerburgh |
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 found a few things, see above.
I also switched the base branch to "develop" since I already collected a few other changes there to release together.
Can you rebase the whole branch onto that latest "develop" branch?
docs/unit.md
Outdated
@@ -2,32 +2,8 @@ | |||
|
|||
An overview of the tools used by this boilerplate for unit testing: | |||
|
|||
- [Karma](https://karma-runner.github.io/): the test runner that launches browsers, runs the tests and reports the results to us. |
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.
@eddyerburgh Since we are leaving the karma setup available, I don't think we should remove this docs section.
We should rather leave that docs in, but prepend the page with new infos about jest.
template/package.json
Outdated
@@ -99,6 +114,32 @@ | |||
"webpack-hot-middleware": "^2.18.2", | |||
"webpack-merge": "^4.1.0" | |||
}, | |||
{{#unit}} |
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.
shouldn't that be {{#if_eq runner "jest"}}
?
template/src/router/index.js
Outdated
name: 'Hello', | ||
>>>>>>> 89c6fb18d4640afd6a5e89106b2493b4465d36a3 |
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 seem to have some leftovers from an older merge conflict...
template/test/unit/.eslintrc
Outdated
@@ -1,9 +1,5 @@ | |||
{ | |||
"env": { | |||
"mocha": 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.
since we are leaving the karma/mocha setup in place, the eslint config should probably also leave this in.
It should be conditional:
{
"env": {{{#if_eq runner "karma"}}
"mocha": true{{/if_eq}}{{#if_eq runner "jest"}}
"jest"{{/if_eq}}
}{{#if_eq runner "karma"}},
"globals": {
"expect": true,
"sinon": true,
"jest": true
}{{/if_eq}}
}
template/package.json
Outdated
@@ -5,7 +5,7 @@ | |||
"author": "{{ author }}", | |||
"private": true, | |||
"scripts": { | |||
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js", | |||
"dev": "node build/dev-server.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.
Hm, that merge doesn't look like it's supposed to I think ... the webpack-dev-server is new in the develop
branch, while yours was still built on the old dev-server
- so the former should stay in and the latter should go out.
Similarly, the other additions to package.json down in this file are all "bringing back" dependencies of the old dev-server.
But we might simply resolve this during / after the merge ..
Thanks for the hard work on this @eddyerburgh |
what's missing from https://github.com/vuejs/vue-test-utils/ to consider it non-beta? |
That's probably a question to ask the team working on that repository. |
was mistakenly removed during merge of #824
* re-merge (#1045) * Reference dev script in start script instead of copy pasting (#894) Less duplication FTW. * add version tag to config/index.js * stick to ES5 this file is not transpiled * Bumping Vue+VueRouter versions, some minor fixes. (#986) * switch hello-world tag to PascalCase (#951) * fix Es6 code issue. This file is not transpiled, so we should stick to ES5 * Fix bug in dev-server when a proxyTable entry is a string (#965) `options` can not be a `const` because it is modified if value is a string. * Fix casing * Revert 9befbfc * update to vue and vue-router latest version (#984) - vue 2.5 - vue-router 3.0 * Fix missing dependency bumps (#987) * switch hello-world tag to PascalCase (#951) * fix Es6 code issue. This file is not transpiled, so we should stick to ES5 * Fix bug in dev-server when a proxyTable entry is a string (#965) `options` can not be a `const` because it is modified if value is a string. * Fix casing * Revert 9befbfc * update to vue and vue-router latest version (#984) - vue 2.5 - vue-router 3.0 * fix missing dependency updates for * vue-template compiler * vue-loader * bump version string * Fix Unknown plugin istanbul error when no unit test (#785) * Fix Unknown plugin istanbul error when no unit test * simplify handlebars conditionals. * Revert "Fix Unknown plugin istanbul error when no unit test (#785)" (#1035) This reverts commit 14f2a92. * Remove unnecessary whitespaces (#1047) * fix(jest): fix Jest coverage directory (#1046) Explicitly set the coverage directory to match Karma and .gitignore * Fix typos and formatting (#1048) * re-add postcss-loader was mistakenly removed during merge of #824 * bumb version string in config * bumb version string in config in package.json
…uejs-templates#824) * refactor: replace karma and mocha with jest * refactor: remove webpack.test.conf * refactor: prompt jest instead of mocha and karma * feat(jest): add coverage reporting * docs(jest): update unit.md with details of jest * docs(jest): remove karma files from structure.md * docs(jest): replace details on Karma with details on Jest * docs: add missing period * docs(jest): replace karma with Jest in commands.md * docs(jest): update npm run unit bullet points * refactor: use module-resolver in place of jest moduleNameMapper * refactor: remove .vue extension from Hello import * test: include src files in test coverage * test: only ignore router/index in coverage if router option selected * chore: fix merge conflicts * chore: add MIT free Jest * Reference dev script in start script instead of copy pasting (vuejs-templates#894) Less duplication FTW. * feat: add karma option * refactor: use const in webpack.test.conf * add version tag to config/index.js * stick to ES5 this file is not transpiled * Bumping Vue+VueRouter versions, some minor fixes. (vuejs-templates#986) * switch hello-world tag to PascalCase (vuejs-templates#951) * fix Es6 code issue. This file is not transpiled, so we should stick to ES5 * Fix bug in dev-server when a proxyTable entry is a string (vuejs-templates#965) `options` can not be a `const` because it is modified if value is a string. * Fix casing * Revert 9befbfc * update to vue and vue-router latest version (vuejs-templates#984) - vue 2.5 - vue-router 3.0 * Fix missing dependency bumps (vuejs-templates#987) * switch hello-world tag to PascalCase (vuejs-templates#951) * fix Es6 code issue. This file is not transpiled, so we should stick to ES5 * Fix bug in dev-server when a proxyTable entry is a string (vuejs-templates#965) `options` can not be a `const` because it is modified if value is a string. * Fix casing * Revert 9befbfc * update to vue and vue-router latest version (vuejs-templates#984) - vue 2.5 - vue-router 3.0 * fix missing dependency updates for * vue-template compiler * vue-loader * bump version string * refactor: use jest module mapping * feat(jest): filter jest setup file * fix: fix trailing comma * docs: add Jest and Karma to unit section * fix: add Jest options if jest option * test: change env in .eslintrc * fix: remove merge trace * fix: merge package.json with develop * docs: split unit test docs into Jest and Karma * docs: add Karma and Jest to README * docs: reimplement karma files in structure.md
was mistakenly removed during merge of vuejs-templates#824
* re-merge (vuejs-templates#1045) * Reference dev script in start script instead of copy pasting (vuejs-templates#894) Less duplication FTW. * add version tag to config/index.js * stick to ES5 this file is not transpiled * Bumping Vue+VueRouter versions, some minor fixes. (vuejs-templates#986) * switch hello-world tag to PascalCase (vuejs-templates#951) * fix Es6 code issue. This file is not transpiled, so we should stick to ES5 * Fix bug in dev-server when a proxyTable entry is a string (vuejs-templates#965) `options` can not be a `const` because it is modified if value is a string. * Fix casing * Revert 9befbfc * update to vue and vue-router latest version (vuejs-templates#984) - vue 2.5 - vue-router 3.0 * Fix missing dependency bumps (vuejs-templates#987) * switch hello-world tag to PascalCase (vuejs-templates#951) * fix Es6 code issue. This file is not transpiled, so we should stick to ES5 * Fix bug in dev-server when a proxyTable entry is a string (vuejs-templates#965) `options` can not be a `const` because it is modified if value is a string. * Fix casing * Revert 9befbfc * update to vue and vue-router latest version (vuejs-templates#984) - vue 2.5 - vue-router 3.0 * fix missing dependency updates for * vue-template compiler * vue-loader * bump version string * Fix Unknown plugin istanbul error when no unit test (vuejs-templates#785) * Fix Unknown plugin istanbul error when no unit test * simplify handlebars conditionals. * Revert "Fix Unknown plugin istanbul error when no unit test (vuejs-templates#785)" (vuejs-templates#1035) This reverts commit 14f2a92. * Remove unnecessary whitespaces (vuejs-templates#1047) * fix(jest): fix Jest coverage directory (vuejs-templates#1046) Explicitly set the coverage directory to match Karma and .gitignore * Fix typos and formatting (vuejs-templates#1048) * re-add postcss-loader was mistakenly removed during merge of vuejs-templates#824 * bumb version string in config * bumb version string in config in package.json
I've added alias resolving when running tests with babel-plugin-module-resolver
I've omitted src/main.js and src/router/index.js from test coverage because I don't think we should encourage testing of those files
This implements part of this issue - #817
The next part is to add vue-test-utils, which I'll do when it's published.