Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CI setup for per version tests #1267

Merged
merged 14 commits into from
Dec 27, 2023
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
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 () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint isn't running on test/serverTest since the .gitignore has

test/server* instead of test/server_* in it https://github.com/PrismarineJS/node-minecraft-protocol/blob/improve_ci_setup/.gitignore#L3

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch thanks

this.timeout(5000)
this.beforeAll(async function () {
PORT = await getPort()
Expand Down
Loading