From 588c96f31d88a8cb2bef5cb29a670061413923bf Mon Sep 17 00:00:00 2001 From: lam eu ler <27113373+lameuler@users.noreply.github.com> Date: Wed, 8 Jan 2025 21:17:11 +0800 Subject: [PATCH] add tests for output logging --- .../astro/test/astro-pageDirectoryUrl.test.js | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/astro/test/astro-pageDirectoryUrl.test.js b/packages/astro/test/astro-pageDirectoryUrl.test.js index 76e224b07466..d3b9aaa002b9 100644 --- a/packages/astro/test/astro-pageDirectoryUrl.test.js +++ b/packages/astro/test/astro-pageDirectoryUrl.test.js @@ -1,11 +1,14 @@ import assert from 'node:assert/strict'; +import { Writable } from 'node:stream'; import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; +import { Logger } from '../dist/core/logger/core.js'; describe('build format', () => { describe('build.format: file', () => { /** @type {import('./test-utils.js').Fixture} */ let fixture; + const logs = []; before(async () => { fixture = await loadFixture({ @@ -14,7 +17,18 @@ describe('build format', () => { format: 'file', }, }); - await fixture.build(); + await fixture.build({ + logger: new Logger({ + level: 'info', + dest: new Writable({ + objectMode: true, + write(event, _, callback) { + logs.push(event); + callback(); + }, + }), + }) + }); }); it('outputs', async () => { @@ -22,11 +36,18 @@ describe('build format', () => { assert.ok(await fixture.readFile('/nested-md.html')); assert.ok(await fixture.readFile('/nested-astro.html')); }); + + it('logs correct output paths', () => { + assert.ok(logs.find((log) => log.level === 'info' && log.message.includes('/client.html'))) + assert.ok(logs.find((log) => log.level === 'info' && log.message.includes('/nested-md.html'))) + assert.ok(logs.find((log) => log.level === 'info' && log.message.includes('/nested-astro.html'))) + }) }); describe('build.format: preserve', () => { /** @type {import('./test-utils.js').Fixture} */ let fixture; + const logs = []; before(async () => { fixture = await loadFixture({ @@ -35,7 +56,18 @@ describe('build format', () => { format: 'preserve', }, }); - await fixture.build(); + await fixture.build({ + logger: new Logger({ + level: 'info', + dest: new Writable({ + objectMode: true, + write(event, _, callback) { + logs.push(event); + callback(); + }, + }), + }), + }); }); it('outputs', async () => { @@ -43,5 +75,11 @@ describe('build format', () => { assert.ok(await fixture.readFile('/nested-md/index.html')); assert.ok(await fixture.readFile('/nested-astro/index.html')); }); + + it('logs correct output paths', () => { + assert.ok(logs.find((log) => log.level === 'info' && log.message.includes('/client.html'))) + assert.ok(logs.find((log) => log.level === 'info' && log.message.includes('/nested-md/index.html'))) + assert.ok(logs.find((log) => log.level === 'info' && log.message.includes('/nested-astro/index.html'))) + }) }); });