mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-19 13:55:21 +00:00
Improve internal API
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import * as path from 'path';
|
||||
import * as assert from 'assert';
|
||||
import * as puppeteer from 'puppeteer';
|
||||
import * as api from '../../../api';
|
||||
@@ -13,50 +12,16 @@ describe('with-basepath', function() {
|
||||
let base: string;
|
||||
|
||||
// hooks
|
||||
before(() => {
|
||||
return new Promise((fulfil, reject) => {
|
||||
// TODO this is brittle. Make it unnecessary
|
||||
process.chdir(__dirname);
|
||||
process.env.NODE_ENV = 'production';
|
||||
before(async () => {
|
||||
await api.build({ cwd: __dirname });
|
||||
|
||||
// TODO this API isn't great. Rethink it
|
||||
const builder = api.build({
|
||||
bundler: 'rollup'
|
||||
}, {
|
||||
src: path.join(__dirname, 'src'),
|
||||
routes: path.join(__dirname, 'src/routes'),
|
||||
dest: path.join(__dirname, '__sapper__/build')
|
||||
});
|
||||
|
||||
builder.on('error', reject);
|
||||
builder.on('done', () => {
|
||||
// TODO it'd be nice if build and export returned promises.
|
||||
// not sure how best to combine promise and event emitter
|
||||
const exporter = api.exporter({
|
||||
build: '__sapper__/build',
|
||||
dest: '__sapper__/export',
|
||||
static: 'static',
|
||||
basepath: 'custom-basepath',
|
||||
timeout: 5000
|
||||
});
|
||||
|
||||
exporter.on('error', (err: Error) => {
|
||||
console.error(err);
|
||||
reject(err);
|
||||
});
|
||||
|
||||
exporter.on('done', async () => {
|
||||
try {
|
||||
runner = new AppRunner(__dirname, '__sapper__/build/server/server.js');
|
||||
({ base, page } = await runner.start());
|
||||
|
||||
fulfil();
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
await api.export({
|
||||
cwd: __dirname,
|
||||
basepath: 'custom-basepath'
|
||||
});
|
||||
|
||||
runner = new AppRunner(__dirname, '__sapper__/build/server/server.js');
|
||||
({ base, page } = await runner.start());
|
||||
});
|
||||
|
||||
after(() => runner.end());
|
||||
@@ -81,7 +46,7 @@ describe('with-basepath', function() {
|
||||
});
|
||||
|
||||
it('crawls an exported site with basepath', () => {
|
||||
const files = walk('__sapper__/export');
|
||||
const files = walk(`${__dirname}/__sapper__/export`);
|
||||
|
||||
const client_assets = files.filter(file => file.startsWith('custom-basepath/client/'));
|
||||
const non_client_assets = files.filter(file => !file.startsWith('custom-basepath/client/')).sort();
|
||||
Reference in New Issue
Block a user