From ed8f695ab1d3b8a01818403dd79189345f18ec47 Mon Sep 17 00:00:00 2001 From: ctcpip Date: Thu, 7 Aug 2025 18:03:11 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20add=20template=20consistency=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 12 +++++++ README.md | 2 -- lib/default-template.js | 1 + package.json | 1 + test/templates.js | 64 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 test/templates.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 24388c5..8dff2b8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,6 +24,17 @@ jobs: - run: npm install - run: npm test + test-templates: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Use Node.js 24 + uses: actions/setup-node@v4 + with: + node-version: 24 + - run: npm install + - run: npm run test:templates + testint: runs-on: ubuntu-latest steps: @@ -36,6 +47,7 @@ jobs: - run: npm run test:integration env: GITHUB_TOKEN: ${{ secrets.INT_TEST_TOKEN }} + action-in-action: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index 42d3c6f..e3d2325 100644 --- a/README.md +++ b/README.md @@ -145,8 +145,6 @@ When using EJS templates for your meeting issues, the following data properties 'Australia/Sydney' ]; %> -# <%= title %> - ## Date/Time | Timezone | Date/Time | diff --git a/lib/default-template.js b/lib/default-template.js index d2afe41..8fd4caf 100644 --- a/lib/default-template.js +++ b/lib/default-template.js @@ -37,6 +37,7 @@ ${timezones.map((zone) => { }).join('\n')} Or in your local time: + * https://www.timeanddate.com/worldclock/?iso=${date.toZonedDateTimeISO('UTC').toPlainDateTime().toString()} ## Agenda diff --git a/package.json b/package.json index dc0ee4d..6434dfd 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "test": "standard && mocha test/index.js", "test:integration": "standard && mocha test/integration.js", "test:integration:debug": "GITHUB_TOKEN=$(gh auth token) mocha --inspect --inspect-brk test/integration.js", + "test:templates": "standard && mocha test/templates.js", "lint:fix": "standard --fix", "preversion": "npm t", "postpublish": "git push origin && git push origin --tags", diff --git a/test/templates.js b/test/templates.js new file mode 100644 index 0000000..0ca8df8 --- /dev/null +++ b/test/templates.js @@ -0,0 +1,64 @@ +'use strict' +/* global Temporal */ +const fs = require('fs') +const path = require('path') +const ejs = require('ejs') +const { suite, test } = require('mocha') +const assert = require('assert') +if (!global.Temporal) { + const polyfill = require('@js-temporal/polyfill') + global.Temporal = polyfill.Temporal +} + +const testData = { + date: Temporal.Instant.from('2024-01-01T12:00:00Z'), + agendaIssues: [ + { html_url: 'https://example.com/issue/1', title: 'issue 1' }, + { html_url: 'https://example.com/issue/2', title: 'issue 2' } + ], + agendaLabel: 'meeting-agenda', + meetingNotes: 'https://example.com/notes', + owner: 'test-owner', + repo: 'test-repo', + meetingLink: 'https://meet.example.com', + title: 'Ye Olde Meetinge' +} + +const readme = fs.readFileSync(path.join(__dirname, '../README.md'), 'utf8') +const defaultTemplate = require('../lib/default-template') +const mdTemplate = fs.readFileSync(path.join(__dirname, '../.github/ISSUE_TEMPLATE/meeting.md'), 'utf8') + +const compiledMd = ejs.render(mdTemplate, testData) +const compiledDefault = defaultTemplate(testData) +const readmeTemplate = getReadmeTemplate() + +suite('template consistency', () => { + test('default template should match md template', () => { + const normalizedMd = normalizeOutput(compiledMd) + const normalizedDefault = normalizeOutput(compiledDefault) + + assert.strictEqual(normalizedMd, normalizedDefault) + }) + + test('readme template should match md template', () => { + const normalizedReadme = normalizeOutput(readmeTemplate) + const normalizedMd = normalizeOutput(mdTemplate) + + assert.strictEqual(normalizedReadme, normalizedMd) + }) +}) + +function normalizeOutput (content) { + return content.trim() +} + +function getReadmeTemplate () { + const ejsStart = readme.indexOf('```ejs') + const ejsEnd = readme.indexOf('```', ejsStart + 6) + + if (ejsStart < 0 || ejsEnd < 0) { + throw new Error('couldn\'t find ejs template section in readme') + } + + return readme.substring(ejsStart + 6, ejsEnd) +}