Skip to content

Commit

Permalink
minor test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
itsMapleLeaf committed Mar 13, 2024
1 parent 07e334c commit 10b2955
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
// @ts-check

import { build, dev } from 'astro';
import assert from 'node:assert';
import { existsSync, readdirSync } from 'node:fs';
import { existsSync } from 'node:fs';
import { readdir } from 'node:fs/promises';
import { join } from 'node:path';
import { describe, it } from 'node:test';
import { build, dev } from 'astro';
import { fileURLToPath } from 'node:url';

const templatesDir = './templates/';
const templates = readdirSync(templatesDir);
const templatesDir = join(fileURLToPath(import.meta.url), '../../templates');

for (const template of templates) {
for (const template of await readdir(templatesDir)) {
describe(template, () => {
const root = templatesDir + template;
const root = join(templatesDir, template);

it('builds successfully', async () => {
await build({ root, logLevel: 'silent' });
await build({ root, logLevel: 'error' });
const distDir = join(root, 'dist');
assert.ok(
existsSync(`${root}/dist`),
`Expected "dist/" directory for template "${template}", but found none.`,
existsSync(distDir),
`Expected "dist" directory for template "${template}", but ${distDir} does not exist.`,
);
});

it('runs the dev server successfully', async () => {
const server = await dev({ root, logLevel: 'silent' });
const server = await dev({ root, logLevel: 'error' });
const res = await fetch(`http://localhost:${server.address.port}/`);
assert.strictEqual(
res.status,
Expand Down

0 comments on commit 10b2955

Please sign in to comment.