Skip to content

Commit 20fb486

Browse files
ctcpipwesleytodd
andauthored
fix(test): ✅ add template consistency test (#241)
Co-authored-by: Wes Todd <[email protected]>
1 parent d33fcc1 commit 20fb486

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ jobs:
2525
- run: npm test
2626
- run: npm run test:integration-issues
2727

28+
test-templates:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
- name: Use Node.js 24
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: 24
36+
- run: npm install
37+
- run: npm run test:templates
38+
2839
testint:
2940
runs-on: ubuntu-latest
3041
# only run if not a fork PR targeting main repo due to permissions

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ When using EJS templates for your meeting issues, the following data properties
145145
'Australia/Sydney'
146146
]; %>
147147
148-
# <%= title %>
149-
150148
## Date/Time
151149
152150
| Timezone | Date/Time |

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"test:integration": "standard && mocha test/integration.js",
1717
"test:integration:debug": "GITHUB_TOKEN=$(gh auth token) mocha --inspect --inspect-brk test/integration.js",
1818
"test:integration-issues": "standard && mocha test/integration-issues.js",
19+
"test:templates": "standard && mocha test/templates.js",
1920
"lint:fix": "standard --fix",
2021
"preversion": "npm t",
2122
"postpublish": "git push origin && git push origin --tags",

test/templates.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
'use strict'
2+
/* global Temporal */
3+
const fs = require('fs')
4+
const path = require('path')
5+
const ejs = require('ejs')
6+
const { suite, test } = require('mocha')
7+
const assert = require('assert')
8+
if (!global.Temporal) {
9+
const polyfill = require('@js-temporal/polyfill')
10+
global.Temporal = polyfill.Temporal
11+
}
12+
13+
const testData = {
14+
date: Temporal.Instant.from('2024-01-01T12:00:00Z'),
15+
agendaIssues: [
16+
{ html_url: 'https://example.com/issue/1', title: 'issue 1' },
17+
{ html_url: 'https://example.com/issue/2', title: 'issue 2' }
18+
],
19+
agendaLabel: 'meeting-agenda',
20+
meetingNotes: 'https://example.com/notes',
21+
owner: 'test-owner',
22+
repo: 'test-repo',
23+
meetingLink: 'https://meet.example.com',
24+
title: 'Ye Olde Meetinge'
25+
}
26+
27+
const readme = fs.readFileSync(path.join(__dirname, '../README.md'), 'utf8')
28+
const defaultTemplate = require('../lib/default-template')
29+
const mdTemplate = fs.readFileSync(path.join(__dirname, '../.github/ISSUE_TEMPLATE/meeting.md'), 'utf8')
30+
31+
const compiledMd = ejs.render(mdTemplate, testData)
32+
const compiledDefault = defaultTemplate(testData)
33+
const readmeTemplate = getReadmeTemplate()
34+
35+
suite('template consistency', () => {
36+
test('default template should match md template', () => {
37+
const normalizedMd = normalizeOutput(compiledMd)
38+
const normalizedDefault = normalizeOutput(compiledDefault)
39+
40+
assert.strictEqual(normalizedMd, normalizedDefault)
41+
})
42+
43+
test('readme template should match md template', () => {
44+
const normalizedReadme = normalizeOutput(readmeTemplate)
45+
const normalizedMd = normalizeOutput(mdTemplate)
46+
47+
assert.strictEqual(normalizedReadme, normalizedMd)
48+
})
49+
})
50+
51+
function normalizeOutput (content) {
52+
return content.trim()
53+
}
54+
55+
function getReadmeTemplate () {
56+
const ejsStart = readme.indexOf('```ejs')
57+
const ejsEnd = readme.indexOf('```', ejsStart + 6)
58+
59+
if (ejsStart < 0 || ejsEnd < 0) {
60+
throw new Error('couldn\'t find ejs template section in readme')
61+
}
62+
63+
return readme.substring(ejsStart + 6, ejsEnd)
64+
}

0 commit comments

Comments
 (0)