Skip to content

Commit 74fd0aa

Browse files
committed
Change <it will="..."> to <test name="...">. Fix issue cleaning up generated files after failed run.
1 parent 5fbe5a5 commit 74fd0aa

File tree

8 files changed

+66
-52
lines changed

8 files changed

+66
-52
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,29 @@ The file is split into two sections, the `<tests>` and the `<script>`.
2929

3030
More details are available in the [API Docs](https://github.com/johnsusek/vue-test-declarative/blob/master/docs/API.md).
3131

32-
## Example .vuetest file
32+
## Examples
33+
34+
## Simplest
35+
36+
The simplest possible test just checks for the specified text anywhere in the rendered component.
37+
38+
```xml
39+
<tests for="@/components/MyComponent.vue">
40+
<test name="Contains success message">
41+
<expect text to-match="Success!" />
42+
</it>
43+
</tests>
44+
```
45+
46+
## HelloWorld
3347

3448
For this example, we'll test the `HelloWorld` component from the [default vue-cli template](https://github.com/vuejs/vue-cli/blob/master/packages/@vue/cli-service/generator/template/src/components/HelloWorld.vue).
3549

3650
Create a `HelloWorld.vuetest` file in the `tests/declarative` directory with these contents:
3751

3852
```xml
3953
<tests for="@/components/HelloWorld.vue">
40-
<it will="render message correctly" v-bind:props="props">
54+
<test name="Render message correctly" v-bind:props="props">
4155
<expect text to-match="Welcome!" />
4256
</it>
4357
</tests>

bin/run.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ function runTests() {
160160

161161
// remove generated tests
162162
function cleanup() {
163-
glob(workingDir + '/*.vuetest.spec.js', options, (err, files) => {
164-
files.forEach(file => {
165-
fs.unlinkSync(file);
166-
})
163+
let files = glob.sync(workingDir + '/*.vuetest.spec.js', options);
164+
165+
files.forEach(file => {
166+
fs.unlinkSync(file);
167+
})
167168

168-
fs.unlinkSync(workingDir + '/generated-setup.js');
169-
});
169+
fs.unlinkSync(workingDir + '/generated-setup.js');
170170
}
171171

172172
function quit(message, code = 1) {

docs/API.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
In summary, a .vuetest file looks like this:
44
```xml
55
<tests>
6-
<it>
6+
<test>
77
<set>
88
<trigger>
99
<expect>
10-
</it>
10+
</test>
1111
</tests>
1212

1313
<script></script>
@@ -34,16 +34,16 @@ This is the path to the component, used when importing it into your tests. Webpa
3434

3535
<br>
3636

37-
## `<it>`
37+
## `<test>`
3838
<details>
3939
<summary>Details</summary>
4040

4141
```xml
42-
<it will="WillValue" BindingTarget="BindingValue">
42+
<test name="NameValue" BindingTarget="BindingValue">
4343
```
4444

45-
### WillValue
46-
This is used as the description for the test case.
45+
### NameValue
46+
This is used as the display name when running the test.
4747

4848
### BindingTarget
4949

@@ -59,13 +59,13 @@ The BindingTarget will be set to this value of the `context` variable in your `<
5959

6060
#### Examples:
6161
```xml
62-
<it will="render app">
62+
<test name="render app">
6363
```
6464
```xml
65-
<it will="render message correctly" v-bind:props="myProps">
65+
<test name="render message correctly" v-bind:props="myProps">
6666
```
6767
```xml
68-
<it will="render data value correctly" v-bind:data="myData">
68+
<test name="render data value correctly" v-bind:data="myData">
6969
```
7070

7171
</details>

docs/Install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Create config file `vuetest.config.json` with these contents:
2626
Create test file `tests/declarative/App.vuetest` in this directory with these contents:
2727
```xml
2828
<tests for="../../examples/todomvc/components/App.vue">
29-
<it will="Render app">
29+
<test name="Render app">
3030
<expect html to-match="todos" />
3131
</it>
3232
</tests>

docs/examples/Vue-CLI-HelloWorld.vuetest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
-->
55

66
<tests for="@/components/HelloWorld.vue">
7-
<it will="render message correctly" v-bind:props="props">
7+
<test name="render message correctly" v-bind:props="props">
88
<expect text to-match="Welcome!" />
9-
</it>
9+
</test>
1010
</tests>
1111

1212
<script>

docs/examples/Vuex-TodoMVC.vuetest

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,48 @@
99
-->
1010

1111
<tests for="../../examples/todomvc/components/App.vue">
12-
<it will="render header">
12+
<test name="render header">
1313
<expect text-of="h1" to-match="todos" />
14-
</it>
14+
</test>
1515

16-
<it will="add a todo">
16+
<test name="add a todo">
1717
<set selector=".new-todo" value="First" />
1818
<trigger selector=".new-todo" event="keyup.enter" />
1919
<expect text-of=".todo-list li" to-match="First" />
2020
<expect text-of=".todo-count" to-match="1 item left" />
21-
</it>
21+
</test>
2222

23-
<it will="remove a todo">
23+
<test name="remove a todo">
2424
<expect text-of=".todo-list" to-be-truthy />
2525
<trigger selector=".todo-list li .destroy" event="click" />
2626
<expect text-of=".todo-list" to-be-falsy />
27-
</it>
27+
</test>
2828

29-
<it will="add then complete a todo">
29+
<test name="add then complete a todo">
3030
<set selector=".new-todo" value="Another" />
3131
<trigger selector=".new-todo" event="keyup.enter" />
3232
<trigger selector="input.toggle" event="click" />
3333
<expect text-of=".todo.completed" to-match="Another" />
34-
</it>
34+
</test>
3535

36-
<it will="clicking `active` hides list">
36+
<test name="clicking `active` hides list">
3737
<expect text-of=".todo-list" to-be-truthy />
3838
<trigger selector='a[href="#/active"]' event="click" />
3939
<expect text-of=".todo-list" to-be-falsy />
40-
</it>
40+
</test>
4141

42-
<it will="clicking `completed` shows item we added + completed">
42+
<test name="clicking `completed` shows item we added + completed">
4343
<trigger selector='a[href="#/completed"]' event="click" />
4444
<expect text-of=".todo-list" to-equal="Another" />
45-
</it>
45+
</test>
4646

47-
<it will="clear the list when `clear completed` is clicked">
47+
<test name="clear the list when `clear completed` is clicked">
4848
<expect text-of=".todo-list" to-equal="Another" />
4949
<trigger selector=".clear-completed" event="click" />
5050
<expect text-of=".todo-list" to-be-falsy />
51-
</it>
51+
</test>
5252

53-
<it will="mark all items completed when `toggle all` clicked">
53+
<test name="mark all items completed when `toggle all` clicked">
5454
<!-- Add a todo -->
5555
<set selector=".new-todo" value="Another" />
5656
<trigger selector=".new-todo" event="keyup.enter" />
@@ -62,5 +62,5 @@
6262
<!-- Confirm the active list is empty -->
6363
<trigger selector='a[href="#/active"]' event="click" />
6464
<expect text-of=".todo-list" to-be-falsy />
65-
</it>
65+
</test>
6666
</tests>

generate.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Loop through parsed xml and write out js
2-
let generateIt = require('./generateIt');
2+
let generateTest = require('./generateTest');
33

44
let head = `
55
/* THIS FILE IS AUTO-GENERATED, EDITS WILL BE OVERWRITTEN */
@@ -21,20 +21,20 @@ function generate(componentPath, parsed, script, localVue) {
2121

2222
lines.push(`describe('${componentPath}', () => {\n`);
2323

24-
let its;
24+
let tests;
2525

26-
// parsed.tests.it might be either an object (single child) or array (multiple)
26+
// parsed.tests.test might be either an object (single child) or array (multiple)
2727
// if single child, turn into array then foreach like usual
28-
if (Array.isArray(parsed.tests.it)) {
29-
its = parsed.tests.it;
28+
if (Array.isArray(parsed.tests.test)) {
29+
tests = parsed.tests.test;
3030
}
3131
else {
32-
its = [parsed.tests.it];
32+
tests = [parsed.tests.test];
3333
}
3434

3535
// loop through each 'its' to generate the case
36-
its.forEach(it => {
37-
lines = lines.concat(generateIt.generateIt(it));
36+
tests.forEach(test => {
37+
lines = lines.concat(generateTest.generateTest(test));
3838
});
3939

4040
lines.push('});');

generateIt.js renamed to generateTest.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ let { generateExpect } = require('./generateExpect');
22
let { generateTrigger } = require('./generateTrigger');
33
let { generateSet } = require('./generateSet');
44

5-
function generateIt(it) {
5+
function generateTest(test) {
66
let lines = [];
77

8-
lines.push(` it('will ${it.$.will}', async () => {`);
8+
lines.push(` it('${test.$.name}', async () => {`);
99

1010
// TODO: move this out one level?
1111
lines.push(` let options = { localVue, sync: false }`)
1212
lines.push(` if (typeof store !== 'undefined') { options.store = store; }`);
1313
lines.push(` let wrapper = mount(Component, options);`);
1414

1515
// v-bind:props="props" = wrapper.setProps(props)
16-
let propsBinding = it.$['v-bind:props'];
16+
let propsBinding = test.$['v-bind:props'];
1717
if (propsBinding) {
1818
lines.push(` wrapper.setProps(context.${propsBinding});`);
1919
}
2020

2121
// v-bind:data="data" = wrapper.setData(data)
22-
let dataBinding = it.$['v-bind:data'];
22+
let dataBinding = test.$['v-bind:data'];
2323
if (dataBinding) {
2424
lines.push(` wrapper.setData(context.${dataBinding});`);
2525
}
2626

27-
// loop through each child of it.$$ and build either an expect line or a trigger line
28-
it.$$.forEach(child => {
27+
// loop through each child of test.$$ and build either an expect line or a trigger line
28+
test.$$.forEach(child => {
2929
lines = lines.concat(generateLines(child));
3030
});
3131

@@ -52,7 +52,7 @@ function generateLines(child) {
5252
break;
5353
}
5454

55-
// For some reason, the first tag shows up in it.$$ and
55+
// For some reason, the first tag shows up in test.$$ and
5656
// the rest of the tags show up on the first child's $$
5757
// on tags with bare attributes like 'to-be-truthy'
5858
// This really seems like it could be a parser bug, but
@@ -69,5 +69,5 @@ function generateLines(child) {
6969
}
7070

7171
module.exports = {
72-
generateIt
72+
generateTest
7373
}

0 commit comments

Comments
 (0)