You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -47,123 +42,22 @@ This plugin is still in development so any feedback is greatly appreciated.
47
42
48
43
Default files matches are: any files in `tests/unit` that end in `.spec.(ts|js)`.
49
44
50
-
All [command line options](https://github.com/avajs/ava/blob/master/docs/05-command-line.md) are supported, the only one that should not work is `--reset-cache` since `ava` doesn't compile the test files, `webpack` does.
45
+
All [command line options](https://github.com/avajs/ava/blob/master/docs/05-command-line.md) are supported.
51
46
52
47
### Installing in an Already Created Project
53
48
54
49
```bash
55
50
vue add @dnlup/unit-ava
56
51
```
57
52
58
-
Once installed, calling `ava` directly will not work anymore, see [how to run tests](#running-tests).
59
-
60
-
### How it works
61
-
This plugin aims to setup an environment where test files are compiled with `webpack` and the tests are run with ava using the compiled files. I had to make some assumptions to configure `ava` to work out of the box with the `webpack` setup enforced in `vue` projects.
62
-
63
-
#### ava configuration
64
-
This is the configuration that will be generated for `ava` in `package.json`:
for a reference of all the options see https://github.com/avajs/ava/blob/master/docs/06-configuration.md#options).
83
-
84
-
##### `files`
85
-
This setup `ava` to run tests on the compiled files which are saved by `webpack` in the `dist_tests` folder in the root of your project. ***This value should not be changed at the moment since the output path of `webpack` is hard-coded***. This will have to change of course.
86
-
87
-
##### `sources`
88
-
This is required to make the `--watch` option work properly. I am excluding every file except the compiled ones, otherwise on a file change the test will run multiple times. ***This value should not be changed***.
89
-
90
-
##### `babel`
91
-
This is required to prevent `ava` to compile test files. ***This value should not be changed***.
92
-
93
-
##### `compileEnhancements`
94
-
This disable `power-assert` but you should be able to safely enable it.
95
-
96
-
##### `require`
97
-
This is ***required to setup `jsdom`*** in tests. The purpose of this file is ***not to setup node require hooks*** as suggested in [this recipe](https://github.com/avajs/ava/blob/master/docs/recipes/vue.md), so if you are using a setup file just for that you can safely let the plugin override your setting. If instead you still have to use your own setup file for other reasons, you can create a file like the following:
98
-
99
-
```js
100
-
require('@dnlup/vue-cli-plugin-ava/setup')
101
-
102
-
//...your code....//
103
-
```
104
-
105
-
and change the value of this field to point to your custom file.
106
-
107
-
#### webpack configuration
108
-
I am modifying the `entry`, `output` and `plugins` field of the confifuration.
109
-
110
-
##### `entry`
111
-
```js
112
-
{
113
-
entry: {
114
-
'tests/unit/<your_test_file>':'<file-path>'
115
-
}
116
-
}
117
-
```
118
-
Every test file is an entry that has as key its path (without the extension). This way `webpack` will generate a directory structure identical to the one of the source files.
hardcoded to `dist_tests` directory in the root of your project
134
-
135
-
*`devtoolModuleFilenameTemplate` and `devtoolFallbackModuleFilenameTemplate`
136
-
137
-
setup to `[absolute-resource-path]` so that in devtools will not appear `webpack://` but the actual file path
138
-
139
-
##### `plugins`
140
-
A custom plugin named `RewriteSourceMap` is added to rewrite the source-maps to have each source test file as the first element of the `sources` list field of the generated source-map. This will allow `ava` to use the correct path for saving snapshots.
141
-
142
-
#### `.gitignore`
143
-
The `dist_tests` folder is added to your `.gitignore` file.
144
-
145
-
#### `package.json` scripts
146
-
The `test:unit` script is added to your `scripts` section of the `package.json` file.
147
-
See [injected commands](#injected-commands).
148
-
149
-
#### Runing tests
150
-
In this configuration you have to call `vue-cli-service test:unit` to run tests. So if for example you want to run tests only on a specific file you would run:
151
-
152
-
```bash
153
-
$ npm run test:unit -- <your file>
154
-
```
155
-
or
156
-
```bash
157
-
$ npx vue-cli-service test:unit <your file>
158
-
```
53
+
#### Prompts
54
+

159
55
160
-
See [injected commands](#injected-commands).
56
+
Will merge or create a new configuration in the selected destination. It will fail if the project is already configured in the destination **not** selected.
161
57
162
-
Calling `ava` directly would not work anymore.
58
+

163
59
164
-
#### Why all of this?
165
-
I went for this setup because I think that in a `vue` project it is better to let webpack compile everything: you have already all your loaders that are working in `dev` mode.
166
-
Using `require hooks` for simple cases should be equivalent, but if you start using packages that add other loaders to the webpack config things might get more complicated. I think [Vuetify](https://vuetifyjs.com/en/getting-started/quick-start) could be a good example. I am open to suggestion anyway, so feel free to chime in and propose alternatives. My end goal is having a `ava` plugin to run unit tests :smile: with `@vue/cli`.
60
+
Will add support for a specific UI Framework. It currently supports only the latest version of [Vuetify](https://vuetifyjs.com/en/).
167
61
168
62
### Contributing
169
63
@@ -174,5 +68,5 @@ Using `require hooks` for simple cases should be equivalent, but if you start us
0 commit comments