ci: add workflow for presets ci
This commit is contained in:
22
.github/workflows/ci.presets.yml
vendored
Normal file
22
.github/workflows/ci.presets.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
name: Continuous integration (presets)
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ presets ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: Build, test and analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Setup NodeJS
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 17
|
||||||
|
- name: Setup metrics
|
||||||
|
run: npm ci
|
||||||
|
- name: Run tests
|
||||||
|
run: npm run test-presets
|
||||||
@@ -5,7 +5,8 @@
|
|||||||
"main": "index.mjs",
|
"main": "index.mjs",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node source/app/web/index.mjs",
|
"start": "node source/app/web/index.mjs",
|
||||||
"test": "jest --runInBand",
|
"test": "jest --runInBand --testPathIgnorePatterns presets.test.js",
|
||||||
|
"test-presets": "jest --runInBand presets.test.js",
|
||||||
"build": "node .github/scripts/build.mjs",
|
"build": "node .github/scripts/build.mjs",
|
||||||
"presets": "node .github/scripts/presets_examples.mjs",
|
"presets": "node .github/scripts/presets_examples.mjs",
|
||||||
"quickstart": "node .github/scripts/quickstart/index.mjs",
|
"quickstart": "node .github/scripts/quickstart/index.mjs",
|
||||||
@@ -14,8 +15,7 @@
|
|||||||
"format": "eslint source/**/*.mjs --fix",
|
"format": "eslint source/**/*.mjs --fix",
|
||||||
"dev": "nodemon source/app/web/index.mjs -e mjs,css,ejs,json",
|
"dev": "nodemon source/app/web/index.mjs -e mjs,css,ejs,json",
|
||||||
"postinstall": "node node_modules/puppeteer/install.js",
|
"postinstall": "node node_modules/puppeteer/install.js",
|
||||||
"indepth": "node source/plugins/languages/analyzers.mjs",
|
"indepth": "node source/plugins/languages/analyzers.mjs"
|
||||||
"autogen": "node .github/examples.mjs"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
78
tests/presets.test.js
Normal file
78
tests/presets.test.js
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
//Imports
|
||||||
|
const processes = require("child_process")
|
||||||
|
const yaml = require("js-yaml")
|
||||||
|
const fss = require("fs")
|
||||||
|
const paths = require("path")
|
||||||
|
|
||||||
|
//Git setup
|
||||||
|
const __metrics = paths.join(paths.dirname(__dirname, ".."))
|
||||||
|
const __presets = paths.join(__metrics, ".presets")
|
||||||
|
|
||||||
|
//Clone presets branch
|
||||||
|
try {
|
||||||
|
fss.accessSync(__presets)
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
processes.execSync(`git clone https://github.com/lowlighter/metrics.git ${__presets} --branch presets --single-branch`)
|
||||||
|
}
|
||||||
|
|
||||||
|
//Generate presets examples
|
||||||
|
for (const path of fss.readdirSync(__presets)) {
|
||||||
|
if (/^[.@]/.test(path))
|
||||||
|
continue
|
||||||
|
if (!(fss.lstatSync(paths.join(__presets, path))).isDirectory())
|
||||||
|
continue
|
||||||
|
|
||||||
|
describe(`Preset: ${path}`, () => {
|
||||||
|
try {
|
||||||
|
//Load preset
|
||||||
|
const preset = yaml.load(fss.readFileSync(paths.join(__presets, path, "preset.yml")))
|
||||||
|
test("syntax is valid", () => expect(true).toBe(true))
|
||||||
|
try {
|
||||||
|
//Load schema
|
||||||
|
const {properties} = yaml.load(fss.readFileSync(paths.join(__presets, "@schema", `${preset.schema}.yml`)))
|
||||||
|
test("schema is valid", () => expect(preset.schema).toBeDefined())
|
||||||
|
//Test schema
|
||||||
|
for (const [key, {type, required}] of Object.entries(properties)) {
|
||||||
|
if (required)
|
||||||
|
test(`preset.${key} is defined`, () => expect(preset[key]).toBeDefined())
|
||||||
|
test(`preset.${key} type is ${type}`, () => {
|
||||||
|
switch (true) {
|
||||||
|
case /^'.*'$/.test(type):{
|
||||||
|
const value = type.substring(1, type.length-1)
|
||||||
|
expect(preset[key]).toBe(value)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case /\{\}$/.test(type):{
|
||||||
|
const typed = type.substring(0, type.length-2)
|
||||||
|
expect(typeof preset[key]).toBe("object")
|
||||||
|
if (typed !== "unknown") {
|
||||||
|
for (const value of Object.values(preset[key]))
|
||||||
|
expect(typeof value).toBe(typed)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case /\[\]$/.test(type):{
|
||||||
|
const typed = type.substring(0, type.length-2)
|
||||||
|
expect(Array.isArray(preset[key])).toBe(true)
|
||||||
|
if (typed !== "unknown") {
|
||||||
|
for (const value of Object.values(preset[key]))
|
||||||
|
expect(typeof value).toBe(typed)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
expect(typeof preset[key]).toBe(type)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
test(`schema is valid (got ${preset.schema})`, () => expect(false).toBe(true))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
test("syntax is valid", () => expect(false).toBe(true))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user