2021-04-14 19:21:25 +00:00
|
|
|
import { fileURLToPath } from 'url';
|
2021-04-19 20:13:53 +00:00
|
|
|
import { build as astroBuild } from '../lib/build.js';
|
2021-03-31 20:10:27 +00:00
|
|
|
import { loadConfig } from '../lib/config.js';
|
2021-04-19 20:13:53 +00:00
|
|
|
import { createRuntime } from '../lib/runtime.js';
|
2021-03-31 20:10:27 +00:00
|
|
|
import * as assert from 'uvu/assert';
|
2021-04-12 15:20:58 +00:00
|
|
|
/** setup fixtures for tests */
|
2021-03-31 20:10:27 +00:00
|
|
|
export function setup(Suite, fixturePath) {
|
|
|
|
let runtime, setupError;
|
|
|
|
|
|
|
|
Suite.before(async (context) => {
|
2021-04-14 19:21:25 +00:00
|
|
|
const astroConfig = await loadConfig(fileURLToPath(new URL(fixturePath, import.meta.url)));
|
2021-03-31 20:10:27 +00:00
|
|
|
|
|
|
|
const logging = {
|
|
|
|
level: 'error',
|
|
|
|
dest: process.stderr,
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
runtime = await createRuntime(astroConfig, { logging });
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
setupError = err;
|
|
|
|
}
|
|
|
|
|
|
|
|
context.runtime = runtime;
|
|
|
|
});
|
|
|
|
|
|
|
|
Suite.after(async () => {
|
|
|
|
(await runtime) && runtime.shutdown();
|
|
|
|
});
|
|
|
|
|
|
|
|
Suite('No errors creating a runtime', () => {
|
|
|
|
assert.equal(setupError, undefined);
|
|
|
|
});
|
|
|
|
}
|
2021-04-19 20:13:53 +00:00
|
|
|
|
|
|
|
export function setupBuild(Suite, fixturePath) {
|
|
|
|
let build, setupError;
|
|
|
|
|
|
|
|
Suite.before(async (context) => {
|
|
|
|
const astroConfig = await loadConfig(fileURLToPath(new URL(fixturePath, import.meta.url)));
|
|
|
|
|
|
|
|
const logging = {
|
|
|
|
level: 'error',
|
|
|
|
dest: process.stderr,
|
|
|
|
};
|
|
|
|
|
|
|
|
build = (...args) => astroBuild(astroConfig, ...args);
|
|
|
|
context.build = build;
|
|
|
|
});
|
|
|
|
|
|
|
|
Suite.after(async () => {
|
|
|
|
// Shutdown i guess.
|
|
|
|
});
|
|
|
|
|
|
|
|
Suite('No errors creating a runtime', () => {
|
|
|
|
assert.equal(setupError, undefined);
|
|
|
|
});
|
|
|
|
}
|