Skip to content

Commit

Permalink
add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
lixinyang123 committed Apr 18, 2024
1 parent 6de37ce commit 81e5b98
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
.pid
27 changes: 24 additions & 3 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,33 @@ await util.test('Server start', async () => {

await util.sleep(1000)
await $`curl -s http://localhost:8080`
console.log('\n')
await app.dispose()
})

await util.test('Basic server', async () => {
await $`echo 'Run basic server example'`
// Link dependence
await $`yarn link`

await util.test('Basic example', async () => {
await util.runExample('example/basic', async () => {
await $`curl -s http://localhost:8080`
})
})

await util.test('Controller example', async () => {
await util.runExample('example/controller', async () => {
await $`curl -s http://localhost:8080`
await $`curl -s http://localhost:8080/home`
await $`curl -s http://localhost:8080/home/index`
await $`curl -s http://localhost:8080/blog`
await $`curl -s http://localhost:8080/blog/index`
await $`curl -s http://localhost:8080/about`
await $`curl -s http://localhost:8080/about/index`
await $`curl -s http://localhost:8080/api/v1`
await $`curl -s http://localhost:8080/api/v1/home`
await $`curl -s http://localhost:8080/api/v1/home/index`
await $`curl -s http://localhost:8080/api/v1/blog`
await $`curl -s http://localhost:8080/api/v1/blog/index`
})
})

util.report()
12 changes: 12 additions & 0 deletions test/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'zx/globals'

let passed = []
let failed = []

Expand Down Expand Up @@ -34,6 +36,16 @@ export default {
}
},

async runExample(path, callback) {
let cwd = process.cwd()
cd(path)
$`node src/main.js & echo $! > .pid`
await sleep(1000)
await callback()
await $`kill $(cat .pid) && rm .pid`
cd(cwd)
},

report() {
console.log('\n========== Report ==========')
console.log(`Passed: ${passed.length}`)
Expand Down

0 comments on commit 81e5b98

Please sign in to comment.