Skip to content

Commit

Permalink
feat(vue-generator): add test coverage script and app generate test case
Browse files Browse the repository at this point in the history
  • Loading branch information
chilingling committed Apr 9, 2024
1 parent 4d80866 commit 802e1a0
Show file tree
Hide file tree
Showing 36 changed files with 1,808 additions and 34 deletions.
4 changes: 3 additions & 1 deletion packages/vue-generator/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ module.exports = {
ecmaFeatures: {
jsx: true
}
}
},
// 忽略 expected 中的内容
ignorePatterns: ['**/**/expected/*']
}
2 changes: 2 additions & 0 deletions packages/vue-generator/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
test/**/result/*

coverage
3 changes: 3 additions & 0 deletions packages/vue-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"test": "npx nyc@latest --reporter=lcov node test/test_generator.js",
"test:latest": "npm run build && node test/testcases/full/index.js",
"test:unit": "vitest",
"coverage": "vitest run --coverage",
"publish:npm": "npm publish --verbose"
},
"repository": {
Expand All @@ -36,7 +37,9 @@
},
"devDependencies": {
"@rushstack/eslint-patch": "^1.1.1",
"@vitest/coverage-v8": "^1.4.0",
"@vue/eslint-config-prettier": "^7.0.0",
"dir-compare": "^4.2.0",
"eslint": "^8.12.0",
"eslint-plugin-vue": "^8.6.0",
"fs-extra": "^10.0.1",
Expand Down
11 changes: 11 additions & 0 deletions packages/vue-generator/src/generator/codeGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ class CodeGenerator {

return true
}
deleteFile(file) {
const { path, fileName } = file
const index = this.genResult.findIndex((item) => item.path === path && item.fileName === fileName)

if (index !== -1) {
this.genResult.splice(index, 1)
return true
}

return false
}
replaceFile(resultItem) {
const { path, fileName } = resultItem

Expand Down
2 changes: 1 addition & 1 deletion packages/vue-generator/src/plugins/parseSchemaPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function parseSchema() {
* @param {import('../generator/generateApp').AppSchema} schema
* @returns
*/
parse(schema) {
run(schema) {
const { pageSchema } = schema
const pagesMap = {}
const resPageTree = []
Expand Down
6 changes: 5 additions & 1 deletion packages/vue-generator/src/utils/parseRequiredBlocks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export const parseRequiredBlocks = (schema) => {
const res = []

for (const item of schema?.children || []) {
if (!Array.isArray(schema?.children)) {
return res
}

for (const item of schema.children) {
if (item.componentType === 'Block') {
res.push(item.componentName)
}
Expand Down
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## portal-app

本工程是使用 TinyEngine 低代码引擎搭建之后得到的出码工程。

## 使用

安装依赖:

```bash
npm install
```

本地启动项目:

```bash
npm run dev
```


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>
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"
}
}
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>
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
}
}
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
}
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
}
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"
}
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
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 }
Loading

0 comments on commit 802e1a0

Please sign in to comment.