2021-04-14 13:21:25 -06:00
|
|
|
import { fileURLToPath } from 'url';
|
2021-03-23 13:47:54 -04: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 15:20:03 -04:00
|
|
|
let runtime, setupError;
|
2021-03-23 13:47:54 -04:00
|
|
|
|
|
|
|
React.before(async () => {
|
2021-04-14 13:21:25 -06:00
|
|
|
const astroConfig = await loadConfig(fileURLToPath(new URL('./fixtures/react-component', import.meta.url)));
|
2021-03-23 13:47:54 -04:00
|
|
|
|
|
|
|
const logging = {
|
|
|
|
level: 'error',
|
2021-03-26 13:14:32 -06:00
|
|
|
dest: process.stderr,
|
2021-03-23 13:47:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
2021-03-30 14:52:09 +00:00
|
|
|
runtime = await createRuntime(astroConfig, { logging });
|
2021-03-26 13:14:32 -06:00
|
|
|
} catch (err) {
|
2021-03-23 13:47:54 -04:00
|
|
|
console.error(err);
|
2021-03-23 15:20:03 -04:00
|
|
|
setupError = err;
|
2021-03-23 13:47:54 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
React.after(async () => {
|
2021-03-26 13:14:32 -06:00
|
|
|
(await runtime) && runtime.shutdown();
|
2021-03-23 13:47:54 -04:00
|
|
|
});
|
|
|
|
|
2021-03-23 15:20:03 -04:00
|
|
|
React('No error creating the runtime', () => {
|
|
|
|
assert.equal(setupError, undefined);
|
|
|
|
});
|
|
|
|
|
2021-04-09 14:23:25 -06:00
|
|
|
React('Can load React', async () => {
|
2021-03-23 13:47:54 -04:00
|
|
|
const result = await runtime.load('/');
|
|
|
|
|
|
|
|
assert.equal(result.statusCode, 200);
|
|
|
|
|
|
|
|
const $ = doc(result.contents);
|
2021-04-09 14:23:25 -06:00
|
|
|
assert.equal($('#react-h2').text(), 'Hello world!');
|
|
|
|
});
|
|
|
|
|
|
|
|
React('Can load Vue', async () => {
|
|
|
|
const result = await runtime.load('/');
|
|
|
|
|
|
|
|
assert.equal(result.statusCode, 200);
|
|
|
|
|
|
|
|
const $ = doc(result.contents);
|
|
|
|
assert.equal($('#vue-h2').text(), 'Hasta la vista, baby');
|
2021-03-23 13:47:54 -04:00
|
|
|
});
|
|
|
|
|
2021-03-26 13:14:32 -06:00
|
|
|
React.run();
|