2021-03-23 19:20:03 +00:00
|
|
|
import { suite } from 'uvu';
|
|
|
|
import * as assert from 'uvu/assert';
|
|
|
|
import { createRuntime } from '../lib/runtime.js';
|
|
|
|
import { loadConfig } from '../lib/config.js';
|
|
|
|
import { doc } from './test-utils.js';
|
|
|
|
|
2021-03-24 15:45:38 +00:00
|
|
|
const Markdown = suite('Astro Markdown');
|
2021-03-23 19:20:03 +00:00
|
|
|
|
|
|
|
let runtime, setupError;
|
|
|
|
|
2021-03-24 15:45:38 +00:00
|
|
|
Markdown.before(async () => {
|
|
|
|
const astroConfig = await loadConfig(new URL('./fixtures/astro-markdown', import.meta.url).pathname);
|
2021-03-26 19:14:32 +00:00
|
|
|
|
2021-03-23 19:20:03 +00:00
|
|
|
const logging = {
|
|
|
|
level: 'error',
|
2021-03-26 19:14:32 +00:00
|
|
|
dest: process.stderr,
|
2021-03-23 19:20:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
runtime = await createRuntime(astroConfig, logging);
|
2021-03-26 19:14:32 +00:00
|
|
|
} catch (err) {
|
2021-03-23 19:20:03 +00:00
|
|
|
console.error(err);
|
|
|
|
setupError = err;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-24 15:45:38 +00:00
|
|
|
Markdown.after(async () => {
|
2021-03-26 19:14:32 +00:00
|
|
|
(await runtime) && runtime.shutdown();
|
2021-03-23 19:20:03 +00:00
|
|
|
});
|
|
|
|
|
2021-03-24 15:45:38 +00:00
|
|
|
Markdown('No errors creating a runtime', () => {
|
2021-03-23 19:20:03 +00:00
|
|
|
assert.equal(setupError, undefined);
|
|
|
|
});
|
|
|
|
|
2021-03-24 15:45:38 +00:00
|
|
|
Markdown('Can load markdown pages with hmx', async () => {
|
2021-03-23 19:20:03 +00:00
|
|
|
const result = await runtime.load('/post');
|
|
|
|
|
|
|
|
assert.equal(result.statusCode, 200);
|
|
|
|
|
|
|
|
const $ = doc(result.contents);
|
|
|
|
assert.ok($('#first').length, 'There is a div added in markdown');
|
|
|
|
assert.ok($('#test').length, 'There is a div added via a component from markdown');
|
|
|
|
});
|
|
|
|
|
2021-03-26 19:14:32 +00:00
|
|
|
Markdown.run();
|