Skip to content

Commit 5a0aec9

Browse files
committed
setup e2e tests
1 parent c0723fe commit 5a0aec9

File tree

6 files changed

+101
-3
lines changed

6 files changed

+101
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.DS_Store
22
node_modules
33
TODOs.md
4+
test/e2e/reports
5+
test/e2e/screenshots
6+
selenium-debug.log

examples/server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fs.readdirSync(__dirname).forEach(file => {
2525

2626
app.use(express.static(__dirname))
2727

28-
app.listen(8080, () => {
29-
console.log('Server listening on http://localhost:8080, Ctrl+C to stop')
28+
const port = process.env.PORT || 8080
29+
module.exports = app.listen(port, () => {
30+
console.log(`Server listening on http://localhost:${port}, Ctrl+C to stop`)
3031
})

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"dev-dist": "rollup -wcm",
2121
"build": "rollup -c && uglifyjs dist/vue-router.js -c -m -o dist/vue-router.min.js",
2222
"lint": "eslint src examples",
23-
"test": "npm run lint && flow check"
23+
"test": "npm run lint && flow check",
24+
"test:e2e": "node test/e2e/runner.js"
2425
},
2526
"devDependencies": {
2627
"axios": "^0.13.1",
@@ -30,14 +31,18 @@
3031
"babel-preset-es2015": "^6.9.0",
3132
"babel-preset-flow-vue": "^1.0.0",
3233
"buble": "^0.12.3",
34+
"cross-spawn": "^4.0.0",
3335
"css-loader": "^0.23.1",
3436
"eslint": "^3.0.1",
3537
"eslint-config-vue": "^1.0.3",
3638
"eslint-plugin-flow-vars": "^0.4.0",
3739
"express": "^4.14.0",
3840
"express-urlrewrite": "^1.2.0",
3941
"flow-bin": "^0.29.0",
42+
"nightwatch": "^0.9.5",
43+
"nightwatch-helpers": "^1.0.0",
4044
"path-to-regexp": "^1.5.3",
45+
"phantomjs-prebuilt": "^2.1.7",
4146
"rollup": "^0.33.0",
4247
"rollup-plugin-babel": "^2.6.1",
4348
"rollup-plugin-buble": "^0.12.1",
@@ -46,6 +51,7 @@
4651
"rollup-plugin-node-resolve": "^1.7.1",
4752
"rollup-plugin-replace": "^1.1.1",
4853
"rollup-watch": "^2.4.0",
54+
"selenium-server": "^2.53.1",
4955
"uglify-js": "^2.7.0",
5056
"vue": "^2.0.0-beta.3",
5157
"vue-loader": "^9.2.0",

test/e2e/nightwatch.config.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// http://nightwatchjs.org/guide#settings-file
2+
module.exports = {
3+
'src_folders': ['test/e2e/specs'],
4+
'output_folder': 'test/e2e/reports',
5+
'custom_commands_path': ['node_modules/nightwatch-helpers/commands'],
6+
'custom_assertions_path': ['node_modules/nightwatch-helpers/assertions'],
7+
8+
'selenium': {
9+
'start_process': true,
10+
'server_path': 'node_modules/selenium-server/lib/runner/selenium-server-standalone-2.53.1.jar',
11+
'host': '127.0.0.1',
12+
'port': 4444
13+
},
14+
15+
'test_settings': {
16+
'default': {
17+
'selenium_port': 4444,
18+
'selenium_host': 'localhost',
19+
'silent': true,
20+
'screenshots': {
21+
'enabled': true,
22+
'on_failure': true,
23+
'on_error': false,
24+
'path': 'test/e2e/screenshots'
25+
}
26+
},
27+
28+
'phantomjs': {
29+
'desiredCapabilities': {
30+
'browserName': 'phantomjs',
31+
'javascriptEnabled': true,
32+
'acceptSslCerts': true
33+
}
34+
}
35+
}
36+
}

test/e2e/runner.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var path = require('path')
2+
var spawn = require('cross-spawn')
3+
// var server = require('../../examples/server')
4+
5+
var args = process.argv.slice(2)
6+
if (args.indexOf('--config') === -1) {
7+
args = args.concat(['--config', 'test/e2e/nightwatch.config.js'])
8+
}
9+
if (args.indexOf('--env') === -1) {
10+
args = args.concat(['--env', 'phantomjs'])
11+
}
12+
var i = args.indexOf('--test')
13+
if (i > -1) {
14+
args[i + 1] = 'test/e2e/specs/' + args[i + 1]
15+
}
16+
17+
var runner = spawn('./node_modules/.bin/nightwatch', args, {
18+
stdio: 'inherit'
19+
})
20+
21+
runner.on('exit', function (code) {
22+
// server.close()
23+
process.exit(code)
24+
})
25+
26+
runner.on('error', function (err) {
27+
// server.close()
28+
throw err
29+
})

test/e2e/specs/basic.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
'basic': function (browser) {
3+
browser
4+
.url('http://localhost:8080/basic/')
5+
.waitForElementVisible('#app', 1000)
6+
.assert.count('li a', 3)
7+
// assert correct href with base
8+
.assert.attributeContains('li:nth-child(1) a', 'href', '/basic/')
9+
.assert.attributeContains('li:nth-child(2) a', 'href', '/basic/foo')
10+
.assert.attributeContains('li:nth-child(3) a', 'href', '/basic/bar')
11+
.assert.containsText('.view', 'home')
12+
13+
.click('li:nth-child(2) a')
14+
.assert.containsText('.view', 'foo')
15+
16+
.click('li:nth-child(3) a')
17+
.assert.containsText('.view', 'bar')
18+
19+
.click('li:nth-child(1) a')
20+
.assert.containsText('.view', 'home')
21+
.end()
22+
}
23+
}

0 commit comments

Comments
 (0)