Skip to content
代码片段 群组 项目
提交 c9e99ba3 编辑于 作者: Timotej Ecimovic's avatar Timotej Ecimovic
浏览文件

Move API check to a separate test file.

上级 6a991c88
No related branches found
No related tags found
无相关合并请求
......@@ -151,11 +151,14 @@ function loadHelper(path) {
* @returns Object containing all the helper functions.
*/
function allGlobalHelpers() {
var allHelpers = {}
var allHelpers = {
api: {}, // keyed functions
duplicates: [], // array of duplicates
}
includedHelpers.forEach((path) => {
var h = require(path)
for (const singleHelper in h) {
allHelpers[singleHelper] = h[singleHelper]
allHelpers.api[singleHelper] = h[singleHelper]
}
})
return allHelpers
......
......@@ -22,8 +22,13 @@ const fs = require('fs')
var helpers = templateEngine.allGlobalHelpers()
var ar = []
for (const key in helpers) {
ar.push({ name: key, isDeprecated: helpers[key].isDeprecated })
if (helpers.duplicates.length > 0) {
console.log(`API has duplicates: ${helpers.duplicates}`)
process.exit(1)
}
for (const key in helpers.api) {
ar.push({ name: key, isDeprecated: helpers.api[key].isDeprecated })
}
ar.sort((a, b) => a.name.localeCompare(b.name))
......
/**
*
* Copyright (c) 2020 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 templateEngine = require('../src-electron/generator/template-engine.js')
const fs = require('fs')
const path = require('path')
test('helper functions need to be snake_case without uppercase characters unless they are deprecated', () => {
var helpers = templateEngine.allGlobalHelpers()
expect(Object.keys(helpers.api).length).toBeGreaterThan(10)
for (const x in helpers.api) {
expect(helpers.api[x]).not.toBeNull()
var n = x
if (!helpers.api[x].isDeprecated) expect(n.toLowerCase()).toEqual(n)
}
})
test('compare APIs against the baseline', () => {
var apiFromFile = JSON.parse(
fs.readFileSync(path.join(__dirname, 'helper-api-baseline.json'))
)
var helpers = templateEngine.allGlobalHelpers()
var errorMessage = ''
apiFromFile.forEach((api) => {
var fn = api.name
var apiFn = helpers.api[fn]
if (apiFn == undefined) {
errorMessage += `Helper ${fn} has been removed, breaking the API.\n`
}
})
expect(errorMessage).toEqual('')
})
......@@ -145,13 +145,3 @@ test('delimeter macros', () => {
expect(helperC.asDelimitedMacro('Very_123_Simple')).toEqual('VERY_123_SIMPLE')
expect(helperC.asDelimitedMacro('MfrDefGpdCmd0')).toEqual('MFR_DEF_GPD_CMD0')
})
test('helper functions need to be snake_case without uppercase characters unless they are deprecated', () => {
var helpers = templateEngine.allGlobalHelpers()
expect(Object.keys(helpers).length).toBeGreaterThan(10)
for (const x in helpers) {
expect(helpers[x]).not.toBeNull()
var n = x
if (!helpers[x].isDeprecated) expect(n.toLowerCase()).toEqual(n)
}
})
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册