Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 2d75811

Browse files
committed
Handle umbrella projects when deciding if test file
1 parent de1fed8 commit 2d75811

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/init.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ const findElixirProjectPath = async (editorPath) => {
3131
const editorDir = dirname(editorPath);
3232
const mixexsPath = find(editorDir, 'mix.exs');
3333
if (mixexsPath !== null) {
34-
const pathArray = mixexsPath.split('/');
34+
const pathArray = mixexsPath.split(sep);
3535
if (pathArray.length > 3 && pathArray[pathArray.length - 3] === 'apps') {
3636
// Treat this as an umbrella app. This may be wrong -
3737
// If you happen to keep your code in a directory called 'apps'
3838
pathArray.splice((pathArray.length - 3), 3);
39-
const umbrellaProjectPath = pathArray.join('/');
39+
const umbrellaProjectPath = pathArray.join(sep);
4040

4141
// Safety check by looking for a `mix.exs` file in the same directory as
4242
// 'apps'. If it exists, then it's likely an umbrella project
@@ -68,11 +68,21 @@ const isMixProject = async (filePath) => {
6868
return existsSync(join(project, 'mix.exs'));
6969
};
7070

71+
const isUmbrellaProject = async (filePath) => {
72+
const project = await elixirProjectPath(filePath);
73+
return existsSync(join(project, 'apps'));
74+
}
75+
7176
const isTestFile = async (filePath) => {
7277
const project = await elixirProjectPath(filePath);
7378
const relativePath = relative(project, filePath);
74-
// Is the first directory of the relative path "test"?
75-
return relativePath.split(sep)[0] === 'test';
79+
if (isUmbrellaProject()) {
80+
// Is the structure "apps/app_name/test/..."
81+
return relativePath.split(sep)[2] === 'test';
82+
} else {
83+
// Is the structure "test/..."
84+
return relativePath.split(sep)[0] === 'test';
85+
}
7686
};
7787

7888
const isForcedElixirc = () => forceElixirc;

0 commit comments

Comments
 (0)