Skip to content

Commit 64427b0

Browse files
authored
tests: auto-generated from examples.yml (lowlighter#773) [skip ci]
1 parent 4d06539 commit 64427b0

File tree

91 files changed

+524
-831
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+524
-831
lines changed

.github/examples.mjs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import yaml from "js-yaml"
1010
const __metrics = paths.join(paths.dirname(url.fileURLToPath(import.meta.url)), "..")
1111
const __templates = paths.join(paths.join(__metrics, "source/templates/"))
1212
const __plugins = paths.join(paths.join(__metrics, "source/plugins/"))
13+
const __test_plugins = paths.join(paths.join(__metrics, "tests/plugins"))
1314

1415
//Load plugins metadata
1516
const {plugins, templates} = await metadata({log:false, diff:true})
@@ -18,25 +19,62 @@ async function plugin(id) {
1819
const path = paths.join(__plugins, id)
1920
const readme = paths.join(path, "README.md")
2021
const examples = paths.join(path, "examples.yml")
22+
const tests = paths.join(__test_plugins, id)
2123
return {
2224
readme:{
2325
path:readme,
2426
content:`${await fs.readFile(readme)}`
2527
},
28+
tests:{
29+
dir:tests,
30+
file:paths.join(tests, "tests.yml")
31+
},
2632
examples:fss.existsSync(examples) ? yaml.load(await fs.readFile(examples), "utf8") ?? [] : [],
2733
options:plugins[id].readme.table
2834
}
2935
}
3036

37+
const secrets = {
38+
$regex:/\$\{\{\s*secrets\.(?<secret>\w+)\s*\}\}/,
39+
METRICS_TOKEN:"MOCKED_TOKEN",
40+
METRICS_BOT_TOKEN:"MOCKED_TOKEN",
41+
PAGESPEED_TOKEN:"MOCKED_TOKEN",
42+
SPOTIFY_TOKENS:"MOCKED_CLIENT_ID, MOCKED_CLIENT_SECRET, MOCKED_REFRESH_TOKEN",
43+
YOUTUBE_MUSIC_TOKEN:"SAPISID=MOCKED_COOKIE; OTHER_PARAM=OTHER_VALUE;",
44+
LASTFM_TOKEN:"MOCKED_TOKEN",
45+
NIGHTSCOUT_URL:"https://testapp.herokuapp.com/",
46+
WAKATIME_TOKEN:"MOCKED_TOKEN",
47+
WAKATIME_TOKEN_NO_PROJECTS:"MOCKED_TOKEN_NO_PROJECTS",
48+
TWITTER_TOKEN:"MOCKED_TOKEN",
49+
RAPIDAPI_TOKEN:"MOCKED_TOKEN",
50+
}
51+
3152
//Plugins
3253
for (const id of Object.keys(plugins)) {
33-
const {examples, options, readme} = await plugin(id)
54+
const {examples, options, readme, tests} = await plugin(id)
55+
3456
//Plugin readme
3557
await fs.writeFile(readme.path, readme.content
3658
.replace(/(<!--examples-->)[\s\S]*(<!--\/examples-->)/g, `$1\n${examples.map(({test, prod, ...step}) => ["```yaml", yaml.dump(step), "```"].join("\n")).join("\n")}\n$2`)
3759
.replace(/(<!--options-->)[\s\S]*(<!--\/options-->)/g, `$1\n${options}\n$2`)
3860
)
3961
//Plugin tests
62+
await fs.mkdir(tests.dir, { recursive: true });
63+
await fs.writeFile(tests.file, yaml.dump(examples.map(({prod, test = {}, name = "", ...step}) => {
64+
const result = {name:`${plugins[id].name} - ${name}`, ...step, ...test}
65+
test.with ??= {}
66+
for (const [k, v] of Object.entries(result.with)) {
67+
if (k in test.with)
68+
result.with[k] = test.with[k]
69+
if (secrets.$regex.test(v))
70+
result.with[k] = v.replace(secrets.$regex, secrets[v.match(secrets.$regex)?.groups?.secret])
71+
}
72+
if (!result.with.base)
73+
delete result.with.base
74+
delete result.with.filename
75+
return result
76+
})))
77+
4078
}
4179

4280
//Templates

source/plugins/achievements/examples.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
base: ""
77
plugin_achievements: yes
88
plugin_achievements_only: sponsor, maintainer, octonaut
9-
test:
10-
timeout: 900000
119

1210
- name: Compact display
1311
uses: lowlighter/metrics@latest
@@ -19,5 +17,3 @@
1917
plugin_achievements_only: polyglot, stargazer, sponsor, deployer, member, maintainer, developer, scripter, packager, explorer, infographile, manager
2018
plugin_achievements_display: compact
2119
plugin_achievements_threshold: X
22-
test:
23-
timeout: 900000

source/plugins/achievements/tests.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

source/plugins/activity/tests.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

source/plugins/anilist/tests.yml

Lines changed: 0 additions & 62 deletions
This file was deleted.

source/plugins/base/tests.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.

source/plugins/contributors/tests.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

source/plugins/core/examples.yml

Whitespace-only changes.

source/plugins/core/tests.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

source/plugins/discussions/tests.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)