xolvio / qualityfaster

An example project showing how to create robust and maintainable acceptance tests
262 stars 58 forks source link

Absolute include paths do not work #58

Closed danimbrogno closed 8 years ago

danimbrogno commented 8 years ago

Hi! I've been trying out this project structure but I've run into a snag. It seems like wallaby is not able to find modules that are included via an absolute path, although this is supported in meteor.

import Hello from '/imports/test'; Error: Cannot find module "/imports/test.js"

using a relative path works fine:

import Hello from '../../test.js';

Do you think it would be possible to get this working? If you point me in the right direction I could give it a shot.

I've published a fork that shows the issue: https://github.com/danimbrogno/automated-testing-best-practices

See error in /imports/ui/components/inctest.js

damonmaria commented 8 years ago

You will need to include a babel plugin in your .babelrc to get root imports working for tools that are not Meteor. babel-root-slash-import provides this but unfortunately it thinks it is inside Meteor when run by the wallaby.js script from this repo. There might be a solution but I haven't looked too far into this.

danimbrogno commented 8 years ago

Thanks @damonmaria, I looked into this a bit more and was able to figure it out. For anyone else looking to enable root imports in their wallaby config. I accomplished this with

npm install babel-project-relative-import --saveDev

then I opened up wallaby_client.js and passed in a custom webpack config.

var babelCompiler = wallaby.compilers.babel({ "presets": ["es2015", "react"], "plugins": [ ["babel-project-relative-import",{ "sourceDir": "src", "importPathPrefix":"/" }] ] } );

Initially I tried to do this with a .babelrc file in root, but the plugin settings don't seem to get picked up when wallaby reads the file, so I recommend you pass your config in via wallaby.compilers.babel();

damonmaria commented 8 years ago

Strange. @danimbrogno's described setup works for me in Wallaby (wallaby_server) but not when I run it in Meteor. I get strange paths like: Cannot find module './../../../Users/damon/development/mindhive/inspector-gadget/mobile/imports/universal/api/withTheme

danimbrogno commented 8 years ago

@damonmaria since meteor supports absolute import resolution out of the box, I would configure it so that you don't use the plugin at all in Meteors build process. This seems to work if you just don't place a .babelrc file inside the "src" directory.

The problem I'm having now is that includes from node_modules installed inside the src directory are not working. I need to install them again the node_modules folder in the project root, which seems verbose and not very DRY.

e.g. import camelcase from 'camelcase'; only works in both the meteor and wallaby build process if it's been installed in root and in src directory.

Gonna look into this now.