Skip to content

Commit 26e6976

Browse files
committed
test:feat e2e
1 parent 9d2c184 commit 26e6976

File tree

6 files changed

+50
-25
lines changed

6 files changed

+50
-25
lines changed

.eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
22
root: true,
3-
extends: ['standard']
3+
plugins: ['testcafe'],
4+
extends: ['standard', 'plugin:testcafe/recommended']
45
}

examples/route/List.vue

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
</router-link>
88
</span>
99
</header>
10-
<ul>
10+
<ul id="ul">
1111
<li v-for="(item, $index) in list.list" :key="item.id">
12-
<router-link :to="{ name: 'detail', params: { id: item.id } }">
13-
{{ item.title }}
14-
</router-link>
12+
<router-link :to="{ name: 'detail', params: { id: item.id } }">{{ item.title }}</router-link>
1513
</li>
1614
</ul>
1715
</div>

examples/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fs.readdirSync(__dirname).forEach(file => {
2222
})
2323

2424
app.use(express.static(__dirname))
25-
app.listen(3000, (err) => {
25+
module.exports = app.listen(3000, (err) => {
2626
if (err) return console.log(err)
2727
console.log('http://localhost:3000/')
2828
})

gulpfile.js

+29-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
const gulp = require('gulp')
2+
3+
const moduleName = 'Vuet'
4+
const destName = 'vuet'
5+
26
const eslint = require('gulp-eslint')
37
const clear = require('clear')
8+
gulp.task('lint', () => {
9+
clear()
10+
return gulp.src(['**/*.js', '!node_modules/**', '!dist/**'])
11+
.pipe(eslint())
12+
.pipe(eslint.format())
13+
})
14+
415
const { rollup } = require('rollup')
516
const babel = require('rollup-plugin-babel')({
617
babelrc: false,
@@ -9,22 +20,10 @@ const babel = require('rollup-plugin-babel')({
920
'stage-0'
1021
]
1122
})
12-
const ava = require('gulp-ava')
1323
const uglify = require('rollup-plugin-uglify')
1424
const { minify } = require('uglify-js')
1525
const replace = require('rollup-plugin-replace')
16-
17-
const moduleName = 'Vuet'
18-
const destName = 'vuet'
19-
20-
gulp.task('lint', () => {
21-
clear()
22-
return gulp.src(['**/*.js', '!node_modules/**', '!dist/**'])
23-
.pipe(eslint())
24-
.pipe(eslint.format())
25-
})
26-
27-
gulp.task('build', ['lint'], () => {
26+
gulp.task('build', () => {
2827
// Development environment version
2928
return rollup({
3029
entry: 'src/index.js',
@@ -65,16 +64,28 @@ gulp.task('build', ['lint'], () => {
6564
})
6665
})
6766

68-
gulp.task('test', ['build'], () => {
69-
return gulp.src('test/**.test.js')
67+
const ava = require('gulp-ava')
68+
gulp.task('test', () => {
69+
return gulp.src('test/unit/**.test.js')
7070
.pipe(ava({
7171
verbose: true // Enable verbose output
7272
}))
7373
})
7474

75-
gulp.task('default', ['test'])
75+
const testcafe = require('gulp-testcafe')
76+
const server = require('./examples/server')
77+
gulp.task('e2e', () => {
78+
return gulp.src('test/e2e/**.test.js')
79+
.pipe(testcafe({ browsers: ['chrome'] }))
80+
})
81+
82+
gulp.task('default', ['lint', 'build', 'test', 'e2e'], () => {
83+
if (process.env.NODE_ENV !== 'development') {
84+
server && server.close()
85+
process.exit()
86+
}
87+
})
7688

7789
if (process.env.NODE_ENV === 'development') {
78-
require('./examples/server')
79-
gulp.watch(['**/*.js', '!node_modules/**', '!dist/**'], ['default'])
90+
gulp.watch(['**/*.js', '!node_modules/**', '!dist/**'], ['dev'])
8091
}

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"cross-env": "node_modules/.bin/cross-env",
88
"gulp": "node_modules/.bin/gulp",
99
"dev": "npm run cross-env NODE_ENV=development npm run gulp",
10-
"dist": "npm run cross-env NODE_ENV=production npm run gulp",
1110
"test": "npm run cross-env NODE_ENV=testing npm run gulp"
1211
},
1312
"files": [
@@ -40,16 +39,19 @@
4039
"babel-register": "^6.24.1",
4140
"clear": "0.0.1",
4241
"cross-env": "^5.0.0",
42+
"css-loader": "^0.28.4",
4343
"eslint-config-standard": "^10.2.1",
4444
"eslint-plugin-import": "^2.2.0",
4545
"eslint-plugin-node": "^4.2.2",
4646
"eslint-plugin-promise": "^3.5.0",
4747
"eslint-plugin-standard": "^3.0.1",
48+
"eslint-plugin-testcafe": "^0.2.1",
4849
"express": "^4.15.3",
4950
"express-urlrewrite": "^1.2.0",
5051
"gulp": "^3.9.1",
5152
"gulp-ava": "^0.17.1",
5253
"gulp-eslint": "^3.0.1",
54+
"gulp-testcafe": "^0.9.1",
5355
"jsdom": "^10.1.0",
5456
"rollup": "^0.41.6",
5557
"rollup-plugin-babel": "^2.7.1",

test/e2e/route.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Selector } from 'testcafe'
2+
3+
fixture`route`
4+
.page`http://localhost:3000/route/index.html`
5+
6+
test('Check property of element', async t => {
7+
await t
8+
.wait(2000)
9+
.expect(Selector('ul li:nth-child(1) a').textContent).eql('1 title')
10+
.expect(Selector('ul li:nth-child(2) a').textContent).eql('2 title')
11+
.expect(Selector('ul li:nth-child(3) a').textContent).eql('3 title')
12+
.expect(Selector('ul li:nth-child(4) a').textContent).eql('4 title')
13+
})

0 commit comments

Comments
 (0)