killing mutants

This commit is contained in:
Timo Hocker 2020-03-26 13:31:07 +01:00
parent 03f0104bca
commit c1fcde7d6f
23 changed files with 79 additions and 71 deletions

View File

@ -39,13 +39,13 @@ function get_handler ({ module_folder, file, opts, rethrow }) {
// eslint-disable-next-line global-require // eslint-disable-next-line global-require
const handler = require (path.join (process.cwd (), module_folder, file)); const handler = require (path.join (process.cwd (), module_folder, file));
return (req, res, next) => { return (req, res, next) => new Promise (
new Promise ((resolve) => resolve (handler (req, res, next, opts))) (resolve) => resolve (handler (req, res, next, opts))
.catch ((e) => { )
if (rethrow) .catch ((e) => {
throw e; if (rethrow)
}); throw e;
}; });
} }

View File

@ -30,7 +30,7 @@ const mock = {
} }
}; };
test ('detect requests on root', (t) => { test ('detect requests on root', async (t) => {
mock.registered = {}; mock.registered = {};
requestor (mock, './test_files/root'); requestor (mock, './test_files/root');
const keys = [ const keys = [
@ -42,9 +42,14 @@ test ('detect requests on root', (t) => {
]; ];
t.deepEqual (Object.keys (mock.registered), keys); t.deepEqual (Object.keys (mock.registered), keys);
const res = await Promise.all (
Object.values (mock.registered)
.map ((val) => val ())
);
t.is (res.filter ((val) => val === 'dummy').length, keys.length);
}); });
test ('detect requests on root.subfolder', (t) => { test ('detect requests on root.subfolder', async (t) => {
mock.registered = {}; mock.registered = {};
requestor (mock, './test_files/root.sub'); requestor (mock, './test_files/root.sub');
const keys = [ const keys = [
@ -56,9 +61,14 @@ test ('detect requests on root.subfolder', (t) => {
]; ];
t.deepEqual (Object.keys (mock.registered), keys); t.deepEqual (Object.keys (mock.registered), keys);
const res = await Promise.all (
Object.values (mock.registered)
.map ((val) => val ())
);
t.is (res.filter ((val) => val === 'dummy').length, keys.length);
}); });
test ('detect requests on subfolder', (t) => { test ('detect requests on subfolder', async (t) => {
mock.registered = {}; mock.registered = {};
requestor (mock, './test_files/sub'); requestor (mock, './test_files/sub');
const keys = [ const keys = [
@ -72,9 +82,14 @@ test ('detect requests on subfolder', (t) => {
]; ];
t.deepEqual (Object.keys (mock.registered), keys); t.deepEqual (Object.keys (mock.registered), keys);
const res = await Promise.all (
Object.values (mock.registered)
.map ((val) => val ())
);
t.is (res.filter ((val) => val === 'dummy').length, keys.length);
}); });
test ('build requests with subdirectory', (t) => { test ('build requests with subdirectory', async (t) => {
mock.registered = {}; mock.registered = {};
requestor (mock, './test_files/sub', { subdir: 'test' }); requestor (mock, './test_files/sub', { subdir: 'test' });
const keys = [ const keys = [
@ -88,4 +103,25 @@ test ('build requests with subdirectory', (t) => {
]; ];
t.deepEqual (Object.keys (mock.registered), keys); t.deepEqual (Object.keys (mock.registered), keys);
const res = await Promise.all (
Object.values (mock.registered)
.map ((val) => val ())
);
t.is (res.filter ((val) => val === 'dummy').length, keys.length);
});
test ('should rethrow', async (t) => {
mock.registered = {};
requestor (mock, './test_files/throw');
const [ func ] = Object.values (mock.registered);
await t.throwsAsync (func);
});
test ('should not rethrow', async (t) => {
mock.registered = {};
requestor (mock, './test_files/throw', { rethrow: false });
const [ func ] = Object.values (mock.registered);
await t.notThrowsAsync (func);
}); });

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -7,6 +7,4 @@
'use strict'; 'use strict';
module.exports = () => { module.exports = () => 'dummy';
// dummy endpoint: do nothing
};

View File

@ -0,0 +1,12 @@
/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Requestor which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, March 2020
*/
'use strict';
module.exports = () => {
throw new Error ('foo');
};