Skip to content

Commit

Permalink
feat: allow calling init from test plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
gabidobo committed Sep 28, 2022
1 parent e4057e7 commit e4b196b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,19 @@ const init = ({
return Promise.resolve();
}

const {name: callerModule} = getCurrentModuleInfo({
const {name: initCaller} = getCurrentModuleInfo({
allowURLs: false,
});
if (!['root', 'mocha>sandworm-mocha'].includes(callerModule)) {
logger.warn(`only root may call init (called from ${callerModule})`);
const initCallerModules = initCaller.split('>');
const rootCallerModule = initCallerModules[0];
const directCallerModule = initCallerModules.slice(-1)[0];

if (
initCaller !== 'root' &&
(rootCallerModule !== 'mocha' || directCallerModule !== 'sandworm-mocha') &&
(rootCallerModule !== 'jest-runner' || directCallerModule !== 'sandworm-jest')
) {
logger.warn(`only root may call init (called from ${initCaller})`);
return Promise.resolve();
}
if (typeof devModeOption !== 'boolean') {
Expand Down

0 comments on commit e4b196b

Please sign in to comment.