2021-03-19 21:17:38 +00:00
|
|
|
import { suite } from 'uvu';
|
|
|
|
import * as assert from 'uvu/assert';
|
|
|
|
import { createRuntime } from '../lib/runtime.js';
|
2021-03-23 17:47:54 +00:00
|
|
|
import { loadConfig } from '../lib/config.js';
|
2021-03-19 21:17:38 +00:00
|
|
|
import { promises as fsPromises } from 'fs';
|
|
|
|
import { relative as pathRelative } from 'path';
|
|
|
|
import { doc } from './test-utils.js';
|
|
|
|
|
|
|
|
const { readdir, stat } = fsPromises;
|
|
|
|
|
|
|
|
const SnowpackDev = suite('snowpack.dev');
|
|
|
|
|
2021-03-23 19:20:03 +00:00
|
|
|
let runtime, cwd, setupError;
|
2021-03-19 21:17:38 +00:00
|
|
|
|
|
|
|
SnowpackDev.before(async () => {
|
2021-03-26 19:14:32 +00:00
|
|
|
// Bug: Snowpack config is still loaded relative to the current working directory.
|
2021-03-23 17:47:54 +00:00
|
|
|
cwd = process.cwd();
|
|
|
|
process.chdir(new URL('../examples/snowpack/', import.meta.url).pathname);
|
|
|
|
|
|
|
|
const astroConfig = await loadConfig(new URL('../examples/snowpack', import.meta.url).pathname);
|
2021-03-21 22:13:38 +00:00
|
|
|
|
2021-03-19 21:17:38 +00:00
|
|
|
const logging = {
|
|
|
|
level: 'error',
|
2021-03-21 22:13:38 +00:00
|
|
|
dest: process.stderr,
|
2021-03-19 21:17:38 +00:00
|
|
|
};
|
|
|
|
|
2021-03-23 17:47:54 +00:00
|
|
|
try {
|
2021-03-30 14:51:31 +00:00
|
|
|
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
|
|
|
}
|
2021-03-19 21:17:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
SnowpackDev.after(async () => {
|
2021-03-23 17:47:54 +00:00
|
|
|
process.chdir(cwd);
|
2021-03-26 19:14:32 +00:00
|
|
|
(await runtime) && runtime.shutdown();
|
2021-03-19 21:17:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
async function* allPageFiles(root) {
|
|
|
|
for (const filename of await readdir(root)) {
|
|
|
|
const fullpath = new URL(filename, root);
|
|
|
|
const info = await stat(fullpath);
|
|
|
|
|
|
|
|
if (info.isDirectory()) {
|
|
|
|
yield* allPageFiles(new URL(fullpath + '/'));
|
|
|
|
} else {
|
|
|
|
yield fullpath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function* allPages(root) {
|
2021-03-21 22:13:38 +00:00
|
|
|
for await (let fileURL of allPageFiles(root)) {
|
2021-03-24 15:45:38 +00:00
|
|
|
let bare = fileURL.pathname.replace(/\.(astro|md)$/, '').replace(/index$/, '');
|
2021-03-19 21:17:38 +00:00
|
|
|
|
|
|
|
yield '/' + pathRelative(root.pathname, bare);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-23 19:20:03 +00:00
|
|
|
SnowpackDev('No error creating the runtime', () => {
|
|
|
|
assert.equal(setupError, undefined);
|
|
|
|
});
|
|
|
|
|
2021-03-21 22:13:38 +00:00
|
|
|
SnowpackDev('Can load every page', async () => {
|
2021-03-19 21:17:38 +00:00
|
|
|
const failed = [];
|
|
|
|
|
|
|
|
const pageRoot = new URL('../examples/snowpack/astro/pages/', import.meta.url);
|
2021-03-21 22:13:38 +00:00
|
|
|
for await (let pathname of allPages(pageRoot)) {
|
|
|
|
if (pathname.includes('proof-of-concept-dynamic')) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-03-19 21:17:38 +00:00
|
|
|
const result = await runtime.load(pathname);
|
2021-03-21 22:13:38 +00:00
|
|
|
if (result.statusCode === 500) {
|
2021-03-26 19:14:32 +00:00
|
|
|
failed.push({ ...result, pathname });
|
2021-03-19 21:17:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
assert.equal(result.statusCode, 200, `Loading ${pathname}`);
|
|
|
|
}
|
|
|
|
|
2021-03-22 03:34:11 +00:00
|
|
|
if (failed.length > 0) {
|
|
|
|
console.error(failed);
|
|
|
|
}
|
|
|
|
assert.equal(failed.length, 0, 'Failed pages');
|
2021-03-19 21:17:38 +00:00
|
|
|
});
|
|
|
|
|
2021-03-21 22:13:38 +00:00
|
|
|
SnowpackDev.run();
|