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:
Romain Beaumont 2023-12-28 00:12:23 +01:00 committed by GitHub
parent 9e99109476
commit 1740124c47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 90 additions and 64 deletions

View file

@ -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
View file

@ -1,6 +1,6 @@
node_modules
test/npm-debug.log
test/server*
test/server_*
package-lock.json
versions/
src/client/*.json

View file

@ -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",

View file

@ -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) {

View file

@ -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
View 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])
}
})
})
}
})
}

View file

@ -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])
}
})
})
})
})

View file

@ -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()

View file

@ -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()