Skip to content

Commit 3ee45b3

Browse files
committed
init
0 parents  commit 3ee45b3

File tree

23 files changed

+14262
-0
lines changed

23 files changed

+14262
-0
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
generator/template/tests

.eslintrc.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
'env': {
3+
'commonjs': true,
4+
'es6': true,
5+
'node': true
6+
},
7+
'extends': 'standard',
8+
'globals': {
9+
'Atomics': 'readonly',
10+
'SharedArrayBuffer': 'readonly'
11+
},
12+
'parserOptions': {
13+
'ecmaVersion': 2018
14+
},
15+
'rules': {
16+
}
17+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
unit-ava

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: node_js
2+
node_js:
3+
- "8"
4+
- "9"
5+
- "10"
6+
- "11"

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2019 dnlup
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[![Build Status](https://travis-ci.com/dnlup/vue-cli-plugin-unit-ava.svg?token=zu3SxXGFaq3y1hcTQfC6&branch=master)](https://travis-ci.com/dnlup/vue-cli-plugin-unit-ava)
2+
3+
<img src="ava.png" height=60>
4+
5+
# @dnlup/vue-cli-plugin-unit-ava
6+
7+
> unit-ava plugin for vue-cli
8+
9+
## Injected commands
10+
11+
- **`vue-cli-service test:unit`**
12+
13+
Run unit tests with [ava](https://github.com/avajs/ava)
14+
15+
**Note the tests are run inside Node.js with browser environment simulated with JSDOM.**
16+
17+
```
18+
Usage: vue-cli-service test:unit [options] [<file|directory|glob> ...]
19+
20+
Options:
21+
22+
--watch, -w Re-run tests when tests and source files change
23+
--match, -m Only run tests with matching title (Can be repeated)
24+
--update-snapshots, -u Update snapshots
25+
--fail-fast Stop after first test failure
26+
--timeout, -T Set global timeout
27+
--serial, -s Run tests serially
28+
--concurrency, -c Max number of test files running at the same time (Default: CPU cores)
29+
--verbose, -v Enable verbose output
30+
--tap, -t Generate TAP output
31+
--color Force color output
32+
--no-color Disable color output
33+
```
34+
35+
Default files matches are: any files in `tests/unit` that end in `.spec.(ts|js)`.
36+
37+
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.
38+
39+
## Installing in an Already Created Project
40+
41+
```bash
42+
vue add @dnlup/unit-ava
43+
```
44+
45+
## Notes
46+
Compilation of tests files is done with webpack and the artifacts are saved in the `dist_tests` directory in the project root (this directory is added to your `.gitignore`).
47+
48+
## Contributing
49+
50+
* Make your changes
51+
* Add them
52+
```bash
53+
git add <your files>
54+
```
55+
* Commit (uses [commitizen](https://github.com/commitizen/cz-cli))
56+
```bash
57+
npm run cm
58+
```
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Snapshot report for `__tests__/avaGenerator.spec.js`
2+
3+
The actual snapshot is saved in `avaGenerator.spec.js.snap`.
4+
5+
Generated by [AVA](https://ava.li).
6+
7+
## base
8+
9+
> Snapshot 1
10+
11+
{
12+
author: undefined,
13+
ava: {
14+
babel: false,
15+
compileEnhancements: false,
16+
files: [
17+
'dist_tests/tests/**/*.js',
18+
],
19+
require: './node_modules/@dnlup/vue-cli-plugin-unit-ava/setup.js',
20+
sources: [
21+
'!**/*.{js,jsx,ts,vue}',
22+
],
23+
},
24+
babel: undefined,
25+
browser: undefined,
26+
browserslist: undefined,
27+
dependencies: undefined,
28+
description: undefined,
29+
devDependencies: {
30+
'@vue/test-utils': '1.0.0-beta.29',
31+
ava: '^1.2.1',
32+
},
33+
eslintConfig: undefined,
34+
files: undefined,
35+
jest: undefined,
36+
jsDelivr: undefined,
37+
main: undefined,
38+
module: undefined,
39+
name: undefined,
40+
peerDependencies: undefined,
41+
postcss: undefined,
42+
prettier: undefined,
43+
private: undefined,
44+
scripts: {
45+
build: undefined,
46+
deploy: undefined,
47+
e2e: undefined,
48+
lint: undefined,
49+
serve: undefined,
50+
test: undefined,
51+
'test:unit': 'vue-cli-service test:unit',
52+
},
53+
unpkg: undefined,
54+
version: undefined,
55+
vue: undefined,
56+
}
57+
58+
> Snapshot 2
59+
60+
{
61+
'package.json': `{␊
62+
"scripts": {␊
63+
"test:unit": "vue-cli-service test:unit"␊
64+
},␊
65+
"devDependencies": {␊
66+
"@vue/test-utils": "1.0.0-beta.29",␊
67+
"ava": "^1.2.1"␊
68+
},␊
69+
"ava": {␊
70+
"files": [␊
71+
"dist_tests/tests/**/*.js"␊
72+
],␊
73+
"sources": [␊
74+
"!**/*.{js,jsx,ts,vue}"␊
75+
],␊
76+
"babel": false,␊
77+
"compileEnhancements": false,␊
78+
"require": "./node_modules/@dnlup/vue-cli-plugin-unit-ava/setup.js"␊
79+
}␊
80+
}␊
81+
`,
82+
'tests/unit/example.spec.js': `import test from 'ava'␊
83+
import { shallowMount } from '@vue/test-utils'␊
84+
import HelloWorld from '@/components/HelloWorld.vue'␊
85+
86+
test('HelloWorld.vue should render', t => {␊
87+
const msg = 'new message'␊
88+
const wrapper = shallowMount(HelloWorld, {␊
89+
propsData: { msg }␊
90+
})␊
91+
t.regex(wrapper.text(), new RegExp(msg))␊
92+
})␊
93+
`,
94+
}
95+
96+
## with TS
97+
98+
> Snapshot 1
99+
100+
{
101+
author: undefined,
102+
ava: {
103+
babel: false,
104+
compileEnhancements: false,
105+
files: [
106+
'dist_tests/tests/**/*.js',
107+
],
108+
require: './node_modules/@dnlup/vue-cli-plugin-unit-ava/setup.js',
109+
sources: [
110+
'!**/*.{js,jsx,ts,vue}',
111+
],
112+
},
113+
babel: undefined,
114+
browser: undefined,
115+
browserslist: undefined,
116+
dependencies: undefined,
117+
description: undefined,
118+
devDependencies: {
119+
'@vue/test-utils': '1.0.0-beta.29',
120+
ava: '^1.2.1',
121+
},
122+
eslintConfig: undefined,
123+
files: undefined,
124+
jest: undefined,
125+
jsDelivr: undefined,
126+
main: undefined,
127+
module: undefined,
128+
name: undefined,
129+
peerDependencies: undefined,
130+
postcss: undefined,
131+
prettier: undefined,
132+
private: undefined,
133+
scripts: {
134+
build: undefined,
135+
deploy: undefined,
136+
e2e: undefined,
137+
lint: undefined,
138+
serve: undefined,
139+
test: undefined,
140+
'test:unit': 'vue-cli-service test:unit',
141+
},
142+
unpkg: undefined,
143+
version: undefined,
144+
vue: undefined,
145+
}
146+
147+
> Snapshot 2
148+
149+
{
150+
'package.json': `{␊
151+
"scripts": {␊
152+
"test:unit": "vue-cli-service test:unit"␊
153+
},␊
154+
"devDependencies": {␊
155+
"@vue/test-utils": "1.0.0-beta.29",␊
156+
"ava": "^1.2.1"␊
157+
},␊
158+
"ava": {␊
159+
"files": [␊
160+
"dist_tests/tests/**/*.js"␊
161+
],␊
162+
"sources": [␊
163+
"!**/*.{js,jsx,ts,vue}"␊
164+
],␊
165+
"babel": false,␊
166+
"compileEnhancements": false,␊
167+
"require": "./node_modules/@dnlup/vue-cli-plugin-unit-ava/setup.js"␊
168+
}␊
169+
}␊
170+
`,
171+
'tests/unit/example.spec.ts': `import test from 'ava'␊
172+
import { shallowMount } from '@vue/test-utils'␊
173+
import HelloWorld from '@/components/HelloWorld.vue'␊
174+
175+
test('HelloWorld.vue should render', t => {␊
176+
const msg = 'new message'␊
177+
const wrapper = shallowMount(HelloWorld, {␊
178+
propsData: { msg }␊
179+
})␊
180+
t.regex(wrapper.text(), new RegExp(msg))␊
181+
})␊
182+
`,
183+
}
1.13 KB
Binary file not shown.

__tests__/avaGenerator.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import test from 'ava'
2+
import generateWithPlugin from '@vue/cli-test-utils/generateWithPlugin'
3+
4+
test('base', async t => {
5+
const { pkg, files } = await generateWithPlugin({
6+
id: 'unit-ava',
7+
apply: require('../generator'),
8+
options: {}
9+
})
10+
t.snapshot(pkg)
11+
t.snapshot(files)
12+
})
13+
14+
test('with TS', async t => {
15+
const { pkg, files } = await generateWithPlugin([
16+
{
17+
id: 'unit-ava',
18+
apply: require('../generator'),
19+
options: {}
20+
},
21+
// mock the presence of the ts plugin
22+
{
23+
id: 'typescript',
24+
apply: () => {},
25+
options: {}
26+
}
27+
])
28+
t.snapshot(pkg)
29+
t.snapshot(files)
30+
})

ava.png

211 KB
Loading

0 commit comments

Comments
 (0)