1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-30 12:17:42 +03:00
leon/test/json/is-valid.spec.js

34 lines
942 B
JavaScript
Raw Normal View History

import fs from 'node:fs'
import path from 'node:path'
2019-02-10 15:26:50 +03:00
describe('are JSON files valid', () => {
2022-09-03 14:12:41 +03:00
const rootFolders = ['core', 'packages', 'core/config', 'server/src/data']
2019-02-10 15:26:50 +03:00
const list = (dir) => {
const entities = fs.readdirSync(dir)
// Browse dir entities
for (let i = 0; i < entities.length; i += 1) {
// Recursive if the entity is a directory
const way = path.join(dir, entities[i])
if (fs.statSync(way).isDirectory()) {
list(way)
} else if (entities[i].indexOf('.json') !== -1) {
const jsonFile = path.join(global.paths.root, dir, entities[i])
test(`${jsonFile} has valid JSON syntax`, () => {
2022-09-03 14:12:41 +03:00
try {
2019-02-10 15:26:50 +03:00
JSON.parse(fs.readFileSync(jsonFile, 'utf8'))
expect(true).toBe(true)
} catch (e) {
throw e
}
})
}
}
}
for (let i = 0; i < rootFolders.length; i += 1) {
list(rootFolders[i])
}
})