1 | import path from 'path'; |
||
2 | import { assert } from 'chai'; |
||
3 | import { entry } from './constants'; |
||
4 | |||
5 | export function load(relPath, clearCache) { |
||
6 | const absPath = path.resolve(entry, relPath); |
||
7 | |||
8 | if (clearCache) delete require.cache[require.resolve(absPath)]; |
||
9 | // eslint-disable-next-line security/detect-non-literal-require |
||
10 | const result = require(absPath); |
||
11 | |||
12 | if (clearCache) delete require.cache[require.resolve(absPath)]; |
||
13 | |||
14 | return result; |
||
15 | } |
||
16 | |||
17 | export function resolve(relPath) { |
||
18 | return require.resolve(path.join(entry, relPath)); |
||
19 | } |
||
20 | |||
21 | export async function ensureError(handler) { |
||
22 | try { |
||
23 | await handler(); |
||
24 | assert.fail('Expected to throw an error'); |
||
0 ignored issues
–
show
Best Practice
introduced
by
![]() |
|||
25 | } catch (error) { |
||
26 | if (error.name === 'AssertionError') throw error; |
||
27 | |||
28 | return error; |
||
29 | } |
||
30 | } |
||
31 |