Skip to content

Commit 03a614a

Browse files
authored
feat: add testCase page json lint (#506)
* feat: add testCase page json lint * fix the test case save and run method * add shortcut for sending request --------- Co-authored-by: rick <[email protected]>
1 parent 3aceced commit 03a614a

File tree

8 files changed

+306
-80
lines changed

8 files changed

+306
-80
lines changed

console/atest-ui/package-lock.json

+251-64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

console/atest-ui/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
"test": "vitest"
1717
},
1818
"dependencies": {
19+
"@vueuse/core": "^10.11.0",
1920
"element-plus": "^2.3.7",
2021
"intro.js": "^7.0.1",
22+
"jsonlint-mod": "^1.7.6",
2123
"jsonpath-plus": "^7.2.0",
2224
"skywalking-client-js": "^0.10.0",
2325
"vue": "^3.3.4",

console/atest-ui/src/locales/en.json

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"403": "403 Forbidden",
7878
"405": "405 Method Not Allowed",
7979
"409": "409 Conflict",
80+
"415": "415 Unsupported Media Type",
8081
"422": "422 Unprocessable Content",
8182
"500": "500 Internal Server Error",
8283
"502": "502 Bad Gateway",

console/atest-ui/src/views/TestCase.vue

+42-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import type { TestCaseResponse } from './cache'
1212
import { useI18n } from 'vue-i18n'
1313
import { JSONPath } from 'jsonpath-plus'
1414
import { Codemirror } from 'vue-codemirror'
15+
import jsonlint from 'jsonlint-mod'
16+
import { useMagicKeys } from '@vueuse/core'
1517
18+
const keys = useMagicKeys()
19+
const keyAltS = keys['Alt+S']
1620
const { t } = useI18n()
1721
1822
const props = defineProps({
@@ -26,14 +30,25 @@ let querySuggestedAPIs = NewSuggestedAPIsQuery(Cache.GetCurrentStore().name!, pr
2630
const testResultActiveTab = ref(Cache.GetPreference().responseActiveTab)
2731
watch(testResultActiveTab, Cache.WatchResponseActiveTab)
2832
33+
watch(keyAltS, (v) => {
34+
if (v) {
35+
sendRequest()
36+
}
37+
})
38+
2939
const parameters = ref([] as Pair[])
3040
const requestLoading = ref(false)
3141
const testResult = ref({ header: [] as Pair[] } as TestResult)
3242
const sendRequest = async () => {
3343
if (needUpdate.value) {
34-
await saveTestCase(false)
44+
await saveTestCase(false, runTestCase)
45+
needUpdate.value = false
46+
} else {
47+
runTestCase()
3548
}
49+
}
3650
51+
const runTestCase = () => {
3752
requestLoading.value = true
3853
const name = props.name
3954
const suite = props.suite
@@ -280,14 +295,18 @@ watch(testCaseWithSuite, (after, before) => {
280295
}, { deep: true })
281296
282297
const saveLoading = ref(false)
283-
function saveTestCase(tip: boolean = true) {
298+
function saveTestCase(tip: boolean = true, callback: (c: any) => void) {
284299
UIAPI.UpdateTestCase(testCaseWithSuite.value, (e) => {
285300
if (tip) {
286301
ElMessage({
287302
message: 'Saved.',
288303
type: 'success'
289304
})
290305
}
306+
307+
if (callback) {
308+
callback()
309+
}
291310
}, UIAPI.ErrorTip, saveLoading)
292311
}
293312
@@ -433,15 +452,21 @@ function bodyTypeChange(e: number) {
433452
}
434453
}
435454
436-
function jsonFormat() {
437-
if (bodyType.value !== 5) {
455+
const lintingError = ref('')
456+
function jsonFormat(space) {
457+
const jsonText = testCaseWithSuite.value.data.request.body
458+
if (bodyType.value !== 5 || jsonText === '') {
438459
return
439460
}
440461
441462
try {
442-
testCaseWithSuite.value.data.request.body = JSON.stringify(JSON.parse(testCaseWithSuite.value.data.request.body), null, 4)
463+
const jsonObj = jsonlint.parse(jsonText)
464+
if (space >= 0) {
465+
testCaseWithSuite.value.data.request.body = JSON.stringify(jsonObj, null, space)
466+
}
467+
lintingError.value = ''
443468
} catch (e) {
444-
console.log(e)
469+
lintingError.value = e.message
445470
}
446471
}
447472
@@ -539,7 +564,7 @@ const duplicateTestCase = () => {
539564
v-model="testCaseWithSuite.data.request.method"
540565
class="m-2"
541566
placeholder="Method"
542-
size="middle"
567+
size="default"
543568
test-id="case-editor-method"
544569
>
545570
<el-option
@@ -654,6 +679,11 @@ const duplicateTestCase = () => {
654679
</el-tab-pane>
655680

656681
<el-tab-pane name="body">
682+
<span style="margin-right: 10px; padding-right: 5px;">
683+
<el-button type="primary" @click="jsonFormat(4)">Beautify</el-button>
684+
<el-button type="primary" @click="jsonFormat(0)">Minify</el-button>
685+
<el-text class="mx-1">Choose the body format</el-text>
686+
</span>
657687
<template #label>
658688
<el-badge :is-dot="testCaseWithSuite.data.request.body !== ''" class="item">Body</el-badge>
659689
</template>
@@ -667,7 +697,7 @@ const duplicateTestCase = () => {
667697

668698
<div style="flex-grow: 1;">
669699
<Codemirror v-if="bodyType === 3 || bodyType === 5"
670-
@change="jsonFormat"
700+
@blur="jsonFormat(-1)"
671701
v-model="testCaseWithSuite.data.request.body"/>
672702
<el-table :data="testCaseWithSuite.data.request.form" style="width: 100%" v-if="bodyType === 4">
673703
<el-table-column label="Key" width="180">
@@ -684,6 +714,9 @@ const duplicateTestCase = () => {
684714
</el-table-column>
685715
</el-table>
686716
</div>
717+
<div v-if="lintingError" style="color: red; margin-top: 10px;">
718+
{{ lintingError }}
719+
</div>
687720
</el-tab-pane>
688721

689722
<el-tab-pane label="Expected" name="expected" v-if="props.kindName !== 'tRPC' && props.kindName !== 'gRPC'">
@@ -777,7 +810,7 @@ const duplicateTestCase = () => {
777810
v-model="currentCodeGenerator"
778811
class="m-2"
779812
style="padding-right: 10px;"
780-
size="middle"
813+
size="default"
781814
>
782815
<el-option
783816
v-for="item in codeGenerators"

e2e/code-generator/start.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/bash
22
set -e
33

4-
docker-compose version
4+
docker compose version
55

66
targets=(golang java python javascript curl)
77
for target in "${targets[@]}"
88
do
9-
docker-compose down
10-
docker-compose up --build $target --exit-code-from $target
9+
docker compose down
10+
docker compose up --build $target --exit-code-from $target
1111
done

e2e/start.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ then
66
file=compose.yaml
77
fi
88

9-
docker-compose version
10-
docker-compose -f "$file" down
11-
docker-compose -f "$file" up --build testing --exit-code-from testing --remove-orphans
9+
docker compose version
10+
docker compose -f "$file" down
11+
docker compose -f "$file" up --build testing --exit-code-from testing --remove-orphans

tools/make/run.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ ATEST_UI = console/atest-ui
1010

1111
.PHONY: run-server
1212
run-server: ## Run the API Testing server
13-
run-server: build-ui
13+
run-server: build-ui run-backend
14+
run-backend:
1415
go run . server --local-storage 'bin/*.yaml' --console-path ${ATEST_UI}/dist --extension-registry ghcr.io
1516

1617
.PHONY: run-console

tools/make/ui.mk

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ BUILD_FLAGS += \
1313
.PHONY: build.ui
1414
build.ui:
1515
cd ${ATEST_UI} && ${FRONT_RUNTIMES} i && ${FRONT_RUNTIMES} run build-only
16+
run-ui:
17+
cd ${ATEST_UI} && ${FRONT_RUNTIMES} i && ${FRONT_RUNTIMES} run dev
1618

1719
.PHONY: build.embed.ui
1820
build.embed.ui: embed.ui

0 commit comments

Comments
 (0)