2021-03-23 17:47:54 +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';
|
|
|
|
|
|
|
|
const React = suite('React Components');
|
|
|
|
|
2021-03-23 19:20:03 +00:00
|
|
|
let runtime, setupError;
|
2021-03-23 17:47:54 +00:00
|
|
|
|
|
|
|
React.before(async () => {
|
|
|
|
const astroConfig = await loadConfig(new URL('./fixtures/react-component', import.meta.url).pathname);
|
|
|
|
|
|
|
|
const logging = {
|
|
|
|
level: 'error',
|
2021-03-26 19:14:32 +00:00
|
|
|
dest: process.stderr,
|
2021-03-23 17:47:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
runtime = await createRuntime(astroConfig, logging);
|
2021-03-26 19:14:32 +00:00
|
|
|
} catch (err) {
|
2021-03-23 17:47:54 +00:00
|
|
|
console.error(err);
|
2021-03-23 19:20:03 +00:00
|
|
|
setupError = err;
|
2021-03-23 17:47:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
React.after(async () => {
|
2021-03-26 19:14:32 +00:00
|
|
|
(await runtime) && runtime.shutdown();
|
2021-03-23 17:47:54 +00:00
|
|
|
});
|
|
|
|
|
2021-03-23 19:20:03 +00:00
|
|
|
React('No error creating the runtime', () => {
|
|
|
|
assert.equal(setupError, undefined);
|
|
|
|
});
|
|
|
|
|
2021-03-24 15:45:38 +00:00
|
|
|
React('Can load page', async () => {
|
2021-03-23 17:47:54 +00:00
|
|
|
const result = await runtime.load('/');
|
|
|
|
|
|
|
|
assert.equal(result.statusCode, 200);
|
|
|
|
|
|
|
|
const $ = doc(result.contents);
|
|
|
|
assert.equal($('h2').text(), 'Hello world!');
|
|
|
|
});
|
|
|
|
|
2021-03-26 19:14:32 +00:00
|
|
|
React.run();
|