|
| 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