expexp
Version:
The express model io and express model and data representation.
57 lines (52 loc) • 1.39 kB
JavaScript
import fs from 'fs'
const TEST_BASE_PATH = './test/'
export function loadCases(dirName) {
const fullPath = TEST_BASE_PATH+dirName
const files = fs.readdirSync(fullPath)
let resHash = {}
files.forEach(fileName => {
const dotIdx = fileName.lastIndexOf('.')
const prefix = fileName.substr(0, dotIdx)
const ext = fileName.substr(dotIdx+1)
if (!(prefix in resHash)) {
resHash[prefix] = {'name': prefix}
}
resHash[prefix][ext] = fullPath + '/' + fileName
})
const res = []
for (let prefix in resHash) {
const fi = resHash[prefix]
if ('xpl' in fi && 'json' in fi) {
res.push(fi)
}
}
return res
}
export function genCaseInfo(dirName, caseName, niceName=null) {
const fullPath = TEST_BASE_PATH+dirName+'/'
const ci = {
name: caseName,
xpl: fullPath+caseName+'.xpl',
json: fullPath+caseName+'.json'
}
return ci
}
export function resolveElement(arr) {
const res = []
for (let tp of arr) {
if (typeof tp == 'string') {
// The tp is 'dirName/caseName' string.
const dcArr = tp.split('/')
const dirName = 'mniUnits'
const caseName = dcArr[1]
const fullPath = TEST_BASE_PATH+dirName+'/'
const jsonFilePath = fullPath+caseName+'.json'
const caseJsonStr = fs.readFileSync(jsonFilePath, 'utf8')
const caseJson = JSON.parse(caseJsonStr)
res.push(caseJson)
} else { // consider it to be json
res.push(tp)
}
}
return res
}