aleclarson / testpass

The compass for your code
MIT License
0 stars 0 forks source link

Support redirecting requires in test files #19

Open aleclarson opened 6 years ago

aleclarson commented 6 years ago

For example, instead of using babel-register, I may want to import the pre-transpiled modules instead. The only problem is I would have to do ../../../../../lib/MyModule.js, which isn't pretty or easy to maintain.

Here's a good solution:

const {redirectImports} = require('testpass')

// The given function is called for every `require` call from a test file.
redirectImports((filename, parent) => {
  return filename.replace('/src/', '/lib/')
})

You would call redirectImports before findTests.