blob: 6fe38a9e3cf74dfb0dfe1205c91f21dfac59b278 [file] [log] [blame]
/**
*
* Copyright (c) 2021 Silicon Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* @jest-environment node
*/
const path = require('path')
const genEngine = require('../src-electron/generator/generation-engine')
const env = require('../src-electron/util/env')
const dbApi = require('../src-electron/db/db-api')
const querySession = require('../src-electron/db/query-session')
const zclLoader = require('../src-electron/zcl/zcl-loader')
const importJs = require('../src-electron/importexport/import')
const testUtil = require('./test-util')
let db
let templateContext
let zclPackageId
const testFile = testUtil.matterTestFile.matterTest
const templateCount = testUtil.testTemplate.matter3Count
beforeAll(async () => {
env.setDevelopmentEnv()
let file = env.sqliteTestFile('gen-matter-3')
db = await dbApi.initDatabaseAndLoadSchema(
file,
env.schemaFile(),
env.zapVersion()
)
let ctx = await zclLoader.loadZcl(db, env.builtinMatterZclMetafile())
zclPackageId = ctx.packageId
}, testUtil.timeout.medium())
afterAll(() => dbApi.closeDatabase(db), testUtil.timeout.short())
test(
'Basic gen template parsing and generation',
async () => {
templateContext = await genEngine.loadTemplates(
db,
testUtil.testTemplate.matter3
)
expect(templateContext.crc).not.toBeNull()
expect(templateContext.templateData).not.toBeNull()
expect(templateContext.templateData.name).toEqual('Matter 3 test templates')
expect(templateContext.templateData.version).toEqual('matter-3')
expect(templateContext.templateData.templates.length).toEqual(templateCount)
expect(templateContext.packageId).not.toBeNull()
},
testUtil.timeout.medium()
)
test(
`Zap file generation: ${path.relative(__dirname, testFile)}`,
async () => {
let sessionId = await querySession.createBlankSession(db)
await importJs.importDataFromFile(db, testFile, {
sessionId: sessionId
})
let genResult = await genEngine.generate(
db,
sessionId,
templateContext.packageId,
{},
{ disableDeprecationWarnings: true }
)
expect(genResult.hasErrors).toEqual(false)
},
testUtil.timeout.long()
)