1
0
ergogen/test/unit/interface.js

101 lines
3.8 KiB
JavaScript
Raw Permalink Normal View History

2021-07-16 11:18:09 -07:00
const fs = require('fs')
const path = require('path')
const yaml = require('js-yaml')
2021-05-16 13:30:26 -07:00
const ergogen = require('../../src/ergogen')
2021-12-15 11:33:50 -08:00
const version = require('../../package.json').version
2021-05-16 13:30:26 -07:00
2021-07-16 11:18:09 -07:00
// fixtures
const load = name => yaml.safeLoad(fs.readFileSync(
path.join(__dirname, `../fixtures/${name}`)
).toString())
const minimal = load('minimal.yaml')
const big = load('big.yaml')
const minimal_kle = load('minimal_kle.json')
const atreus_kle = load('atreus_kle.json')
2021-05-16 13:30:26 -07:00
describe('Interface', function() {
2021-07-16 16:15:27 -07:00
this.timeout(120000)
this.slow(120000)
2021-07-16 11:18:09 -07:00
it('debug', async function() {
// to check whether the output has "private" exports
const underscore = obj => {
for (const val of Object.values(obj)) {
for (const key of Object.keys(val)) {
if (key.startsWith('_')) return true
}
}
return false
}
2021-07-15 13:03:03 -07:00
underscore(await ergogen.process(minimal)).should.be.false
2021-07-16 11:18:09 -07:00
underscore(await ergogen.process(big, false)).should.be.false
underscore(await ergogen.process(big, true)).should.be.true
2021-05-16 13:30:26 -07:00
})
2021-07-16 11:18:09 -07:00
it('formats', async function() {
const logger = msg => {
if (msg.startsWith('Interpreting format:')) {
throw msg.split(':')[1].trim()
}
}
return Promise.all([
ergogen.process(minimal, true, logger).should.be.rejectedWith('OBJ'),
ergogen.process(yaml.dump(minimal), true, logger).should.be.rejectedWith('YAML'),
ergogen.process(`
//:
return {points: {}}
`, true, logger).should.be.rejectedWith('JS'),
ergogen.process(`
//:
return 'not an object';
`, true, logger).should.be.rejectedWith('not valid'),
ergogen.process(minimal_kle, true, logger).should.be.rejectedWith('KLE'),
ergogen.process(atreus_kle, true, logger).should.be.rejectedWith('KLE'),
2021-07-16 11:18:09 -07:00
ergogen.process('not an object', true, logger).should.be.rejectedWith('object'),
ergogen.process({}, true, logger).should.be.rejectedWith('empty'),
2021-07-17 15:39:33 -07:00
ergogen.process({not_points: {}}, true, () => {}).should.be.rejectedWith('points clause'),
ergogen.process({points: {zones: {}}}, true, () => {}).should.be.rejectedWith('any points')
2021-07-16 11:18:09 -07:00
])
2021-05-16 13:30:26 -07:00
})
2022-01-14 10:28:19 -08:00
it('preprocessor', async function() {
return Promise.all([
// unnesting
ergogen.process({'points.zones.matrix': {}}).should.eventually.have.deep.property('canonical', {
points: {zones: {matrix: {}}}
}),
// inheritance
ergogen.process({
'points.zones.parent.key.a': 1,
'points.zones.child': {
'$extends': 'points.zones.parent',
'key.b': 2
}
}).should.eventually.have.deep.nested.property('canonical.points.zones.child.key', {
a: 1,
b: 2
}),
// parameterization
ergogen.process({
'points.zones.matrix.key': {
a: 'PAR',
$params: ['PAR'],
$args: [1]
}
}).should.eventually.have.deep.nested.property('canonical.points.zones.matrix.key', {
a: '1'
})
])
})
2021-05-16 13:30:26 -07:00
2021-12-15 11:33:50 -08:00
it('engine', async function() {
return Promise.all([
ergogen.process({'meta.engine': 'invalid'}).should.be.rejectedWith('Invalid'),
ergogen.process({'meta.engine': '0.1.2'}).should.be.rejectedWith('satisfy'),
2021-12-15 11:33:50 -08:00
// no "points clause" means we're over the engine check, so it "succeeded"
ergogen.process({'meta.engine': `${version}`}).should.be.rejectedWith('points clause')
2021-12-15 11:33:50 -08:00
])
})
2021-05-16 13:30:26 -07:00
})