Skip to content

Commit

Permalink
Improve CI setup for per version tests (#1267)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rom1504 authored Dec 27, 2023
1 parent 9e99109 commit 1740124
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 63 deletions.
46 changes: 29 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,39 @@ on:
- master

jobs:
test:
Lint:
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']
fail-fast: false

steps:
- uses: actions/checkout@v2
- name: Use Node.js 18.x
uses: actions/setup-node@v1
uses: actions/setup-node@v1.4.4
with:
node-version: 18.x
- name: Setup Java JDK
uses: actions/setup-java@v1.4.3
- 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:
java-version: '17'
distribution: 'adopt'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test -- -g ${{ matrix.mcVersion }}
packet-cycle-test:
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: ${{fromJson(needs.PrepareSupportedVersions.outputs.matrix)}}
fail-fast: false

steps:
- uses: actions/checkout@v2
Expand All @@ -43,6 +52,9 @@ jobs:
- name: Setup Java JDK
uses: actions/setup-java@v1.4.3
with:
java-version: '16'
java-version: '17'
distribution: 'adopt'
- run: npm install && npm run test-non-par
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run mochaTest -- -g ${{ matrix.mcVersion }}v
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules
test/npm-debug.log
test/server*
test/server_*
package-lock.json
versions/
src/client/*.json
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/clientTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
53 changes: 53 additions & 0 deletions test/cyclePacketTest.js
Original file line number Diff line number Diff line change
@@ -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])
}
})
})
}
})
}
39 changes: 0 additions & 39 deletions test/non-par-test.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/packetTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/serverTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1740124

Please sign in to comment.