Skip to content

Commit 5212f88

Browse files
committed
added demo component and a prompt
1 parent 3c5b1e0 commit 5212f88

File tree

4 files changed

+125
-3
lines changed

4 files changed

+125
-3
lines changed

generator/index.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
module.exports = api => {
1+
const fs = require('fs');
2+
3+
module.exports = (api, options) => {
24
api.render('./template');
35

46
// These dependencies always need to be added
@@ -16,5 +18,37 @@ module.exports = api => {
1618
'test:e2e:parallel': 'vue-cli-service test:e2e:parallel',
1719
'test:e2e:open': 'vue-cli-service test:e2e:open',
1820
},
19-
});
21+
});
22+
23+
if (options.demo) api.injectImports(api.entryFile, `import TestMe from './components/TestMe'`);
24+
}
25+
26+
module.exports.hooks = (api, options) => {
27+
api.afterInvoke(() => {
28+
appendGitIgnore(api);
29+
if (options.demo) replaceAppFile(api);
30+
})
31+
}
32+
33+
34+
function replaceAppFile(api) {
35+
const contentMain = fs.readFileSync(api.entryFile, { encoding: 'utf-8' });
36+
const newContent = contentMain.replace('new Vue({', `
37+
Vue.component('TestMe', TestMe);
38+
39+
new Vue({`);
40+
41+
fs.writeFileSync(api.entryFile, newContent, { encoding: 'utf-8' });
42+
43+
const appPath = api.resolve('src/App.vue')
44+
const appFile = fs.readFileSync(appPath, { encoding: 'utf-8' });
45+
46+
// replace div inside a template
47+
const newAppFile = appFile.replace('</div>', `<TestMe></TestMe></div>`);
48+
fs.writeFileSync(appPath, newAppFile, { encoding: 'utf-8' });
49+
}
50+
51+
function appendGitIgnore(api) {
52+
const ignorePath = api.resolve('.gitignore');
53+
fs.appendFileSync(ignorePath, `\n/tests/e2e/output`);
2054
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<template>
2+
<div>
3+
<h1>Demo Component. Submit me!</h1>
4+
<div class="row">
5+
<div class="col-md-6 mb-3">
6+
<label for="firstName">First name</label>
7+
<input type="text" v-model="data.first_name" class="form-control" id="firstName" placeholder="" value="" required>
8+
</div>
9+
<div class="col-md-6 mb-3">
10+
<label for="lastName">Last name</label>
11+
<input type="text" v-model="data.last_name" class="form-control" id="lastName" placeholder="" value="" required>
12+
</div>
13+
</div>
14+
15+
<div class="mb-3">
16+
<label for="username">Username</label>
17+
<input type="text" class="form-control" v-model="data.username" id="username" placeholder="Username" required>
18+
</div>
19+
20+
<div class="mb-3">
21+
<label for="email">Email</label>
22+
<input type="email" class="form-control" v-model="data.email" id="email" placeholder="you@example.com">
23+
</div>
24+
25+
<div class="mb-3">
26+
<label for="address">Address</label>
27+
<input type="text" class="form-control" v-model="data.address" id="address" placeholder="1234 Main St" required>
28+
</div>
29+
<div>
30+
<button @click="submit()">Submit</button>
31+
</div>
32+
<div>
33+
<h1>Result</h1>
34+
<pre id="result" v-html="result"></pre>
35+
</div>
36+
</div>
37+
</template>
38+
39+
<script>
40+
export default {
41+
data() {
42+
return {
43+
data: {},
44+
result: '',
45+
};
46+
},
47+
methods: {
48+
submit() {
49+
this.result = JSON.stringify(this.data);
50+
return false;
51+
}
52+
}
53+
}
54+
</script>
55+
56+
<style lang="css">
57+
h1 {
58+
font-weight: bold;
59+
font-size: 24px;
60+
margin-bottom: 16px;
61+
}
62+
input {
63+
margin-left: 20px;
64+
border: 1px solid silver;
65+
}
66+
67+
button {
68+
background: blueviolet;
69+
padding: 20px 60px;
70+
color: white;
71+
}
72+
</style>

generator/template/tests/e2e/app_test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,14 @@ Feature('App');
22

33
Scenario('Open app', (I) => {
44
I.amOnPage('/');
5-
I.see('Vue');
5+
I.see('Demo Component', 'h1');
6+
I.fillField('First name', 'tester'); // using semantic locators
7+
I.fillField('Last name', 'end2end');
8+
I.fillField('#username', 'codecept'); // using CSS locators
9+
I.fillField('Email', 'tester@codecept.io');
10+
I.fillField('Address', 'some street');
11+
I.click('Submit');
12+
I.see('"first_name":"tester"','#result');
13+
I.see('"last_name":"end2end"','#result');
14+
pause(); // TODO: Add more assertions when paused!
615
});

prompts.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = [
2+
{
3+
name: 'demo',
4+
type: 'confirm',
5+
message: `Do you want to update App.vue and add a demo component for testing?`
6+
}
7+
]

0 commit comments

Comments
 (0)