diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4d4064f..757b662 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,6 +25,17 @@ jobs: - run: npm test - run: npm run test:integration-issues + 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 # only run if not a fork PR targeting main repo due to permissions diff --git a/README.md b/README.md index a285aa2..c694d79 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/package.json b/package.json index 1878da1..3c90e06 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "test:integration": "standard && mocha test/integration.js", "test:integration:debug": "GITHUB_TOKEN=$(gh auth token) mocha --inspect --inspect-brk test/integration.js", "test:integration-issues": "standard && mocha test/integration-issues.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) +}