Skip to content

createRequire support & a way to access the mocked require #265

Open
@PaperStrike

Description

@PaperStrike

The package I want to mock uses createRequire to require, which proxyquire doesn't proxy yet. To workaround, I tried:

proxyquire('./example', {
  module: {
    createRequire: (filename) => Object.assign((id) => require(id), {
      // ...some other stuff like `resolve`
    }),
    '@global': true,
  },
  // ... stubs I use
});

But then I found the require above can't be the mocked one. I wonder if you can support createRequire and give us a way to access the mocked require (so that we can mock createRequire to return a require with our own properties).

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions