Skip to content

Commit

Permalink
use parent to define calleePath, per review
Browse files Browse the repository at this point in the history
  • Loading branch information
bumblehead committed Aug 19, 2022
1 parent e9327d1 commit ef706ea
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/esmock.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ import {
} from './esmockCache.js'

const esmock = async (modulePath, mockDefs, globalDefs, opt = {}, err) => {
const calleePath = (err || new Error).stack.split('\n')[2]
const calleePath = (opt.parent || (err || new Error).stack.split('\n')[2])
.replace(/^.*file:\/\//, '') // rm every before filepath
.replace(/:[\d]*:[\d]*.*$/, '') // rm line and row number
.replace(/^.*:/, '') // rm windows-style drive location
.replace(/.*at [^(]*\(/, '') // rm ' at TestContext.<anonymous> ('

if (opt.parent)
modulePath = fileURLToPath(new URL("../index.js", opt.parent))

if (!global.esmockloader)
throw new Error('process must be started with --loader=esmock')

Expand Down

0 comments on commit ef706ea

Please sign in to comment.