@vitronai/themis 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/discovery.js CHANGED
@@ -2,17 +2,18 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
 
4
4
  function discoverTests(cwd, config) {
5
- const start = path.resolve(cwd, config.testDir);
6
5
  const regex = new RegExp(config.testRegex);
7
6
  const ignored = compileIgnorePatterns(config.testIgnore);
8
- const files = [];
7
+ const files = new Set();
8
+ const searchRoots = resolveSearchRoots(cwd, config);
9
9
 
10
- if (!fs.existsSync(start)) {
11
- return files;
10
+ for (const start of searchRoots) {
11
+ if (!fs.existsSync(start)) {
12
+ continue;
13
+ }
14
+ walk(start, regex, ignored, files, cwd);
12
15
  }
13
-
14
- walk(start, regex, ignored, files, cwd);
15
- return files.sort();
16
+ return [...files].sort();
16
17
  }
17
18
 
18
19
  function walk(dir, regex, ignored, files, cwd) {
@@ -31,11 +32,20 @@ function walk(dir, regex, ignored, files, cwd) {
31
32
  continue;
32
33
  }
33
34
  if (entry.isFile() && regex.test(entry.name)) {
34
- files.push(fullPath);
35
+ files.add(fullPath);
35
36
  }
36
37
  }
37
38
  }
38
39
 
40
+ function resolveSearchRoots(cwd, config) {
41
+ const candidates = [config.testDir, config.generatedTestsDir]
42
+ .map((entry) => String(entry || '').trim())
43
+ .filter(Boolean)
44
+ .map((entry) => path.resolve(cwd, entry));
45
+
46
+ return [...new Set(candidates)];
47
+ }
48
+
39
49
  function compileIgnorePatterns(patterns) {
40
50
  if (!Array.isArray(patterns) || patterns.length === 0) {
41
51
  return [];