Skip to content

Commit

Permalink
add tests for output logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lameuler committed Jan 8, 2025
1 parent a1930f3 commit 588c96f
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions packages/astro/test/astro-pageDirectoryUrl.test.js
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -14,19 +17,37 @@ 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 () => {
assert.ok(await fixture.readFile('/client.html'));
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({
Expand All @@ -35,13 +56,30 @@ 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 () => {
assert.ok(await fixture.readFile('/client.html'));
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')))
})
});
});

0 comments on commit 588c96f

Please sign in to comment.