Skip to content

Commit

Permalink
fix: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchuzhang committed Sep 13, 2022
1 parent 79f1dac commit 2ac3c95
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
coverage
*.log
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORKDIR /app

COPY ["package.json", "pnpm-lock.yaml*", "./"]

RUN pnpm intall
RUN pnpm install

COPY . .

Expand Down
13 changes: 10 additions & 3 deletions __test__/hello.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import axios from 'axios'
import { stopServer } from './helpers/server'
import { stopServer, startServer } from './helpers/server'

let origin: string

beforeAll(async () => {
const port = await startServer()
origin = `http://localhost:${port}`
})

afterAll(() => {
stopServer()
})

describe('hello', () => {
it('world', async () => {
const res = await axios.get('http://localhost:4001/api/hello/world')
expect(1 + 199).toEqual(200)
const res = await axios.get(`${origin}/api/hello/world`)
expect(res.status).toEqual(200)
})
})
14 changes: 11 additions & 3 deletions __test__/helpers/server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { exec } from 'child_process'
import portfinder from 'portfinder'
import * as http from 'http'
import { delay } from './utils'
import app from '../../src/app'

const server = app.listen(4001)
let server: http.Server

export const startServer = async () => {
await delay(1000)
const port = await portfinder.getPortPromise({ port: 4001 })
server = app.listen(port)
return port
}

export const stopServer = async () => {
server.close()
server?.close()
}
17 changes: 12 additions & 5 deletions __test__/proxy.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
import axios from 'axios'
import { stopServer } from './helpers/server'
import { stopServer, startServer } from './helpers/server'

let origin: string

beforeAll(async () => {
const port = await startServer()
origin = `http://localhost:${port}`
})

afterAll(() => {
stopServer()
})

describe('proxy', () => {
it('kuwo', async () => {
const res = await axios.get('http://localhost:4001/api/kuwo')
const res = await axios.get(`${origin}/api/kuwo`)
expect(res.status).toEqual(200)
})

it('163', async () => {
const res = await axios.get('http://localhost:4001/api/music163/api/artist/10559')
const res = await axios.get(`${origin}/api/music163/api/artist/10559`)
expect(res.status).toEqual(200)
})

it('migu', async () => {
const res = await axios.get('http://localhost:4001/api/appcnfmigu/MIGUM3.0/v1.0/template/rank-list/release?dataVersion=1616469593718&templateVersion=9')
const res = await axios.get(`${origin}/api/appcnfmigu/MIGUM3.0/v1.0/template/rank-list/release?dataVersion=1616469593718&templateVersion=9`)
expect(res.status).toEqual(200)
})

it('migu', async () => {
const res = await axios.get('http://localhost:4001/api/cyqq/v8/fcg-bin/fcg_myqq_toplist.fcg?g_tk=5381&inCharset=utf-8&outCharset=utf-8&notice=0&format=json&uin=0&needNewCode=1&platform=h5')
const res = await axios.get(`${origin}/api/cyqq/v8/fcg-bin/fcg_myqq_toplist.fcg?g_tk=5381&inCharset=utf-8&outCharset=utf-8&notice=0&format=json&uin=0&needNewCode=1&platform=h5`)
expect(res.status).toEqual(200)
})
})
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"dev": "nodemon -r @swc-node/register src/server.ts",
"test": "jest",
"test": "jest --coverage --silent",
"server": "node -r @swc-node/register src/server.ts"
},
"author": "",
Expand All @@ -25,6 +25,7 @@
"@types/jest": "^29.0.0",
"@types/node": "^18.7.17",
"jest": "^29.0.2",
"nodemon": "^2.0.19"
"nodemon": "^2.0.19",
"portfinder": "^1.0.32"
}
}
57 changes: 57 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"allowSyntheticDefaultImports": true,
"types": ["node"]
},
"include": ["*.ts", "./**/*.ts"],
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"types": ["node", "jest"]
},
"extends": "./tsconfig.json",
"include": ["./__test__/*.ts", "./__test__/**/*.ts"],
"include": ["__test__/**/*.ts"],
"exclude": ["node_modules"]
}

0 comments on commit 2ac3c95

Please sign in to comment.