-
Notifications
You must be signed in to change notification settings - Fork 1.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
Add Vue.js recipe #1361
Merged
Merged
Add Vue.js recipe #1361
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Testing Vue.js components | ||
|
||
## Dependencies | ||
|
||
- [Require Extension hooks](https://github.com/jackmellis/require-extension-hooks): | ||
- `npm i -D require-extension-hooks require-extension-hooks-vue require-extension-hooks-babel` | ||
|
||
- [browser-env](browser-testing.md) | ||
- `npm i -D browser-env` | ||
|
||
## Setup | ||
|
||
The first step is setting up a helper to configure the environment to transpile `.vue` files and run in a browser like environment: | ||
|
||
```json | ||
{ | ||
"ava": { | ||
"babel": "inherit", | ||
"require": [ | ||
"./test/helpers/setup.js" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
```js | ||
// ./test/helpers/setup.js | ||
|
||
// Setup browser environment | ||
require('browser-env')(); | ||
const hooks = require('require-extension-hooks'); | ||
const Vue = require('vue'); | ||
|
||
// Setup Vue.js to remove production tip | ||
Vue.config.productionTip = false; | ||
|
||
// Setup vue files to be processed by `require-extension-hooks-vue` | ||
hooks('vue').plugin('vue').push(); | ||
// Setup vue and js files to be processed by `require-extension-hooks-babel` | ||
hooks(['vue', 'js']).plugin('babel').push(); | ||
``` | ||
|
||
You can find more information about setting up Babel with AVA in the [babelrc recipe](babelrc.md). | ||
|
||
## Sample snapshot test | ||
|
||
```js | ||
import test from 'ava'; | ||
import Vue from 'vue'; | ||
import Component from 'component.vue'; | ||
|
||
test('renders', t => { | ||
const vm = new Vue(Component).$mount(); | ||
const tree = { $el: vm.$el.outerHTML }; | ||
t.snapshot(tree); | ||
}); | ||
``` | ||
|
||
## Coverage reporting | ||
|
||
Follow the [coverage reporting recipe](code-coverage.md), additionally adding the `.vue` extension to the nyc configuration to instrument `.vue` files. | ||
|
||
```json | ||
{ | ||
"nyc": { | ||
"extension": [ | ||
".js", | ||
".vue" | ||
] | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 be cool if someone made all this a module, so you could just do
require('ava-vue-setup');
and be done.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.
Agree, currently you can add more options to
babel
extension plugin and there will most likely be more work forvue
extension plugin to support other languages (TypeScript, Pug ect). Once this is done then we could create this npm module to wrap these options to make it simplier.For now i think this setup is relatively easy to create and at least gives users the ability to test Vue with Ava.js which is a large step forward to Vue.js testing workflow.
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.
On a further note, it should be trivial to add support for this in https://github.com/vuejs-templates/webpack so this could be the first stepping stone.
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 know I wrote the babel extension hook but I've actually stopped using it myself due to the amount of slowdown babel causes.
I instead went for manually transpiling export/import statements like this as node can already handle pretty much all of ES2015. So unless you're using cutting edge 2017 stuff you'll probably find this much faster than babel (I should probably create a package for it).
I'm aware the impact of importing babel-core in every ava process is a known issue but I'm not sure about whether people are happy to put up with it or not?
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.
Hmm perhaps this logic should sit in the
ava-vue-setup
as mentioned. As we can expose all this functionality with options, and maintainability for users will be reduced. Also i'd rather provide a fully functional solution for the time being. Would cause more issues to provide all that code, especially if there is an edgecase that hasn't yet been thought off, such as dynamic import statementsimport('a/file.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.
@blake-newman Any updates?
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 happy for this recipe to be released. Looking at adding a
ava-setup-vue
package. However due to the flexible nature of Vue files will need to be more customisable so you can select transpilers. Which will take a bit of time. This recipe is good fine for a standard Vue setup but not much moreThere 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.
Cool :)