mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-13 11:35:28 +00:00
use nightmare for testing
This commit is contained in:
@@ -9,7 +9,7 @@ const generate_asset_cache = require('./utils/generate_asset_cache.js');
|
||||
const { dest } = require('./config.js');
|
||||
|
||||
module.exports = () => {
|
||||
mkdirp(dest);
|
||||
mkdirp.sync(dest);
|
||||
rimraf.sync(path.join(dest, '**/*'));
|
||||
|
||||
// create main.js and server-routes.js
|
||||
|
||||
@@ -14,7 +14,7 @@ exports.dest = path.resolve(
|
||||
);
|
||||
|
||||
if (exports.dev) {
|
||||
mkdirp(exports.dest);
|
||||
mkdirp.sync(exports.dest);
|
||||
rimraf.sync(path.join(exports.dest, '**/*'));
|
||||
}
|
||||
|
||||
|
||||
17
lib/index.js
17
lib/index.js
@@ -20,7 +20,7 @@ function connect_dev() {
|
||||
|
||||
let asset_cache;
|
||||
|
||||
return compose_handlers([
|
||||
const middleware = compose_handlers([
|
||||
require('webpack-hot-middleware')(compilers.client, {
|
||||
reload: true,
|
||||
path: '/__webpack_hmr',
|
||||
@@ -59,6 +59,13 @@ function connect_dev() {
|
||||
|
||||
get_not_found_handler(() => asset_cache)
|
||||
]);
|
||||
|
||||
middleware.close = () => {
|
||||
watcher.close();
|
||||
// TODO shut down chokidar
|
||||
};
|
||||
|
||||
return middleware;
|
||||
}
|
||||
|
||||
function connect_prod() {
|
||||
@@ -67,7 +74,7 @@ function connect_prod() {
|
||||
read_json(path.join(dest, 'stats.server.json'))
|
||||
);
|
||||
|
||||
return compose_handlers([
|
||||
const middleware = compose_handlers([
|
||||
set_req_pathname,
|
||||
|
||||
get_asset_handler({
|
||||
@@ -95,6 +102,12 @@ function connect_prod() {
|
||||
|
||||
get_not_found_handler(() => asset_cache)
|
||||
]);
|
||||
|
||||
// here for API consistency between dev, and prod, but
|
||||
// doesn't actually need to do anything
|
||||
middleware.close = () => {};
|
||||
|
||||
return middleware;
|
||||
}
|
||||
|
||||
module.exports = dev ? connect_dev : connect_prod;
|
||||
|
||||
@@ -21,7 +21,8 @@ update();
|
||||
|
||||
if (dev) {
|
||||
const watcher = chokidar.watch(`${src}/**/*.+(html|js|mjs)`, {
|
||||
ignoreInitial: true
|
||||
ignoreInitial: true,
|
||||
persistent: false
|
||||
});
|
||||
|
||||
watcher.on('add', update);
|
||||
|
||||
@@ -66,7 +66,8 @@ create_templates();
|
||||
|
||||
if (dev) {
|
||||
const watcher = chokidar.watch('templates/**.html', {
|
||||
ignoreInitial: true
|
||||
ignoreInitial: true,
|
||||
persistent: false
|
||||
});
|
||||
|
||||
watcher.on('add', create_templates);
|
||||
|
||||
@@ -71,7 +71,8 @@ if (dev) {
|
||||
route_manager.onchange(create_app);
|
||||
|
||||
const watcher = chokidar.watch(`templates/main.js`, {
|
||||
ignoreInitial: true
|
||||
ignoreInitial: true,
|
||||
persistent: false
|
||||
});
|
||||
|
||||
watcher.on('add', create_app);
|
||||
|
||||
@@ -38,10 +38,6 @@ module.exports = function create_watcher() {
|
||||
);
|
||||
});
|
||||
|
||||
watcher = {
|
||||
ready: invalidate()
|
||||
};
|
||||
|
||||
function watch_compiler(type) {
|
||||
const compiler = compilers[type];
|
||||
|
||||
@@ -55,7 +51,7 @@ module.exports = function create_watcher() {
|
||||
deferreds[type].reject(err);
|
||||
});
|
||||
|
||||
compiler.watch({}, (err, stats) => {
|
||||
return compiler.watch({}, (err, stats) => {
|
||||
if (stats.hasErrors()) {
|
||||
deferreds[type].reject(stats.toJson().errors[0]);
|
||||
} else {
|
||||
@@ -64,8 +60,16 @@ module.exports = function create_watcher() {
|
||||
});
|
||||
}
|
||||
|
||||
watch_compiler('client');
|
||||
watch_compiler('server');
|
||||
watcher = {
|
||||
ready: invalidate(),
|
||||
client: watch_compiler('client'),
|
||||
server: watch_compiler('server'),
|
||||
|
||||
close: () => {
|
||||
watcher.client.close();
|
||||
watcher.server.close();
|
||||
}
|
||||
};
|
||||
|
||||
return watcher;
|
||||
};
|
||||
Reference in New Issue
Block a user