-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vue-generator): add test coverage script and app generate test case
- Loading branch information
1 parent
4d80866
commit 802e1a0
Showing
36 changed files
with
1,808 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,7 @@ module.exports = { | |
ecmaFeatures: { | ||
jsx: true | ||
} | ||
} | ||
}, | ||
// 忽略 expected 中的内容 | ||
ignorePatterns: ['**/**/expected/*'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
test/**/result/* | ||
|
||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/vue-generator/test/testcases/generator/expected/appdemo01/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
node_modules | ||
dist/ | ||
|
||
# local env files | ||
.env.local | ||
.env.*.local | ||
|
||
# Editor directories and files | ||
.vscode | ||
.idea | ||
|
||
yarn.lock | ||
package-lock.json |
19 changes: 19 additions & 0 deletions
19
packages/vue-generator/test/testcases/generator/expected/appdemo01/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## portal-app | ||
|
||
本工程是使用 TinyEngine 低代码引擎搭建之后得到的出码工程。 | ||
|
||
## 使用 | ||
|
||
安装依赖: | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
本地启动项目: | ||
|
||
```bash | ||
npm run dev | ||
``` | ||
|
||
|
13 changes: 13 additions & 0 deletions
13
packages/vue-generator/test/testcases/generator/expected/appdemo01/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>portal-app</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.js"></script> | ||
</body> | ||
</html> |
27 changes: 27 additions & 0 deletions
27
packages/vue-generator/test/testcases/generator/expected/appdemo01/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "portal-app", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"main": "dist/index.js", | ||
"module": "dist/index.js", | ||
"dependencies": { | ||
"@opentiny/tiny-engine-i18n-host": "^1.0.0", | ||
"@opentiny/vue": "latest", | ||
"@opentiny/vue-icon": "latest", | ||
"axios": "latest", | ||
"axios-mock-adapter": "^1.19.0", | ||
"vue": "^3.3.9", | ||
"vue-i18n": "^9.2.0-beta.3", | ||
"vue-router": "^4.2.5", | ||
"pinia": "^2.1.7" | ||
}, | ||
"devDependencies": { | ||
"@vitejs/plugin-vue": "^4.5.1", | ||
"@vitejs/plugin-vue-jsx": "^3.1.0", | ||
"vite": "^4.3.7" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/vue-generator/test/testcases/generator/expected/appdemo01/src/App.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<router-view></router-view> | ||
</template> | ||
|
||
<script setup> | ||
import { I18nInjectionKey } from 'vue-i18n' | ||
import { provide } from 'vue' | ||
import i18n from './i18n' | ||
provide(I18nInjectionKey, i18n) | ||
</script> |
139 changes: 139 additions & 0 deletions
139
packages/vue-generator/test/testcases/generator/expected/appdemo01/src/http/axios.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/** | ||
* Copyright (c) 2023 - present TinyEngine Authors. | ||
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd. | ||
* | ||
* Use of this source code is governed by an MIT-style license. | ||
* | ||
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, | ||
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR | ||
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. | ||
* | ||
*/ | ||
|
||
import axios from 'axios' | ||
import MockAdapter from 'axios-mock-adapter' | ||
|
||
export default (config) => { | ||
const instance = axios.create(config) | ||
const defaults = {} | ||
let mock | ||
|
||
if (typeof MockAdapter.prototype.proxy === 'undefined') { | ||
MockAdapter.prototype.proxy = function ({ url, config = {}, proxy, response, handleData } = {}) { | ||
let stream = this | ||
const request = (proxy, any) => { | ||
return (setting) => { | ||
return new Promise((resolve) => { | ||
config.responseType = 'json' | ||
axios | ||
.get(any ? proxy + setting.url + '.json' : proxy, config) | ||
.then(({ data }) => { | ||
/* eslint-disable no-useless-call */ | ||
typeof handleData === 'function' && (data = handleData.call(null, data, setting)) | ||
resolve([200, data]) | ||
}) | ||
.catch((error) => { | ||
resolve([error.response.status, error.response.data]) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
if (url === '*' && proxy && typeof proxy === 'string') { | ||
stream = proxy === '*' ? this.onAny().passThrough() : this.onAny().reply(request(proxy, true)) | ||
} else { | ||
if (proxy && typeof proxy === 'string') { | ||
stream = this.onAny(url).reply(request(proxy)) | ||
} else if (typeof response === 'function') { | ||
stream = this.onAny(url).reply(response) | ||
} | ||
} | ||
|
||
return stream | ||
} | ||
} | ||
|
||
return { | ||
request(config) { | ||
return instance(config) | ||
}, | ||
get(url, config) { | ||
return instance.get(url, config) | ||
}, | ||
delete(url, config) { | ||
return instance.delete(url, config) | ||
}, | ||
head(url, config) { | ||
return instance.head(url, config) | ||
}, | ||
post(url, data, config) { | ||
return instance.post(url, data, config) | ||
}, | ||
put(url, data, config) { | ||
return instance.put(url, data, config) | ||
}, | ||
patch(url, data, config) { | ||
return instance.patch(url, data, config) | ||
}, | ||
all(iterable) { | ||
return axios.all(iterable) | ||
}, | ||
spread(callback) { | ||
return axios.spread(callback) | ||
}, | ||
defaults(key, value) { | ||
if (key && typeof key === 'string') { | ||
if (typeof value === 'undefined') { | ||
return instance.defaults[key] | ||
} | ||
instance.defaults[key] = value | ||
defaults[key] = value | ||
} else { | ||
return instance.defaults | ||
} | ||
}, | ||
defaultSettings() { | ||
return defaults | ||
}, | ||
interceptors: { | ||
request: { | ||
use(fnHandle, fnError) { | ||
return instance.interceptors.request.use(fnHandle, fnError) | ||
}, | ||
eject(id) { | ||
return instance.interceptors.request.eject(id) | ||
} | ||
}, | ||
response: { | ||
use(fnHandle, fnError) { | ||
return instance.interceptors.response.use(fnHandle, fnError) | ||
}, | ||
eject(id) { | ||
return instance.interceptors.response.eject(id) | ||
} | ||
} | ||
}, | ||
mock(config) { | ||
if (!mock) { | ||
mock = new MockAdapter(instance) | ||
} | ||
|
||
if (Array.isArray(config)) { | ||
config.forEach((item) => { | ||
mock.proxy(item) | ||
}) | ||
} | ||
|
||
return mock | ||
}, | ||
disableMock() { | ||
mock && mock.restore() | ||
mock = undefined | ||
}, | ||
isMock() { | ||
return typeof mock !== 'undefined' | ||
}, | ||
CancelToken: axios.CancelToken, | ||
isCancel: axios.isCancel | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/vue-generator/test/testcases/generator/expected/appdemo01/src/http/config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Copyright (c) 2023 - present TinyEngine Authors. | ||
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd. | ||
* | ||
* Use of this source code is governed by an MIT-style license. | ||
* | ||
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, | ||
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR | ||
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. | ||
* | ||
*/ | ||
|
||
export default { | ||
withCredentials: false | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/vue-generator/test/testcases/generator/expected/appdemo01/src/http/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (c) 2023 - present TinyEngine Authors. | ||
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd. | ||
* | ||
* Use of this source code is governed by an MIT-style license. | ||
* | ||
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, | ||
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR | ||
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. | ||
* | ||
*/ | ||
|
||
import axios from './axios' | ||
import config from './config' | ||
|
||
export default (dataHandler) => { | ||
const http = axios(config) | ||
|
||
http.interceptors.response.use(dataHandler, (error) => { | ||
const response = error.response | ||
if (response.status === 403 && response.headers && response.headers['x-login-url']) { | ||
// TODO 处理无权限时,重新登录再发送请求 | ||
} | ||
}) | ||
|
||
return http | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/vue-generator/test/testcases/generator/expected/appdemo01/src/i18n/en_US.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"lowcode.c257d5e8": "search", | ||
"lowcode.61c8ac8c": "dsdsa", | ||
"lowcode.f53187a0": "test", | ||
"lowcode.97ad00dd": "createMaterial", | ||
"lowcode.61dcef52": "sadasda", | ||
"lowcode.45f4c42a": "gfdgfd", | ||
"lowcode.c6f5a652": "fsdafds", | ||
"lowcode.34923432": "fdsafds", | ||
"lowcode.6534943e": "fdsafdsa", | ||
"lowcode.44252642": "aaaa", | ||
"lowcode.2a743651": "fdsaf", | ||
"lowcode.24315357": "fsdafds", | ||
"lowcode.44621691": "sd", | ||
"lowcode.65636226": "fdsfsd", | ||
"lowcode.6426a4e2": "fdsafsd", | ||
"lowcode.e41c6636": "aa", | ||
"lowcode.51c23164": "aa", | ||
"lowcode.17245b46": "aa", | ||
"lowcode.4573143c": "a", | ||
"lowcode.56432442": "aa", | ||
"lowcode.33566643": "aa", | ||
"lowcode.565128f3": "aa", | ||
"lowcode.56643835": "aa" | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/vue-generator/test/testcases/generator/expected/appdemo01/src/i18n/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import i18n from '@opentiny/tiny-engine-i18n-host' | ||
import lowcode from '../lowcodeConfig/lowcode' | ||
import locale from './locale.js' | ||
|
||
i18n.lowcode = lowcode | ||
i18n.global.mergeLocaleMessage('en_US', locale.en_US) | ||
i18n.global.mergeLocaleMessage('zh_CN', locale.zh_CN) | ||
|
||
export default i18n |
4 changes: 4 additions & 0 deletions
4
packages/vue-generator/test/testcases/generator/expected/appdemo01/src/i18n/locale.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import en_US from './en_US.json' | ||
import zh_CN from './zh_CN.json' | ||
|
||
export default { en_US, zh_CN } |
Oops, something went wrong.