Test improvements.
Clean mojang test directory. Added test for server status. Disable winston in test mode.
This commit is contained in:
parent
c7b95f3719
commit
e76eb91ac9
18
package-lock.json
generated
18
package-lock.json
generated
@ -1418,6 +1418,15 @@
|
|||||||
"integrity": "sha512-aN5IAC8QNtSUdQzxu7lGBgYAOuU1tmRU4c9dIq5OKGf/SBVjXo+ffM2wEjudAWbgpOhy60nLoAGH1xm8fpCKFQ==",
|
"integrity": "sha512-aN5IAC8QNtSUdQzxu7lGBgYAOuU1tmRU4c9dIq5OKGf/SBVjXo+ffM2wEjudAWbgpOhy60nLoAGH1xm8fpCKFQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@types/chai-as-promised": {
|
||||||
|
"version": "7.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/chai-as-promised/-/chai-as-promised-7.1.3.tgz",
|
||||||
|
"integrity": "sha512-FQnh1ohPXJELpKhzjuDkPLR2BZCAqed+a6xV4MI/T3XzHfd2FlarfUGUdZYgqYe8oxkYn0fchHEeHfHqdZ96sg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/chai": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/color-name": {
|
"@types/color-name": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
|
||||||
@ -3078,6 +3087,15 @@
|
|||||||
"type-detect": "^4.0.5"
|
"type-detect": "^4.0.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"chai-as-promised": {
|
||||||
|
"version": "7.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.1.tgz",
|
||||||
|
"integrity": "sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"check-error": "^1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"chalk": {
|
"chalk": {
|
||||||
"version": "4.1.0",
|
"version": "4.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz",
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
"lint": "eslint --ext=jsx,js,tsx,ts src",
|
"lint": "eslint --ext=jsx,js,tsx,ts src",
|
||||||
"dev": "electron-webpack dev",
|
"dev": "electron-webpack dev",
|
||||||
"compile": "electron-webpack",
|
"compile": "electron-webpack",
|
||||||
"test": "cross-env TS_NODE_PROJECT='./tsconfig.test.json' mocha -r ts-node/register -r tsconfig-paths/register test/**/*.ts"
|
"test": "cross-env TS_NODE_PROJECT='./tsconfig.test.json' NODE_ENV=test mocha -r ts-node/register -r tsconfig-paths/register test/**/*.ts"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "12.x.x"
|
"node": "12.x.x"
|
||||||
@ -51,6 +51,7 @@
|
|||||||
"@types/adm-zip": "^0.4.33",
|
"@types/adm-zip": "^0.4.33",
|
||||||
"@types/async": "^3.2.3",
|
"@types/async": "^3.2.3",
|
||||||
"@types/chai": "^4.2.12",
|
"@types/chai": "^4.2.12",
|
||||||
|
"@types/chai-as-promised": "^7.1.3",
|
||||||
"@types/discord-rpc": "^3.0.4",
|
"@types/discord-rpc": "^3.0.4",
|
||||||
"@types/fs-extra": "^9.0.1",
|
"@types/fs-extra": "^9.0.1",
|
||||||
"@types/jquery": "^3.5.1",
|
"@types/jquery": "^3.5.1",
|
||||||
@ -68,6 +69,7 @@
|
|||||||
"@typescript-eslint/eslint-plugin": "^3.10.1",
|
"@typescript-eslint/eslint-plugin": "^3.10.1",
|
||||||
"@typescript-eslint/parser": "^3.10.1",
|
"@typescript-eslint/parser": "^3.10.1",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
|
"chai-as-promised": "^7.1.1",
|
||||||
"cross-env": "^7.0.2",
|
"cross-env": "^7.0.2",
|
||||||
"electron": "^9.2.1",
|
"electron": "^9.2.1",
|
||||||
"electron-builder": "^22.8.0",
|
"electron-builder": "^22.8.0",
|
||||||
|
@ -35,7 +35,7 @@ export class LoggerUtil {
|
|||||||
return `[${moment().format('YYYY-MM-DD hh:mm:ss').trim()}] [${info.level}] [${info.label}]: ${info.message}${info.stack ? `\n${info.stack}` : ''}`
|
return `[${moment().format('YYYY-MM-DD hh:mm:ss').trim()}] [${info.level}] [${info.label}]: ${info.message}${info.stack ? `\n${info.stack}` : ''}`
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
level: 'debug',
|
level: process.env.NODE_ENV === 'test' ? 'emerg' : 'debug',
|
||||||
transports: [
|
transports: [
|
||||||
new transports.Console()
|
new transports.Console()
|
||||||
]
|
]
|
||||||
|
@ -89,7 +89,7 @@ export function getServerStatus(protocol: number, address: string, port = 25565)
|
|||||||
socket.write(getRequestPacket())
|
socket.write(getRequestPacket())
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.setTimeout(10000, () => {
|
socket.setTimeout(5000, () => {
|
||||||
socket.destroy()
|
socket.destroy()
|
||||||
logger.error(`Server Status Socket timed out (${address}:${port})`)
|
logger.error(`Server Status Socket timed out (${address}:${port})`)
|
||||||
reject(new Error(`Server Status Socket timed out (${address}:${port})`))
|
reject(new Error(`Server Status Socket timed out (${address}:${port})`))
|
||||||
|
52
test/mojang/net/ServerStatusAPITest.ts
Normal file
52
test/mojang/net/ServerStatusAPITest.ts
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import chai, { expect } from 'chai'
|
||||||
|
import chaiAsPromised from 'chai-as-promised'
|
||||||
|
import { getServerStatus, ServerStatus } from 'common/mojang/net/ServerStatusAPI'
|
||||||
|
|
||||||
|
chai.use(chaiAsPromised)
|
||||||
|
|
||||||
|
describe('[Server Status API] Errors', () => {
|
||||||
|
|
||||||
|
it('Server Status (Not Found)', async () => {
|
||||||
|
|
||||||
|
await expect(getServerStatus(47, 'a', 25565)).to.eventually.be.null
|
||||||
|
|
||||||
|
}).timeout(5000)
|
||||||
|
|
||||||
|
it('Server Status (Wrong Port)', async () => {
|
||||||
|
|
||||||
|
await expect(getServerStatus(47, 'play.hypixel.net', 34454)).to.eventually.be.null
|
||||||
|
|
||||||
|
}).timeout(5000)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
function verifyResult(res: ServerStatus): void {
|
||||||
|
expect(res).to.not.be.null
|
||||||
|
expect(res).to.be.an('object')
|
||||||
|
expect(res).to.have.property('version')
|
||||||
|
expect(res).to.have.property('players')
|
||||||
|
expect(res).to.have.property('description')
|
||||||
|
expect(res.players).to.be.an('object')
|
||||||
|
expect(res.players).to.have.property('max')
|
||||||
|
expect(res.players).to.have.property('online')
|
||||||
|
expect(res.description).to.be.an('object')
|
||||||
|
expect(res.description).to.have.property('text')
|
||||||
|
}
|
||||||
|
|
||||||
|
const serversToCheck = [
|
||||||
|
'play.hypixel.net',
|
||||||
|
'play.hivemc.com',
|
||||||
|
'us.mineplex.com'
|
||||||
|
]
|
||||||
|
|
||||||
|
describe('[Server Status API] Server Status', () => {
|
||||||
|
|
||||||
|
for(const server of serversToCheck) {
|
||||||
|
it(`Server Status (${server})`, async () => {
|
||||||
|
|
||||||
|
verifyResult((await getServerStatus(47, server, 25565))!)
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
@ -31,7 +31,7 @@ function expectMojangResponse(res: MojangResponse<unknown>, responseCode: Mojang
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Mojang Errors', () => {
|
describe('[Mojang Rest API] Errors', () => {
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
nock.cleanAll()
|
nock.cleanAll()
|
||||||
@ -72,7 +72,7 @@ describe('Mojang Errors', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Mojang Status', () => {
|
describe('[Mojang Rest API] Status', () => {
|
||||||
|
|
||||||
it('Status (Online)', async () => {
|
it('Status (Online)', async () => {
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ describe('Mojang Status', () => {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Mojang Auth', () => {
|
describe('[Mojang Rest API] Auth', () => {
|
||||||
|
|
||||||
it('Authenticate', async () => {
|
it('Authenticate', async () => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user