paralleldrive / riteway

Simple, readable, helpful unit tests.
MIT License
1.15k stars 35 forks source link

Riteway does not recognise absolute paths to imports #302

Closed dshenderson closed 3 years ago

dshenderson commented 3 years ago

I have the following in my Webpack config:

resolve: {
  modules: [
    path.resolve(__dirname, 'src'),
    'node_modules',
    path.resolve('node_modules')
  ]
}

However, when I run tests, it doesn't seem to recognise paths pointing to directories in src.

For example, if I have

import {method_to_test} from 'utils';

I get the following error:

Error: Cannot find module 'utils/method_to_test'

To get it to work, I seem to have to use a relative path:

import {method_to_test} from '../../utils';

Absolute paths in imported modules are also not properly resolved.

dshenderson commented 3 years ago

It's been 3 weeks since I posted this issue. Anyone have any thoughts? I'm trying to avoid relative path hell, but if this isn't resolved I will either have to use relative paths or use a different testing framework, neither of which is ideal. Thanks in advance for any help!

ericelliott commented 3 years ago

How are you invoking RITEWay? What does your test script look like? RITEWay doesn't do anything special with respect to module import resolution. You can literally invoke it like node my/test/folder/file.js and it will act just like any other JS script you run.

Does your test script even use your Webpack config? That might be your issue.

dshenderson commented 3 years ago

Thank you, and apologies.

Apologies because you're right, the issue wasn't with RITEWay.

And thank you, because your comment nudged me out of my mental rut.

The tests do not use the Webpack config, but I wasn't seeing that. I've resolved the problem by using babel-plugin-module-resolver.

Closing the ticket. Thanks!