From 87b7c2d483d8ce9d5e5d44cc267e3c232f0e60be Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sun, 9 Feb 2025 20:12:26 -0800 Subject: [PATCH] Assert example 1.6 logs to console --- test/examples.test.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/test/examples.test.js b/test/examples.test.js index b65ee33..a39e2f9 100644 --- a/test/examples.test.js +++ b/test/examples.test.js @@ -3,7 +3,7 @@ import { ok } from 'node:assert/strict'; import { mkdir, cp, opendir, readFile, rm } from 'node:fs/promises'; import { pathToFileURL } from 'node:url'; -import { createTempFolder } from './utils.js'; +import { createTempFolder, assertConsole } from './utils.js'; const dir = await createTempFolder(); const tempExamples = pathToFileURL(`${dir}/examples/`); // Trailing forward slash is REQUIRED for using this URL as a URL base later @@ -35,11 +35,22 @@ for await (const file of files) { suite('examples', { concurrency: true }, () => { after(async () => await rm(dir, { recursive: true, force: true })); for (const { name, code, output } of tests) { - test(name, { concurrency: true }, async () => { - const expected = await readFile(output); - await import(code); - const actual = await readFile(output); - ok(actual.equals(expected)); - }); + if (name === 'ex1_6') { + test(name, { concurrency: true }, async (t) => { + assertConsole(t, { log: 1 }); + const expected = await readFile(output); + await import(code); + const actual = await readFile(output); + ok(actual.equals(expected)); + }); + } + else { + test(name, { concurrency: true }, async () => { + const expected = await readFile(output); + await import(code); + const actual = await readFile(output); + ok(actual.equals(expected)); + }); + } } }); -- 2.47.3