mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
feat: parse all quest
This commit is contained in:
1 parent
ed4d04b658
commit
61d1871e95
9 files changed
+77
-18
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import { describe, it, expect, beforeAll } from '@jest/globals'
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
import yaml from 'yaml'
|
||||
import { questSchema } from '../src/quest/quest.js'
|
||||
|
||||
describe('Parse all quests', () => {
|
||||
let quests: any[] = []
|
||||
|
||||
test('should parse all quests', async () => {
|
||||
const questDirectory = path.join(process.cwd(), 'quests')
|
||||
|
||||
const loadQuests = async () => {
|
||||
const questNames = await fs.readdir(questDirectory, {
|
||||
withFileTypes: true,
|
||||
})
|
||||
|
||||
return Promise.all(
|
||||
questNames
|
||||
.filter(
|
||||
(dirent) => dirent.isDirectory() && !dirent.name.startsWith('.')
|
||||
)
|
||||
.map(async (dirent) => {
|
||||
const id = dirent.name
|
||||
const questPath = path.join(questDirectory, id)
|
||||
const files = await fs.readdir(questPath)
|
||||
if (!files.includes('game.yml')) {
|
||||
throw new Error(`Missing game.yml in quest ${id}`)
|
||||
}
|
||||
|
||||
const body = await fs.readFile(
|
||||
path.join(questPath, 'game.yml'),
|
||||
'utf-8'
|
||||
)
|
||||
const questData = yaml.parse(body, { merge: true })
|
||||
const image = files.includes('Dockerfile') ? id : 'base'
|
||||
return {
|
||||
id,
|
||||
image,
|
||||
...questData,
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
quests = await loadQuests()
|
||||
quests.forEach((quest) => {
|
||||
console.log(`Quest ID: ${quest.id}`)
|
||||
expect(questSchema.safeParse(quest).error).toBeUndefined()
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user