Update tests
This commit is contained in:
@@ -1,81 +1,17 @@
|
|||||||
//Imports
|
//Imports
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import metrics from "../src/metrics.mjs"
|
|
||||||
import setup from "../src/setup.mjs"
|
|
||||||
import build from "../utils/build.mjs"
|
import build from "../utils/build.mjs"
|
||||||
import octokit from "@octokit/graphql"
|
|
||||||
import OctokitRest from "@octokit/rest"
|
|
||||||
import libxmljs from "libxmljs"
|
|
||||||
import url from "url"
|
import url from "url"
|
||||||
|
|
||||||
//Initialization
|
//Initialization
|
||||||
const __dirname = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "..", "action")
|
const __dirname = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "..", "action")
|
||||||
process.on("unhandledRejection", error => { throw error })
|
process.on("unhandledRejection", error => { throw error })
|
||||||
const templates = (await fs.promises.readdir(path.join(__dirname, "..", "src/templates"))).filter(name => !/.*[.]mjs$/.test(name))
|
|
||||||
|
|
||||||
/** Test function */
|
/** Test function */
|
||||||
export default async function test() {
|
export default async function test() {
|
||||||
//Load GitHub handlers
|
|
||||||
const token = process.argv.slice(2)[0]
|
|
||||||
const graphql = octokit.graphql.defaults({headers:{authorization: `token ${token}`}})
|
|
||||||
const rest = new OctokitRest.Octokit({auth:token})
|
|
||||||
|
|
||||||
//Perform tests
|
//Perform tests
|
||||||
await test.build()
|
await test.build()
|
||||||
for (const template of templates) {
|
|
||||||
for (const q of [
|
|
||||||
{},
|
|
||||||
{"base.header":0},
|
|
||||||
{"base.activity":0},
|
|
||||||
{"base.community":0},
|
|
||||||
{"base.repositories":0},
|
|
||||||
{"base.metadata":0},
|
|
||||||
{followup:1},
|
|
||||||
{languages:1},
|
|
||||||
{followup:1, languages:1},
|
|
||||||
{habits:1, "habits.events":1},
|
|
||||||
{lines:1},
|
|
||||||
{traffic:1},
|
|
||||||
{selfskip:1},
|
|
||||||
{pagespeed:1},
|
|
||||||
{music:1},
|
|
||||||
{music:1, "music.mode":"recent"},
|
|
||||||
{music:1, "music.mode":"recent", "music.provider":"apple"},
|
|
||||||
{music:1, "music.mode":"recent", "music.provider":"spotify"},
|
|
||||||
{music:1, "music.mode":"playlist"},
|
|
||||||
{followup:1, languages:1, habits:1, "habits.events":1, lines:1, traffic:1, selfskip:1, pagespeed:1, music:1},
|
|
||||||
]) {
|
|
||||||
await test.metrics({graphql, rest, q:{template, repositories:1, ...q}})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Metrics tests */
|
|
||||||
test.metrics = async function ({graphql, rest, q}) {
|
|
||||||
//Preparation
|
|
||||||
console.log(`### Checking metrics with [${Object.entries(q).map(([key, value]) => `${key}=${value}`).join(", ")}]`)
|
|
||||||
const plugins = {
|
|
||||||
lines:{enabled:true},
|
|
||||||
traffic:{enabled:true},
|
|
||||||
pagespeed:{enabled:true},
|
|
||||||
habits:{enabled:true},
|
|
||||||
selfskip:{enabled:true},
|
|
||||||
languages:{enabled:true},
|
|
||||||
followup:{enabled:true},
|
|
||||||
musit:{enabled:true},
|
|
||||||
}
|
|
||||||
|
|
||||||
//Compute render
|
|
||||||
console.log("#### Checking that SVG can be generated")
|
|
||||||
const conf = await setup({log:false})
|
|
||||||
const rendered = await metrics({login:"lowlighter", q}, {graphql, rest, plugins, conf})
|
|
||||||
|
|
||||||
//Ensure it's a well-formed SVG image
|
|
||||||
console.log("#### Checking that generated SVG can be parsed")
|
|
||||||
const parsed = libxmljs.parseXml(rendered)
|
|
||||||
if (parsed.errors.length)
|
|
||||||
throw new Error(`Malformed SVG : \n${parsed.errors.join("\n")}`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Build test */
|
/** Build test */
|
||||||
@@ -88,7 +24,6 @@
|
|||||||
throw new Error(`GitHub Action has not been rebuild. Run "npm run build" to solve this issue`)
|
throw new Error(`GitHub Action has not been rebuild. Run "npm run build" to solve this issue`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Main
|
//Main
|
||||||
if (/metrics.mjs/.test(process.argv[1])) {
|
if (/metrics.mjs/.test(process.argv[1])) {
|
||||||
//Test
|
//Test
|
||||||
|
|||||||
Reference in New Issue
Block a user