Skip to content

Commit 9db3d97

Browse files
committed
Resolve correctly relative imports from tests
1 parent 473ccc1 commit 9db3d97

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

lib/transforms/import-declarations.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,23 @@ function transformer(file, api) {
1515
return;
1616
}
1717

18+
// determine the actual path that importPath points to
19+
// TODO: extract these resolutions into classic-file-info and test-file-info
1820
var relative = path_utils.isRelative(importPath);
1921
if (relative) {
20-
importPath = path_utils.makeAbsolute(appName + '/' + file.fileInfo.sourceRelativePath, importPath);
22+
var sourceRelativePath = file.fileInfo.sourceRelativePath;
23+
24+
if (sourceRelativePath.startsWith('tests/')) {
25+
importPath = path_utils.makeAbsolute(appName + '/app/' + sourceRelativePath, importPath);
26+
27+
// see if we stayed within tests
28+
var inTestsPrefix = appName + '/app/tests/';
29+
if (importPath.startsWith(inTestsPrefix)) {
30+
importPath = appName + '/tests/' + importPath.substring(inTestsPrefix.length);
31+
}
32+
} else {
33+
importPath = path_utils.makeAbsolute(appName + '/' + sourceRelativePath, importPath);
34+
}
2135
} else {
2236
// check if import path starts with appName and add /app
2337
if (importPath.startsWith(appName + '/') && !importPath.startsWith(appName + '/app/')) {

0 commit comments

Comments
 (0)