mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 10:55:05 -05:00
Improve CI setup for per version tests (#1267)
* Improve CI setup: move lint out of per version * fix * Simplify go back to all per version. * refactor cycle test to use supported versions * fix cycle packet test * Add v to version to avoid 1.19 running every 1.19 minor. * Add quotes. * Use versions from js file in ci.yml * Fix ci.yml syntax. * Fix matrix read. * fix * fix * fix gitignore
This commit is contained in:
parent
9e99109476
commit
1740124c47
9 changed files with 90 additions and 64 deletions
48
.github/workflows/ci.yml
vendored
48
.github/workflows/ci.yml
vendored
|
@ -9,11 +9,38 @@ on:
|
|||
- master
|
||||
|
||||
jobs:
|
||||
Lint:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js 18.x
|
||||
uses: actions/setup-node@v1.4.4
|
||||
with:
|
||||
node-version: 18.x
|
||||
- run: npm i && npm run lint
|
||||
PrepareSupportedVersions:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js 18.x
|
||||
uses: actions/setup-node@v1.4.4
|
||||
with:
|
||||
node-version: 18.x
|
||||
- id: set-matrix
|
||||
run: |
|
||||
node -e "
|
||||
const supportedVersions = require('./src/version').supportedVersions;
|
||||
console.log('matrix='+JSON.stringify({'include': supportedVersions.map(mcVersion => ({mcVersion}))}))
|
||||
" >> $GITHUB_OUTPUT
|
||||
test:
|
||||
needs: PrepareSupportedVersions
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
mcVersion: ['1.7', '1.8', '1.9', '1.10', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17', '1.17.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20', '1.20.1']
|
||||
matrix: ${{fromJson(needs.PrepareSupportedVersions.outputs.matrix)}}
|
||||
fail-fast: false
|
||||
|
||||
steps:
|
||||
|
@ -30,19 +57,4 @@ jobs:
|
|||
- name: Install dependencies
|
||||
run: npm install
|
||||
- name: Run tests
|
||||
run: npm test -- -g ${{ matrix.mcVersion }}
|
||||
packet-cycle-test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js 18.x
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 18.x
|
||||
- name: Setup Java JDK
|
||||
uses: actions/setup-java@v1.4.3
|
||||
with:
|
||||
java-version: '16'
|
||||
distribution: 'adopt'
|
||||
- run: npm install && npm run test-non-par
|
||||
run: npm run mochaTest -- -g ${{ matrix.mcVersion }}v
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,6 +1,6 @@
|
|||
node_modules
|
||||
test/npm-debug.log
|
||||
test/server*
|
||||
test/server_*
|
||||
package-lock.json
|
||||
versions/
|
||||
src/client/*.json
|
|
@ -9,8 +9,8 @@
|
|||
"url": "git://github.com/PrismarineJS/node-minecraft-protocol.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha --recursive --reporter spec --exit --exclude \"non-par-test.js\"",
|
||||
"test-non-par": "mocha --recursive --reporter spec --exit \"test/non-par-test.js\"",
|
||||
"test": "npm run mochaTest",
|
||||
"mochaTest": "mocha --recursive --reporter spec --exit",
|
||||
"lint": "standard",
|
||||
"fix": "standard --fix",
|
||||
"pretest": "npm run lint",
|
||||
|
|
|
@ -16,7 +16,7 @@ const testDataWrite = [
|
|||
for (const supportedVersion of mc.supportedVersions) {
|
||||
const mcData = require('minecraft-data')(supportedVersion)
|
||||
const version = mcData.version
|
||||
describe('benchmark ' + version.minecraftVersion, function () {
|
||||
describe('benchmark ' + supportedVersion + 'v', function () {
|
||||
this.timeout(60 * 1000)
|
||||
const inputData = []
|
||||
it('bench serializing', function (done) {
|
||||
|
|
|
@ -28,7 +28,7 @@ for (const supportedVersion of mc.supportedVersions) {
|
|||
console.log(line)
|
||||
})
|
||||
|
||||
describe('client ' + version.minecraftVersion, function () {
|
||||
describe('client ' + supportedVersion + 'v', function () {
|
||||
this.timeout(10 * 60 * 1000)
|
||||
|
||||
before(async function () {
|
||||
|
|
53
test/cyclePacketTest.js
Normal file
53
test/cyclePacketTest.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
/* eslint-env mocha */
|
||||
// Tests packet serialization/deserialization from with raw binary from minecraft-packets
|
||||
const { createSerializer, createDeserializer, states, supportedVersions } = require('minecraft-protocol')
|
||||
const mcPackets = require('minecraft-packets')
|
||||
const assert = require('assert')
|
||||
|
||||
const makeClientSerializer = version => createSerializer({ state: states.PLAY, version, isServer: true })
|
||||
const makeClientDeserializer = version => createDeserializer({ state: states.PLAY, version })
|
||||
|
||||
for (const supportedVersion of supportedVersions) {
|
||||
let serializer, deserializer, data
|
||||
const mcData = require('minecraft-data')(supportedVersion)
|
||||
const version = mcData.version
|
||||
|
||||
function convertBufferToObject (buffer) {
|
||||
return deserializer.parsePacketBuffer(buffer)
|
||||
}
|
||||
|
||||
function convertObjectToBuffer (object) {
|
||||
return serializer.createPacketBuffer(object)
|
||||
}
|
||||
|
||||
function testBuffer (buffer, [packetName, packetIx]) {
|
||||
const parsed = convertBufferToObject(buffer).data
|
||||
const parsedBuffer = convertObjectToBuffer(parsed)
|
||||
const areEq = buffer.equals(parsedBuffer)
|
||||
assert.strictEqual(areEq, true, `Error when testing ${+packetIx + 1} ${packetName} packet`)
|
||||
}
|
||||
describe(`Test cycle packet for version ${supportedVersion}v`, () => {
|
||||
before(() => {
|
||||
serializer = makeClientSerializer(version.minecraftVersion)
|
||||
deserializer = makeClientDeserializer(version.minecraftVersion)
|
||||
})
|
||||
data = mcPackets.pc[version.minecraftVersion]
|
||||
it('Has packet data', () => {
|
||||
if (data === undefined) {
|
||||
// many version do not have data, so print a log for now
|
||||
// assert when most versions have packet data
|
||||
console.log(`Version ${version.minecraftVersion} has no packet dump.`)
|
||||
}
|
||||
})
|
||||
// server -> client
|
||||
if (data !== undefined) {
|
||||
Object.entries(data['from-server']).forEach(([packetName, packetData]) => {
|
||||
it(`${packetName} packet`, () => {
|
||||
for (const i in packetData) {
|
||||
testBuffer(packetData[i].raw, [packetName, i])
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/* eslint-env mocha */
|
||||
// Tests packet serialization/deserialization from with raw binary from minecraft-packets
|
||||
const { createSerializer, createDeserializer, states } = require('minecraft-protocol')
|
||||
const mcPackets = require('minecraft-packets')
|
||||
const assert = require('assert')
|
||||
|
||||
const makeClientSerializer = version => createSerializer({ state: states.PLAY, version, isServer: true })
|
||||
const makeClientDeserializer = version => createDeserializer({ state: states.PLAY, version })
|
||||
|
||||
Object.entries(mcPackets.pc).forEach(([ver, data]) => {
|
||||
let serializer, deserializer
|
||||
|
||||
function convertBufferToObject (buffer) {
|
||||
return deserializer.parsePacketBuffer(buffer)
|
||||
}
|
||||
|
||||
function convertObjectToBuffer (object) {
|
||||
return serializer.createPacketBuffer(object)
|
||||
}
|
||||
|
||||
function testBuffer (buffer, [packetName, packetIx]) {
|
||||
const parsed = convertBufferToObject(buffer).data
|
||||
const parsedBuffer = convertObjectToBuffer(parsed)
|
||||
const areEq = buffer.equals(parsedBuffer)
|
||||
assert.strictEqual(areEq, true, `Error when testing ${+packetIx + 1} ${packetName} packet`)
|
||||
}
|
||||
describe(`Test version ${ver}`, () => {
|
||||
serializer = makeClientSerializer(ver)
|
||||
deserializer = makeClientDeserializer(ver)
|
||||
// server -> client
|
||||
Object.entries(data['from-server']).forEach(([packetName, packetData]) => {
|
||||
it(`${packetName} packet`, () => {
|
||||
for (const i in packetData) {
|
||||
testBuffer(packetData[i].raw, [packetName, i])
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
|
@ -244,7 +244,7 @@ for (const supportedVersion of mc.supportedVersions) {
|
|||
const version = mcData.version
|
||||
const packets = mcData.protocol
|
||||
|
||||
describe('packets ' + version.minecraftVersion, function () {
|
||||
describe('packets ' + supportedVersion + 'v', function () {
|
||||
let client, server, serverClient
|
||||
before(async function () {
|
||||
PORT = await getPort()
|
||||
|
|
|
@ -94,7 +94,7 @@ for (const supportedVersion of mc.supportedVersions) {
|
|||
}
|
||||
}
|
||||
|
||||
describe('mc-server ' + version.minecraftVersion, function () {
|
||||
describe('mc-server ' + supportedVersion + 'v', function () {
|
||||
this.timeout(5000)
|
||||
this.beforeAll(async function () {
|
||||
PORT = await getPort()
|
||||
|
|
Loading…
Reference in a new issue