killing mutants
This commit is contained in:
parent
03f0104bca
commit
c1fcde7d6f
6
index.js
6
index.js
@ -39,13 +39,13 @@ function get_handler ({ module_folder, file, opts, rethrow }) {
|
||||
// eslint-disable-next-line global-require
|
||||
const handler = require (path.join (process.cwd (), module_folder, file));
|
||||
|
||||
return (req, res, next) => {
|
||||
new Promise ((resolve) => resolve (handler (req, res, next, opts)))
|
||||
return (req, res, next) => new Promise (
|
||||
(resolve) => resolve (handler (req, res, next, opts))
|
||||
)
|
||||
.catch ((e) => {
|
||||
if (rethrow)
|
||||
throw e;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
44
test/main.js
44
test/main.js
@ -30,7 +30,7 @@ const mock = {
|
||||
}
|
||||
};
|
||||
|
||||
test ('detect requests on root', (t) => {
|
||||
test ('detect requests on root', async (t) => {
|
||||
mock.registered = {};
|
||||
requestor (mock, './test_files/root');
|
||||
const keys = [
|
||||
@ -42,9 +42,14 @@ test ('detect requests on root', (t) => {
|
||||
];
|
||||
|
||||
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 = {};
|
||||
requestor (mock, './test_files/root.sub');
|
||||
const keys = [
|
||||
@ -56,9 +61,14 @@ test ('detect requests on root.subfolder', (t) => {
|
||||
];
|
||||
|
||||
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 = {};
|
||||
requestor (mock, './test_files/sub');
|
||||
const keys = [
|
||||
@ -72,9 +82,14 @@ test ('detect requests on subfolder', (t) => {
|
||||
];
|
||||
|
||||
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 = {};
|
||||
requestor (mock, './test_files/sub', { subdir: 'test' });
|
||||
const keys = [
|
||||
@ -88,4 +103,25 @@ test ('build requests with subdirectory', (t) => {
|
||||
];
|
||||
|
||||
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);
|
||||
});
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
@ -7,6 +7,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
||||
module.exports = () => 'dummy';
|
||||
|
12
test_files/throw/all-root.js
Normal file
12
test_files/throw/all-root.js
Normal 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');
|
||||
};
|
Reference in New Issue
Block a user