mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 11:15:14 +00:00
Adds a sapper extract CLI command, which scrapes the server to run as a static website starting at the site's root.
TESTED=Basic unit test ensuring relevant routes are added.
This commit is contained in:
@@ -5,6 +5,7 @@ const serve = require('serve-static');
|
||||
const Nightmare = require('nightmare');
|
||||
const getPort = require('get-port');
|
||||
const fetch = require('node-fetch');
|
||||
const walkSync = require('walk-sync');
|
||||
|
||||
run('production');
|
||||
run('development');
|
||||
@@ -70,6 +71,7 @@ function run(env) {
|
||||
if (env === 'production') {
|
||||
const cli = path.resolve(__dirname, '../../cli/index.js');
|
||||
await exec(`${cli} build`);
|
||||
await exec(`${cli} extract`);
|
||||
}
|
||||
|
||||
const resolved = require.resolve('../..');
|
||||
@@ -306,6 +308,57 @@ function run(env) {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
if (env === 'production') {
|
||||
describe('extract', () => {
|
||||
it('extract all pages', () => {
|
||||
const dest = path.resolve(__dirname, '../app/dist');
|
||||
|
||||
// Pages that should show up in the extraction directory.
|
||||
const expectedPages = [
|
||||
'index.html',
|
||||
'api/index.html',
|
||||
|
||||
'about/index.html',
|
||||
'api/about/index.html',
|
||||
|
||||
'blog/index.html',
|
||||
'api/blog/index.html',
|
||||
|
||||
'blog/a-very-long-post/index.html',
|
||||
'api/blog/a-very-long-post/index.html',
|
||||
|
||||
'blog/how-can-i-get-involved/index.html',
|
||||
'api/blog/how-can-i-get-involved/index.html',
|
||||
|
||||
'blog/how-is-sapper-different-from-next/index.html',
|
||||
'api/blog/how-is-sapper-different-from-next/index.html',
|
||||
|
||||
'blog/how-to-use-sapper/index.html',
|
||||
'api/blog/how-to-use-sapper/index.html',
|
||||
|
||||
'blog/what-is-sapper/index.html',
|
||||
'api/blog/what-is-sapper/index.html',
|
||||
|
||||
'blog/why-the-name/index.html',
|
||||
'api/blog/why-the-name/index.html',
|
||||
|
||||
'favicon.png',
|
||||
'global.css',
|
||||
'great-success.png',
|
||||
'manifest.json',
|
||||
'service-worker.js',
|
||||
'svelte-logo-192.png',
|
||||
'svelte-logo-512.png',
|
||||
];
|
||||
const allPages = walkSync(dest);
|
||||
|
||||
expectedPages.forEach((expectedPage) => {
|
||||
assert.ok(allPages.includes(expectedPage));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -322,4 +375,4 @@ function exec(cmd) {
|
||||
fulfil();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user