Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E test, fix #802 #863

Merged
merged 24 commits into from
Aug 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
.DS_Store
npm-debug.log
node_modules/
out/

server/dist
node_modules
.vscode-test

dist
server/dist
docs/.vuepress/dist

*.zip
30 changes: 28 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -17,7 +17,11 @@
],
"internalConsoleOptions": "neverOpen",
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/**/*.js"]
"outFiles": ["${workspaceRoot}/dist/**/*.js"],
"smartStep": true,
"skipFiles": [
"<node_internals>/**"
]
},
{
"name": "server",
@@ -27,7 +31,29 @@
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/server/dist/**/*.js"],
"protocol": "inspector",
"restart": true
"restart": true,
"smartStep": true,
"skipFiles": [
"<node_internals>/**"
]
},
{
"name": "E2E Test",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"--extensionTestsPath=${workspaceRoot}/dist/test",
"${workspaceRoot}/test/fixture"
],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/dist/test/**/*.js"],
"smartStep": true,
"skipFiles": [
"<node_internals>/**"
]
}
]
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@
"files.exclude": {
"server/dist": true,
"docs/_book": true,
"client/out": true
"dist": true
}
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@
"prepush": "npm run test:server",
"lint": "tslint -p tslint.json",
"test:server": "cd server && npm run compile && npm test",
"test": "npm run lint && npm run test:server",
"test:e2e": "sh ./test/e2e.sh",
"test": "run-s lint compile test:server test:e2e",
"docs": "bash ./build/update-docs.sh",
"postinstall": "if [[ ${NODE_ENV} != \"production\" ]]; then node ./node_modules/vscode/bin/install; fi"
},
@@ -48,7 +49,7 @@
"activationEvents": [
"onLanguage:vue"
],
"main": "./out/vueMain",
"main": "./dist/client/vueMain",
"contributes": {
"commands": [
{
@@ -308,9 +309,11 @@
}
},
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^8.0.51",
"husky": "^0.14.3",
"lint-staged": "^6.0.0",
"mocha": "^5.2.0",
"npm-run-all": "^4.1.3",
"tslint": "^5.8.0",
"typescript": "^2.8.1",
13 changes: 13 additions & 0 deletions test/definition/1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as vscode from 'vscode';
import { testDefinition, getDocUri } from '../helper';

describe('Should find definition', () => {
const docUri = getDocUri('client/components/Counter.vue');

it('find definition', async () => {
await testDefinition(docUri, new vscode.Position(31, 24), {
range: new vscode.Range(new vscode.Position(21, 6), new vscode.Position(21, 9)),
uri: docUri
});
});
});
6 changes: 6 additions & 0 deletions test/e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

export CODE_TESTS_PATH="$(pwd)/dist/test"
export CODE_TESTS_WORKSPACE="$(pwd)/test/fixture"

node "$(pwd)/node_modules/vscode/bin/test"
21 changes: 21 additions & 0 deletions test/fixture/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017-present, Pine Wu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 28 additions & 0 deletions test/fixture/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Veturpack

Project based on [vuepack](https://github.com/egoist/vuepack) to try [Vetur](https://github.com/octref/vetur).

## Usage

```bash
$ yarn
$ yarn dev
```

## Things to Try

- Do a emmet expansion on the html template.
- Try `_.` in `Counter.vue` to see lodash auto completion.
- Edit `.eslintrc` to config linting rules.
- Remove `// @ts-check` and add it back to see their difference.
- Format the document.
- Change some options in `vetur.format.*` then format again.
- Install another library with types, such as jquery.
- `npm i -S jquery && npm i -D @types/jquery`.
- Put `import * as $ from 'jquery'`.
- Try some jquery auto completion by typing `$.`.
- Try some auto completion in scss.

## License

MIT © [Pine Wu](https://github.com/octref)
10 changes: 10 additions & 0 deletions test/fixture/build/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'
const pkg = require('../package')

module.exports = {
port: 4000,
title: 'veturpack',
// when you use electron please set to relative path like ./
// otherwise only set to absolute path when you're using history mode
publicPath: '/',
}
10 changes: 10 additions & 0 deletions test/fixture/build/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<div id="app"></div>
</body>
</html>
15 changes: 15 additions & 0 deletions test/fixture/build/log-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'
const chalk = require('chalk')

// this plugin if for loggin url after each time the compilation is done.
module.exports = class LogPlugin {
constructor(port) {
this.port = port
}

apply(compiler) {
compiler.plugin('done', () => {
console.log(`> VuePack is running at ${chalk.yellow(`http://localhost:${this.port}`)}\n`)
})
}
}
52 changes: 52 additions & 0 deletions test/fixture/build/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict'
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const express = require('express')
const webpack = require('webpack')
const webpackConfig = require('./webpack.dev')
const config = require('./config')
const LogPlugin = require('./log-plugin')

const app = express()

const port = config.port
webpackConfig.entry.client = [
`webpack-hot-middleware/client?reload=true`,
webpackConfig.entry.client
]

webpackConfig.plugins.push(new LogPlugin(port))

let compiler

try {
compiler = webpack(webpackConfig)
} catch (err) {
console.log(err.message)
process.exit(1)
}

const devMiddleWare = require('webpack-dev-middleware')(compiler, {
publicPath: webpackConfig.output.publicPath,
quiet: true
})
app.use(devMiddleWare)
app.use(require('webpack-hot-middleware')(compiler, {
log: () => {}
}))

const mfs = devMiddleWare.fileSystem
const file = path.join(webpackConfig.output.path, 'index.html')


devMiddleWare.waitUntilValid()

app.get('*', (req, res) => {
devMiddleWare.waitUntilValid(() => {
const html = mfs.readFileSync(file)
res.end(html)
})
})

app.listen(port)
68 changes: 68 additions & 0 deletions test/fixture/build/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict'
const path = require('path')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const config = require('./config')

const _ = module.exports = {}

_.cwd = (file) => {
return path.join(process.cwd(), file || '')
}

_.cssLoader = config.cssModules ?
'css-loader?-autoprefixer&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]' :
'css-loader?-autoprefixer'

_.cssProcessors = [
{loader: '', test: /\.css$/},
{loader: 'sass-loader?sourceMap', test: /\.scss$/},
{loader: 'less-loader?sourceMap', test: /\.less$/},
{loader: 'stylus-loader?sourceMap', test: /\.styl$/},
{loader: 'sass-loader?indentedSyntax&sourceMap', test: /\.sass$/},
]

_.outputPath = config.electron ?
path.join(__dirname, '../app/dist') :
path.join(__dirname, '../dist')

_.outputIndexPath = config.electron ?
path.join(__dirname, '../app/dist/index.html') :
path.join(__dirname, '../dist/index.html')

_.target = config.electron ?
'electron-renderer' :
'web'

// https://github.com/egoist/vbuild/blob/master/lib/vue-loaders.js
_.loadersOptions = () => {
const isProd = process.env.NODE_ENV === 'production'

function generateLoader(langs) {
langs.unshift('css-loader?sourceMap&-autoprefixer')
if (!isProd) {
return ['vue-style-loader'].concat(langs).join('!')
}
return ExtractTextPlugin.extract({
fallback: 'vue-style-loader',
use: langs.join('!')
})
}

return {
minimize: isProd,
options: {
// css-loader relies on context
context: process.cwd(),
vue: {
loaders: {
css: generateLoader([]),
sass: generateLoader(['sass-loader?indentedSyntax&sourceMap']),
scss: generateLoader(['sass-loader?sourceMap']),
less: generateLoader(['less-loader?sourceMap']),
stylus: generateLoader(['stylus-loader?sourceMap']),
js: 'babel-loader'
}
}
}
}
}
Loading