Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions _tests/e2e-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ import path from 'node:path'
import yaml from 'js-yaml'
import test from 'ava'

/**
* Sanitize a string for safe inclusion in XML/TAP output;
* removes ANSI escape codes and replaces control characters.
*
* Nota bene: Errors thrown by Puppeteer/Chrome may contain escape codes and/or
* control characters that must be removed before inclusion in XML output.
*/
const sanitizeForXml = (str) => {
if (!str) return ''
return str
// Remove ANSI escape codes
.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, '')
// Replace control characters (except newline/tab) with spaces
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, ' ')
// Truncate to reasonable length
.slice(0, 2000)
}

const publicationName = 'test-publication'
const pathedPub = `${publicationName}-pathname`

Expand Down Expand Up @@ -63,22 +81,22 @@ const buildSitePdfEpub = async (t) => {
const downloadsDir = path.join('_site', '_assets', 'downloads')
const publicationPdf = path.join(downloadsDir, 'publication.pdf')
if (!fs.existsSync(publicationPdf)) {
t.fail(`No publication PDF generated! ${buildStdout} ${buildStderr}`)
t.fail(`No publication PDF generated! ${sanitizeForXml(buildStdout)} ${sanitizeForXml(buildStderr)}`)
}

const essayPdf = path.join(downloadsDir, 'publication-essay.pdf')
if (!fs.existsSync(essayPdf)) {
t.fail(`No essay PDF generated! ${pdfStdout} ${pdfStderr}`)
t.fail(`No essay PDF generated! ${sanitizeForXml(pdfStdout)} ${sanitizeForXml(pdfStderr)}`)
}

const epubDir = '_epub'
if (!fs.existsSync(epubDir)) {
t.fail(`No epub assets generated! ${stdout} ${stderr}`)
t.fail(`No epub assets generated! ${sanitizeForXml(epubStdout)} ${sanitizeForXml(epubStderr)}`)
}

const epubFile = 'epubjs.epub'
if (!fs.existsSync(epubFile)) {
t.fail(`No epub file generated! ${epubStdout} ${epubStderr}`)
t.fail(`No epub file generated! ${sanitizeForXml(epubStdout)} ${sanitizeForXml(epubStderr)}`)
}
}

Expand Down