Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ jobs:
run: npm install

- name: Run tests
run: npm run mochaTest -- -g ${{ matrix.mcVersion }}v
run: npm run mochaTest
env:
MC_VERSION: ${{ matrix.mcVersion }}
3 changes: 2 additions & 1 deletion test/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
const ITERATIONS = 10000

const mc = require('../')
const testedVersions = require('./common/testedVersions')
const states = mc.states

for (const supportedVersion of mc.supportedVersions) {
for (const supportedVersion of testedVersions) {
const mcData = require('minecraft-data')(supportedVersion)
const version = mcData.version
const positionFlags = mcData.isNewerOrEqualTo('1.21.3') ? { flags: { onGround: true, hasHorizontalCollision: false } } : { onGround: true }
Expand Down
3 changes: 2 additions & 1 deletion test/clientTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ const util = require('util')
const applyClientHelpers = require('./common/clientHelpers')
const download = util.promisify(require('minecraft-wrap').download)
const { getPort } = require('./common/util')
const testedVersions = require('./common/testedVersions')

const SURVIVE_TIME = 10000
const MC_SERVER_PATH = path.join(__dirname, 'server')

const Wrap = require('minecraft-wrap').Wrap

for (const supportedVersion of mc.supportedVersions) {
for (const supportedVersion of testedVersions) {
let PORT = null
const mcData = require('minecraft-data')(supportedVersion)
const version = mcData.version
Expand Down
10 changes: 10 additions & 0 deletions test/common/testedVersions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const mc = require('minecraft-protocol')

// MC_VERSION names the one supported version to test; unset tests all of them.
const only = process.env.MC_VERSION

if (only && !mc.supportedVersions.includes(only)) {
throw new Error(`MC_VERSION is ${only}, which is not one of ${mc.supportedVersions.join(', ')}`)
}

module.exports = only ? [only] : mc.supportedVersions
3 changes: 2 additions & 1 deletion test/cyclePacketTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env mocha */
// Tests packet serialization/deserialization from with raw binary from minecraft-packets
const { createSerializer, createDeserializer, states, supportedVersions } = require('minecraft-protocol')
const { createSerializer, createDeserializer, states } = require('minecraft-protocol')
const supportedVersions = require('./common/testedVersions')
const mcPackets = require('minecraft-packets')
const assert = require('assert')

Expand Down
4 changes: 2 additions & 2 deletions test/docTest.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-env mocha */

const mc = require('../')
const fs = require('fs')
const assert = require('assert')
const path = require('path')
const testedVersions = require('./common/testedVersions')

const readmeContent = fs.readFileSync(path.join(__dirname, '/../docs/README.md'), { encoding: 'utf8', flag: 'r' })

for (const supportedVersion of mc.supportedVersions) {
for (const supportedVersion of testedVersions) {
describe('doc ' + supportedVersion + 'v', function () {
it('mentions the supported version in the readme', () => {
assert.ok(readmeContent.includes(supportedVersion), `${supportedVersion} should be mentionned in the README.md but it is not`)
Expand Down
3 changes: 2 additions & 1 deletion test/packetTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const getFieldInfo = require('protodef').utils.getFieldInfo
const getField = require('protodef').utils.getField

const { getPort } = require('./common/util')
const testedVersions = require('./common/testedVersions')

function evalCount (count, fields) {
if (fields[count.field] in count.map) { return count.map[fields[count.field]] }
Expand Down Expand Up @@ -467,7 +468,7 @@ function getValue (_type, packet) {
}
}

for (const supportedVersion of mc.supportedVersions) {
for (const supportedVersion of testedVersions) {
let PORT

const mcData = require('minecraft-data')(supportedVersion)
Expand Down
3 changes: 2 additions & 1 deletion test/serverTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const nbt = require('prismarine-nbt')
const applyClientHelpers = require('./common/clientHelpers')

const { getPort } = require('./common/util')
const testedVersions = require('./common/testedVersions')

const w = nbt.comp({
piglin_safe: nbt.byte(0),
Expand All @@ -25,7 +26,7 @@ const w = nbt.comp({
has_ceiling: nbt.byte(0)
})

for (const supportedVersion of mc.supportedVersions) {
for (const supportedVersion of testedVersions) {
let PORT
const mcData = require('minecraft-data')(supportedVersion)
const version = mcData.version
Expand Down
Loading