Skip to content

Commit c61b4bb

Browse files
committed
fix jsclient
1 parent c97a138 commit c61b4bb

File tree

6 files changed

+20
-25
lines changed

6 files changed

+20
-25
lines changed

.github/workflows/spa-server-ci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ jobs:
5959
- uses: actions/checkout@v4
6060
- name: Run spa-server docker
6161
run: |
62-
docker run -d \
63-
-p 9000:9000 -p 8080:8080 \
64-
--mount type=bind,source=${{ github.workspace }}/jsclient/test/config.toml,target=/config/config.toml \
65-
ghcr.io/fornetcode/spa-server:latest
62+
docker run -d -p 9000:9000 -p 8080:8080 -v $(PWD)/jsclient/test/config.toml:/config/config.toml ghcr.io/fornetcode/spa-server:2.4.0
6663
- uses: actions/setup-node@v4
6764
with:
6865
node-version: '20.x'

docs/develop/change-log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- improve: bump deps version.
66
- ci: jsclient can test auto.
77
- feat: remove openTelemetry trace.
8+
- jsclient: change info response to pure json
89

910
### Version 2.4.0
1011

jsclient/src/command.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async function getClient(configPath: string | undefined) {
5757
}
5858

5959
function writeResult(func: () => Promise<any>) {
60-
func().then((v) => console.log(chalk.green(v))).catch((e) => {
60+
func().then((v) => console.log(v)).catch((e) => {
6161
console.error(e)
6262
process.exit(-1)
6363
})
@@ -72,7 +72,7 @@ const info = command({
7272
handler: ({domain, config}) => {
7373
writeResult(async () => {
7474
const client = await getClient(config)
75-
return await client.getDomainInfo(domain)
75+
return JSON.stringify(await client.getDomainInfo(domain))
7676
})
7777
}
7878
})
@@ -117,7 +117,7 @@ const reload = command({
117117
writeResult(async () => {
118118
const client = await getClient(config)
119119
await client.reloadSPAServer()
120-
return "reload successful"
120+
return chalk.green("reload successful")
121121
})
122122
}
123123
})
@@ -132,7 +132,7 @@ const deleteCmd = command({
132132
writeResult(async () => {
133133
const client = await getClient(config)
134134
await client.removeFiles(domain, maxReserve)
135-
return "delete successful"
135+
return chalk.green("delete successful")
136136
})
137137
}
138138
})
@@ -147,7 +147,7 @@ const revokeVersionCmd = command({
147147
writeResult(async () => {
148148
const client = await getClient(config)
149149
await client.revokeVersion(domain, version)
150-
return "revoke successful"
150+
return chalk.green("revoke successful")
151151
})
152152
}
153153
})

jsclient/test/command.spec.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,16 @@ test('info', async () => {
1313
})
1414

1515
test('upload', async () => {
16-
const exampleProjectDir = path.resolve(__dirname, '../../example/js-app-example/build')
17-
try {
18-
const result = await runCommand(['upload', path.join(exampleProjectDir, 'build'), LOCAL_HOST])
19-
console.log(result)
20-
} catch (e) {
21-
// expect error
22-
}
16+
const exampleProjectDir = path.resolve(__dirname, '../../example/js-app-example')
17+
18+
const result = await runCommand(['upload', path.join(exampleProjectDir, 'build'), LOCAL_HOST])
19+
console.log(result)
20+
2321
})
2422
test('release', async () => {
25-
try {
26-
const result = await runCommand(['release', LOCAL_HOST])
27-
console.log(result)
28-
} catch (e) {
29-
30-
}
23+
const result = await runCommand(['release', LOCAL_HOST])
24+
console.log(result)
25+
expect(await runCommand(['info'])).toBe(`[{"domain":"${LOCAL_HOST}","current_version":1,"versions":[1]}]`)
3126
})
3227

3328

jsclient/test/config.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
file_dir = "./data"
2-
cors = []
2+
cors = true # would change
33
[http]
44
port = 8080
55
addr = "0.0.0.0"
66

77
[admin_config]
88
port = 9000
9-
addr = "0.0.0.0"
9+
addr = "0.0.0.0"
10+
token = "token"

jsclient/test/practice.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//@ts-ignore
22
import parse from '@pushcorn/hocon-parser'
33
import walkdir from "walkdir";
4+
45
test("hocon-parser can load files ", async () => {
56
const data = await parse({url: './test/example.conf'})
67
expect(data).toStrictEqual({a:{b:2}})
@@ -9,7 +10,7 @@ test("hocon-parser can load files ", async () => {
910

1011
test("read directory", async () => {
1112

12-
const files = await walkdir.async('./test', {return_object: true})
13+
const files = await walkdir.async('./test/practise', {return_object: true})
1314
Object.keys(files).forEach((path) => {
1415
const stat = files[path]
1516
if(stat.isFile()) {

0 commit comments

Comments
 (0)