minecraft data raw code
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
require('./version_iterator')(function (p, versionString) {
|
||||
describe('audit blockitems ' + versionString, function () {
|
||||
it('audit blockitems', function () {
|
||||
const itemsFile = path.join(p, 'items.json')
|
||||
if (!fs.existsSync(itemsFile)) return
|
||||
const items = require(itemsFile)
|
||||
|
||||
const blocksFile = path.join(p, 'blocks.json')
|
||||
if (!fs.existsSync(blocksFile)) return
|
||||
const blocks = require(blocksFile)
|
||||
|
||||
if (items[0].id === 0) return
|
||||
|
||||
let rewriteItems = false
|
||||
for (const block of blocks) {
|
||||
let blockitem = null
|
||||
for (const item of items) {
|
||||
if (item.name === block.name) {
|
||||
blockitem = item
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!blockitem) {
|
||||
// console.log('Missing item for block ' + block.name)
|
||||
rewriteItems = false
|
||||
items.push({
|
||||
id: block.id,
|
||||
displayName: block.displayName,
|
||||
name: block.name,
|
||||
stackSize: 64
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
items.sort((a, b) => { return a.id - b.id })
|
||||
|
||||
// Automatically fix item data, if necessary
|
||||
if (rewriteItems) {
|
||||
fs.writeFileSync(itemsFile, JSON.stringify(items, null, 2))
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,58 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
// checks for duplicates names and jumps in ids
|
||||
|
||||
require('./version_iterator')(function (p, versionString) {
|
||||
describe('audit blocks ' + versionString, function () {
|
||||
it('audit blocks', function () {
|
||||
let blocks
|
||||
const pFile = path.join(p, 'blocks.json')
|
||||
if (fs.existsSync(pFile)) {
|
||||
blocks = require(pFile)
|
||||
} else {
|
||||
// console.log('No blocks for version ' + versionString)
|
||||
}
|
||||
if (blocks) {
|
||||
const all = []
|
||||
blocks.forEach(block => {
|
||||
all[block.id] = block
|
||||
})
|
||||
|
||||
const displayNames = {}
|
||||
const names = {}
|
||||
for (let i = 0; i < all.length; ++i) {
|
||||
const block = all[i]
|
||||
if (block) {
|
||||
if (block.displayName == null) {
|
||||
// console.log('Missing displayName:', i)
|
||||
} else {
|
||||
const otherBlock = displayNames[block.displayName]
|
||||
if (otherBlock) {
|
||||
// console.log('Duplicate displayName:', otherBlock.id, 'and', block.id,
|
||||
// 'both share', block.displayName)
|
||||
} else {
|
||||
displayNames[block.displayName] = block
|
||||
}
|
||||
}
|
||||
if (block.name == null) {
|
||||
console.log('Missing name:', i)
|
||||
} else {
|
||||
const otherBlock = names[block.name]
|
||||
if (otherBlock) {
|
||||
// console.log('Duplicate name:', otherBlock.id, 'and', block.id,
|
||||
// 'both share', block.name)
|
||||
} else {
|
||||
names[block.name] = block
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// console.log('Missing:', i)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
const fs = require('fs')
|
||||
const { join } = require('path')
|
||||
const assert = require('assert')
|
||||
|
||||
describe('audit dataPaths', function () {
|
||||
const dataPaths = require('../../../data/dataPaths.json')
|
||||
it('should have a dataPath for each file', function () {
|
||||
require('./version_iterator')(function (p, versionString) {
|
||||
const [type, version] = versionString.split(' ')
|
||||
const dp = dataPaths[type][version]
|
||||
if (fs.existsSync(p)) {
|
||||
const files = fs.readdirSync(p).map(f => f.split('.')[0])
|
||||
for (const file of files) {
|
||||
assert(dp[file], `missing dataPath for ${type} ${version} ${file}`)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('dataPath should point to valid files', function () {
|
||||
for (const version in dataPaths) {
|
||||
for (const type in dataPaths[version]) {
|
||||
const dp = dataPaths[version][type]
|
||||
for (const file in dp) {
|
||||
const path = dp[file]
|
||||
const p = join(__dirname, '../../../data/' + path + '/' + file)
|
||||
const exists = fs.existsSync(p + '.json') || fs.existsSync(p + '.yml')
|
||||
assert(exists, `missing file for ${type} ${version} ${file}, path: ${p}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,54 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
// checks for duplicates names and jumps in ids
|
||||
|
||||
require('./version_iterator')(function (p, versionString) {
|
||||
describe('audit items ' + versionString, function () {
|
||||
it('audit items', function () {
|
||||
let items
|
||||
const pFile = path.join(p, 'items.json')
|
||||
if (fs.existsSync(pFile)) {
|
||||
items = require(pFile)
|
||||
} else {
|
||||
// console.log('No items for version ' + versionString)
|
||||
}
|
||||
if (items) {
|
||||
const displayNames = {}
|
||||
const names = {}
|
||||
let lastItemId = 0
|
||||
items.forEach(item => {
|
||||
if (item.displayName == null) {
|
||||
console.log('Missing displayName:', item.id)
|
||||
} else {
|
||||
const otherBlock = displayNames[item.displayName]
|
||||
if (otherBlock) {
|
||||
// console.log('Duplicate displayName:', otherBlock.id, 'and', item.id,
|
||||
// 'both share', item.displayName)
|
||||
} else {
|
||||
displayNames[item.displayName] = item
|
||||
}
|
||||
}
|
||||
if (item.name == null) {
|
||||
console.log('Missing name:', item.id)
|
||||
} else {
|
||||
const otherBlock = names[item.name]
|
||||
if (otherBlock) {
|
||||
// console.log('Duplicate name:', otherBlock.id, 'and', item.id,
|
||||
// 'both share', item.name)
|
||||
} else {
|
||||
names[item.name] = item
|
||||
}
|
||||
}
|
||||
const delta = item.id - lastItemId
|
||||
if (delta !== 1) {
|
||||
// console.log('jump from', lastItemId, 'to', item.id)
|
||||
}
|
||||
lastItemId = item.id
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,136 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const assert = require('assert')
|
||||
|
||||
// counts the number of recipes with a shape, without one and with an outShape
|
||||
|
||||
function getIfExist (path) {
|
||||
if (fs.existsSync(path)) {
|
||||
return require(path)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
require('./version_iterator')(function (p, versionString) {
|
||||
describe('audit recipes ' + versionString, function () {
|
||||
it('audit recipes', function () {
|
||||
let recipes
|
||||
const pFile = path.join(p, 'recipes.json')
|
||||
if (fs.existsSync(pFile)) {
|
||||
recipes = require(pFile)
|
||||
} else {
|
||||
console.log('No recipes for version ' + versionString)
|
||||
}
|
||||
if (recipes) {
|
||||
let shapeCount = 0
|
||||
let shapelessCount = 0
|
||||
let outShapeCount = 0
|
||||
Object.keys(recipes).forEach(key => {
|
||||
const list = recipes[key]
|
||||
for (let i = 0; i < list.length; ++i) {
|
||||
const recipe = list[i]
|
||||
if (recipe.inShape != null) {
|
||||
shapeCount += 1
|
||||
} else if (recipe.ingredients != null) {
|
||||
shapelessCount += 1
|
||||
} else {
|
||||
console.log('inShape or ingredients required:', key)
|
||||
}
|
||||
if (recipe.outShape) outShapeCount += 1
|
||||
}
|
||||
})
|
||||
|
||||
console.log('normal recipes:', shapeCount)
|
||||
console.log('shapeless recipes:', shapelessCount)
|
||||
console.log('how many have an outShape:', outShapeCount)
|
||||
}
|
||||
})
|
||||
it('pickaxe not upside-down', () => {
|
||||
const recipes = getIfExist(path.join(p, 'recipes.json'))
|
||||
const items = getIfExist(path.join(p, 'items.json'))
|
||||
if (recipes && items) {
|
||||
const pickaxe = items.find(x => x.name === 'diamond_pickaxe')
|
||||
const stick = items.find(x => x.name === 'stick')
|
||||
const diamond = items.find(x => x.name === 'diamond')
|
||||
|
||||
const recipe = recipes[pickaxe.id]
|
||||
|
||||
// Uncomment to fix upside-down recipes
|
||||
/* if (recipe[0].inShape[0][0] !== diamond.id) {
|
||||
for (const item of Object.values(recipes)) {
|
||||
for (const rep of item) {
|
||||
if (rep.inShape) rep.inShape.reverse()
|
||||
}
|
||||
}
|
||||
fs.writeFileSync(path.join(p, 'recipes.json'), JSON.stringify(recipes, null, 2))
|
||||
} */
|
||||
|
||||
// Those 2 versions doesnt contain diamond pickaxe recipe, to be fixed...
|
||||
if (versionString === 'pc 1.9' || versionString === 'pc 1.10' || !recipe[0]) return
|
||||
|
||||
assert.deepStrictEqual(recipe[0].inShape, [
|
||||
[
|
||||
diamond.id,
|
||||
diamond.id,
|
||||
diamond.id
|
||||
],
|
||||
[
|
||||
null,
|
||||
stick.id,
|
||||
null
|
||||
],
|
||||
[
|
||||
null,
|
||||
stick.id,
|
||||
null
|
||||
]
|
||||
])
|
||||
}
|
||||
})
|
||||
it('iron door not rotated', () => {
|
||||
const recipes = getIfExist(path.join(p, 'recipes.json'))
|
||||
const items = getIfExist(path.join(p, 'items.json'))
|
||||
if (recipes && items) {
|
||||
const ironDoor = items.find(x => x.name === 'iron_door')
|
||||
const iron = items.find(x => x.name === 'iron_ingot')
|
||||
|
||||
const recipe = recipes[ironDoor.id]
|
||||
|
||||
if (!recipe[0]) return
|
||||
|
||||
assert.deepStrictEqual(recipe[0].inShape, [
|
||||
[
|
||||
iron.id,
|
||||
iron.id
|
||||
],
|
||||
[
|
||||
iron.id,
|
||||
iron.id
|
||||
],
|
||||
[
|
||||
iron.id,
|
||||
iron.id
|
||||
]
|
||||
])
|
||||
}
|
||||
})
|
||||
it('crafting benches has multiple recipes', () => {
|
||||
const recipes = getIfExist(path.join(p, 'recipes.json'))
|
||||
const items = getIfExist(path.join(p, 'items.json'))
|
||||
if (recipes && items) {
|
||||
const craftingTable = items.find(x => x.name === 'crafting_table')
|
||||
const oakPlanks = items.find(x => x.name === 'oak_planks')
|
||||
if (!oakPlanks) return // Bail if version doesn't have seperately defined planks, this prevents the test failing on versions that use metadata
|
||||
const recipe = recipes[craftingTable.id]
|
||||
if (!recipe[0]) return
|
||||
// remove the if after fixing https://github.com/PrismarineJS/minecraft-data/issues/917
|
||||
if (versionString !== 'pc 1.20.5' && versionString !== 'pc 1.20.6') {
|
||||
assert.notEqual(recipe.length, 1) // Check that crafting table has multiple recipes.
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,94 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
// checks if bounding boxes data in blocks.json is consistent with blockCollisionShapes.json
|
||||
|
||||
require('./version_iterator')(function (p, versionString) {
|
||||
describe('audit block shapes ' + versionString, function () {
|
||||
const blockFile = path.join(p, 'blocks.json')
|
||||
if (!fs.existsSync(blockFile)) {
|
||||
return // Only audit shape where block exists
|
||||
}
|
||||
it('audit bb', function () {
|
||||
const shapeFile = path.join(p, 'blockCollisionShapes.json')
|
||||
if (!fs.existsSync(shapeFile)) {
|
||||
// console.log('No collision shapes for version ' + versionString)
|
||||
return
|
||||
}
|
||||
|
||||
const blocks = require(blockFile)
|
||||
const shapes = require(shapeFile)
|
||||
|
||||
const blockByName = {}
|
||||
|
||||
// Check bijection between blocks and shapes
|
||||
|
||||
// Check that every block have a shape
|
||||
blocks.forEach(block => {
|
||||
blockByName[block.name] = block
|
||||
const shape = shapes.blocks[block.name]
|
||||
if (shape === undefined) {
|
||||
// console.log('missing shape for block: ' + block.name)
|
||||
}
|
||||
})
|
||||
|
||||
// Check that every shape have a block
|
||||
for (const key of Object.keys(shapes.blocks)) {
|
||||
const block = blockByName[key]
|
||||
if (block === undefined) {
|
||||
// console.log('missing block for shape: ' + key)
|
||||
}
|
||||
}
|
||||
|
||||
// Check every shape is present
|
||||
const usedShapes = {}
|
||||
for (let value of Object.values(shapes.blocks)) {
|
||||
if (!(value instanceof Array)) value = [value]
|
||||
for (const shape of value) {
|
||||
if (shapes.shapes[shape] === undefined) {
|
||||
// console.log('missing shape: ' + shape)
|
||||
}
|
||||
usedShapes[shape] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Check every shape is used
|
||||
for (const key of Object.keys(shapes.shapes)) {
|
||||
if (!usedShapes[key]) {
|
||||
// console.log('unused shape: ' + key)
|
||||
}
|
||||
}
|
||||
|
||||
// Check block bounding box is consistent with shape
|
||||
let rewriteBlocks = false
|
||||
blocks.forEach(block => {
|
||||
blockByName[block.name] = block
|
||||
const shape = shapes.blocks[block.name]
|
||||
if (shape !== undefined) {
|
||||
if (block.boundingBox === 'empty') {
|
||||
if (shape !== 0) {
|
||||
// console.log('Inconsistent BB for block ' + block.name + ' (expected empty got ' + shape + ')')
|
||||
block.boundingBox = 'block'
|
||||
rewriteBlocks = false
|
||||
}
|
||||
} else if (block.boundingBox === 'block') {
|
||||
if (shape === 0) {
|
||||
// console.log('Inconsistent BB for block ' + block.name + ' (expected block got ' + shape + ')')
|
||||
block.boundingBox = 'empty'
|
||||
rewriteBlocks = false
|
||||
}
|
||||
} else {
|
||||
// console.log('Unknown BB: ' + block.boundingBox + ' for block ' + block.name)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Automatically fix block data, if necessary
|
||||
if (rewriteBlocks) {
|
||||
fs.writeFileSync(blockFile, JSON.stringify(blocks, null, 2))
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,95 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
const assert = require('assert')
|
||||
|
||||
/**
|
||||
* Gets the chronological index of a version from the versions.json file
|
||||
* Returns -1 if version is not found, or null for non-version strings like "latest"
|
||||
*/
|
||||
function getVersionIndex (platform, version) {
|
||||
// Skip non-version entries like "latest"
|
||||
if (version === 'latest') return null
|
||||
|
||||
try {
|
||||
const versions = require(`../../../data/${platform}/common/versions.json`)
|
||||
return versions.indexOf(version)
|
||||
} catch (error) {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
describe('audit version regression in dataPaths', function () {
|
||||
const dataPaths = require('../../../data/dataPaths.json')
|
||||
|
||||
const platforms = ['pc', 'bedrock']
|
||||
|
||||
platforms.forEach(function (platform) {
|
||||
if (!dataPaths[platform]) return
|
||||
|
||||
describe(`${platform} version regression`, function () {
|
||||
it('should not have newer versions pointing to older data than previously seen', function () {
|
||||
const platformData = dataPaths[platform]
|
||||
|
||||
// Load the chronological version order from versions.json
|
||||
const versions = require(`../../../data/${platform}/common/versions.json`)
|
||||
|
||||
// Track the highest version index seen for each data type
|
||||
const highestVersionIndexForDataType = {}
|
||||
|
||||
// Iterate through versions in chronological order, but only process ones in dataPaths
|
||||
for (const version of versions) {
|
||||
if (!platformData[version]) continue
|
||||
|
||||
const versionData = platformData[version]
|
||||
|
||||
for (const [dataType, dataPath] of Object.entries(versionData)) {
|
||||
// Skip non-version data paths (like "latest" or cross-platform refs)
|
||||
const pathParts = dataPath.split('/')
|
||||
if (pathParts.length !== 2) continue
|
||||
|
||||
const [dataPathPlatform, dataPathVersion] = pathParts
|
||||
|
||||
// Skip cross-platform references (e.g., bedrock data pointing to pc data)
|
||||
if (dataPathPlatform !== platform) continue
|
||||
|
||||
// Get the chronological index of the data path version
|
||||
const dataPathIndex = getVersionIndex(platform, dataPathVersion)
|
||||
|
||||
// Skip if version not found in versions.json (like "latest")
|
||||
if (dataPathIndex === null || dataPathIndex === -1) continue
|
||||
|
||||
// Initialize tracking for this data type if not seen before
|
||||
if (!highestVersionIndexForDataType[dataType]) {
|
||||
highestVersionIndexForDataType[dataType] = {
|
||||
version: dataPath,
|
||||
index: dataPathIndex
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if current data path is older than the highest we've seen
|
||||
const previousHighest = highestVersionIndexForDataType[dataType]
|
||||
if (dataPathIndex < previousHighest.index) {
|
||||
assert.fail(
|
||||
`Version regression detected in ${platform}:\n` +
|
||||
` Version: ${version}\n` +
|
||||
` Data type: ${dataType}\n` +
|
||||
` Current path: ${dataPath} (index: ${dataPathIndex})\n` +
|
||||
` Expected at least: ${previousHighest.version} (index: ${previousHighest.index})\n` +
|
||||
' A newer version should not point to older data than previously seen.'
|
||||
)
|
||||
}
|
||||
|
||||
// Update the highest version if current is newer
|
||||
if (dataPathIndex > previousHighest.index) {
|
||||
highestVersionIndexForDataType[dataType] = {
|
||||
version: dataPath,
|
||||
index: dataPathIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,48 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
const assert = require('assert')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
describe('dataPaths.json consistency with versions.json', function () {
|
||||
const dataPathsFile = path.join(__dirname, '../../../data/dataPaths.json')
|
||||
const dataPaths = require(dataPathsFile)
|
||||
|
||||
const editions = ['pc', 'bedrock']
|
||||
|
||||
editions.forEach(function (edition) {
|
||||
describe(`${edition} versions consistency`, function () {
|
||||
const versionsFile = path.join(
|
||||
__dirname,
|
||||
`../../../data/${edition}/common/versions.json`
|
||||
)
|
||||
assert.ok(
|
||||
fs.existsSync(versionsFile),
|
||||
`Missing versions.json for ${edition}`
|
||||
)
|
||||
|
||||
const versionsList = require(versionsFile)
|
||||
const manifestVersions = Object.keys(dataPaths[edition] || {})
|
||||
|
||||
it('all manifest versions are present in versions.json', function () {
|
||||
const missing = manifestVersions.filter(
|
||||
(v) => !versionsList.includes(v)
|
||||
)
|
||||
assert.deepStrictEqual(
|
||||
missing,
|
||||
[],
|
||||
`The following ${edition} versions are in dataPaths.json but not in versions.json: ${missing.join(', ')}`
|
||||
)
|
||||
})
|
||||
|
||||
it('no extra versions exist in versions.json compared to manifest', function () {
|
||||
const extra = versionsList.filter((v) => !manifestVersions.includes(v))
|
||||
assert.deepStrictEqual(
|
||||
extra,
|
||||
[],
|
||||
`The following ${edition} versions are in versions.json but not in dataPaths.json: ${extra.join(', ')}`
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,8 @@
|
||||
/* eslint-env mocha */
|
||||
const protocolTools = require('../compileProtocol')
|
||||
|
||||
describe('protocol yaml', () => {
|
||||
it('should be valid and in sync with json', () => {
|
||||
protocolTools.all(protocolTools.validate)
|
||||
}).timeout(9000)
|
||||
})
|
||||
@@ -0,0 +1,83 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
const assert = require('assert')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const Ajv = require('ajv')
|
||||
const v = new Ajv({ verbose: true })
|
||||
|
||||
const Validator = require('protodef-validator')
|
||||
|
||||
Error.stackTraceLimit = 0
|
||||
|
||||
const data = ['attributes', 'biomes', 'commands', 'instruments', 'items', 'materials', 'blocks', 'blockCollisionShapes', 'recipes', 'windows', 'entities', 'protocol', 'version', 'effects', 'enchantments', 'language', 'foods', 'particles', 'blockLoot', 'entityLoot', 'mapIcons', 'tints', 'blockMappings', 'sounds']
|
||||
|
||||
require('./version_iterator')(function (p, versionString) {
|
||||
describe('minecraft-data schemas ' + versionString, function () {
|
||||
this.timeout(60 * 1000)
|
||||
data.forEach(function (dataName) {
|
||||
let instance
|
||||
const pFile = path.join(p, dataName + '.json')
|
||||
if (fs.existsSync(pFile)) {
|
||||
instance = require(pFile)
|
||||
}
|
||||
if (instance) {
|
||||
it(dataName + '.json is valid', function () {
|
||||
// Skip tints schema validation for PC 1.21.4, as it doesn't meet the
|
||||
// maxItems: 1 check for the constant tints.
|
||||
if (dataName === 'tints' && versionString === 'pc 1.21.4') {
|
||||
this.skip()
|
||||
}
|
||||
|
||||
if (dataName === 'protocol') {
|
||||
const validator = new Validator()
|
||||
|
||||
instance.types.LatinString = 'native' // TODO: Update protodef validator
|
||||
validator.addType('entityMetadataItem', require('../../../schemas/protocol_types/entity_metadata_item.json'))
|
||||
validator.addType('entityMetadataLoop', require('../../../schemas/protocol_types/entity_metadata_loop.json'))
|
||||
validator.validateProtocol(instance)
|
||||
} else {
|
||||
const schema = require('../../../schemas/' + dataName + '_schema.json')
|
||||
const valid = v.validate(schema, instance)
|
||||
assert.ok(valid, JSON.stringify(v.errors, null, 2))
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
const commonData = ['protocolVersions', 'features']
|
||||
const minecraftTypes = ['pc', 'bedrock']
|
||||
|
||||
minecraftTypes.forEach(function (type) {
|
||||
describe('minecraft-data schemas of common data of ' + type, function () {
|
||||
this.timeout(60 * 1000)
|
||||
commonData.forEach(function (dataName) {
|
||||
it(dataName + '.json is valid', function () {
|
||||
const instance = require('../../../data/' + type + '/common/' + dataName + '.json')
|
||||
const schema = require('../../../schemas/' + dataName + '_schema.json')
|
||||
const valid = v.validate(schema, instance)
|
||||
assert.ok(valid, JSON.stringify(v.errors, null, 2))
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('features.json quality is good', function () {
|
||||
it('there is no duplicate feature in features.json', () => {
|
||||
const features = require('../../../data/' + type + '/common/features.json')
|
||||
const countPerFeature = {}
|
||||
for (const feature of features) {
|
||||
countPerFeature[feature.name] = countPerFeature[feature.name] ? countPerFeature[feature.name] + 1 : 1
|
||||
}
|
||||
let duplicateCount = 0
|
||||
for (const [name, count] of Object.entries(countPerFeature)) {
|
||||
if (count > 1) {
|
||||
console.log(`feature ${name} is duplicated ${count} times, please remove ${count - 1}`)
|
||||
duplicateCount += 1
|
||||
}
|
||||
}
|
||||
assert.equal(duplicateCount, 0, `${duplicateCount} duplicates found. Please remove them.`)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,14 @@
|
||||
module.exports = forEach
|
||||
|
||||
const path = require('path')
|
||||
|
||||
const minecraftTypes = ['pc', 'bedrock']
|
||||
|
||||
function forEach (f) {
|
||||
minecraftTypes.forEach(function (type) {
|
||||
const versions = require('../../../data/' + type + '/common/versions')
|
||||
versions.forEach(function (version) {
|
||||
f(path.join(__dirname, '../../../data', type, version), type + ' ' + version)
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user