2021-03-23 14:20:03 -05: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 10:45:38 -05:00
|
|
|
const Markdown = suite('Astro Markdown');
|
2021-03-23 14:20:03 -05:00
|
|
|
|
|
|
|
let runtime, setupError;
|
|
|
|
|
2021-03-24 10:45:38 -05:00
|
|
|
Markdown.before(async () => {
|
|
|
|
const astroConfig = await loadConfig(new URL('./fixtures/astro-markdown', import.meta.url).pathname);
|
2021-03-26 14:14:32 -05:00
|
|
|
|
2021-03-23 14:20:03 -05:00
|
|
|
const logging = {
|
|
|
|
level: 'error',
|
2021-03-26 14:14:32 -05:00
|
|
|
dest: process.stderr,
|
2021-03-23 14:20:03 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
runtime = await createRuntime(astroConfig, logging);
|
2021-03-26 14:14:32 -05:00
|
|
|
} catch (err) {
|
2021-03-23 14:20:03 -05:00
|
|
|
console.error(err);
|
|
|
|
setupError = err;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-24 10:45:38 -05:00
|
|
|
Markdown.after(async () => {
|
2021-03-26 14:14:32 -05:00
|
|
|
(await runtime) && runtime.shutdown();
|
2021-03-23 14:20:03 -05:00
|
|
|
});
|
|
|
|
|
2021-03-24 10:45:38 -05:00
|
|
|
Markdown('No errors creating a runtime', () => {
|
2021-03-23 14:20:03 -05:00
|
|
|
assert.equal(setupError, undefined);
|
|
|
|
});
|
|
|
|
|
2021-03-24 10:45:38 -05:00
|
|
|
Markdown('Can load markdown pages with hmx', async () => {
|
2021-03-23 14:20:03 -05: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 14:14:32 -05:00
|
|
|
Markdown.run();
|