@vitronai/themis 0.1.0-beta.0 → 0.1.0-beta.2

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/config.js CHANGED
@@ -9,13 +9,18 @@ const DEFAULT_CONFIG = {
9
9
  reporter: 'next',
10
10
  environment: 'node',
11
11
  setupFiles: [],
12
- tsconfigPath: 'tsconfig.json'
12
+ tsconfigPath: 'tsconfig.json',
13
+ testIgnore: []
13
14
  };
14
15
 
15
16
  function loadConfig(cwd) {
16
17
  const configPath = path.join(cwd, 'themis.config.json');
17
18
  if (!fs.existsSync(configPath)) {
18
- return { ...DEFAULT_CONFIG, setupFiles: [] };
19
+ return {
20
+ ...DEFAULT_CONFIG,
21
+ setupFiles: [],
22
+ testIgnore: []
23
+ };
19
24
  }
20
25
 
21
26
  const raw = fs.readFileSync(configPath, 'utf8');
@@ -39,9 +44,22 @@ function normalizeConfig(config) {
39
44
  throw new Error('Invalid config tsconfigPath value: expected a string path or null.');
40
45
  }
41
46
 
47
+ if (!Array.isArray(config.testIgnore) || !config.testIgnore.every((entry) => typeof entry === 'string')) {
48
+ throw new Error('Invalid config testIgnore value: expected an array of regex strings.');
49
+ }
50
+
51
+ for (const pattern of config.testIgnore) {
52
+ try {
53
+ new RegExp(pattern);
54
+ } catch (error) {
55
+ throw new Error(`Invalid config testIgnore pattern "${pattern}": ${error.message}`);
56
+ }
57
+ }
58
+
42
59
  return {
43
60
  ...config,
44
- setupFiles: [...config.setupFiles]
61
+ setupFiles: [...config.setupFiles],
62
+ testIgnore: [...config.testIgnore]
45
63
  };
46
64
  }
47
65
 
package/src/discovery.js CHANGED
@@ -4,25 +4,30 @@ const path = require('path');
4
4
  function discoverTests(cwd, config) {
5
5
  const start = path.resolve(cwd, config.testDir);
6
6
  const regex = new RegExp(config.testRegex);
7
+ const ignored = compileIgnorePatterns(config.testIgnore);
7
8
  const files = [];
8
9
 
9
10
  if (!fs.existsSync(start)) {
10
11
  return files;
11
12
  }
12
13
 
13
- walk(start, regex, files);
14
+ walk(start, regex, ignored, files, cwd);
14
15
  return files.sort();
15
16
  }
16
17
 
17
- function walk(dir, regex, files) {
18
+ function walk(dir, regex, ignored, files, cwd) {
18
19
  const entries = fs.readdirSync(dir, { withFileTypes: true });
19
20
  for (const entry of entries) {
20
21
  if (entry.name === 'node_modules' || entry.name.startsWith('.')) {
21
22
  continue;
22
23
  }
23
24
  const fullPath = path.join(dir, entry.name);
25
+ const relativePath = normalizeRelativePath(cwd, fullPath);
26
+ if (shouldIgnore(relativePath, entry.isDirectory(), ignored)) {
27
+ continue;
28
+ }
24
29
  if (entry.isDirectory()) {
25
- walk(fullPath, regex, files);
30
+ walk(fullPath, regex, ignored, files, cwd);
26
31
  continue;
27
32
  }
28
33
  if (entry.isFile() && regex.test(entry.name)) {
@@ -31,4 +36,28 @@ function walk(dir, regex, files) {
31
36
  }
32
37
  }
33
38
 
39
+ function compileIgnorePatterns(patterns) {
40
+ if (!Array.isArray(patterns) || patterns.length === 0) {
41
+ return [];
42
+ }
43
+
44
+ return patterns.map((pattern) => new RegExp(pattern));
45
+ }
46
+
47
+ function normalizeRelativePath(cwd, fullPath) {
48
+ return path.relative(cwd, fullPath).split(path.sep).join('/');
49
+ }
50
+
51
+ function shouldIgnore(relativePath, isDirectory, ignored) {
52
+ if (!Array.isArray(ignored) || ignored.length === 0) {
53
+ return false;
54
+ }
55
+
56
+ const candidates = isDirectory
57
+ ? [relativePath, `${relativePath}/`]
58
+ : [relativePath];
59
+
60
+ return candidates.some((candidate) => ignored.some((pattern) => pattern.test(candidate)));
61
+ }
62
+
34
63
  module.exports = { discoverTests };
package/src/expect.js CHANGED
@@ -117,11 +117,29 @@ function createExpect(context = {}) {
117
117
  );
118
118
  }
119
119
  },
120
- toMatchSnapshot(snapshotName) {
121
- if (!context.snapshotState) {
122
- throw new Error('toMatchSnapshot() is only available inside the Themis runtime');
120
+ toHaveTextContent(expected) {
121
+ const node = assertDomNode(received, 'toHaveTextContent');
122
+ const actual = normalizeText(node.textContent);
123
+ const target = normalizeText(expected);
124
+ if (!actual.includes(target)) {
125
+ throw new Error(`Expected element text ${format(actual)} to contain ${format(target)}`);
126
+ }
127
+ },
128
+ toHaveAttribute(name, expectedValue) {
129
+ const node = assertDomNode(received, 'toHaveAttribute');
130
+ const actual = node.getAttribute(name);
131
+ if (actual === null) {
132
+ throw new Error(`Expected element to have attribute ${String(name)}`);
133
+ }
134
+ if (expectedValue !== undefined && actual !== String(expectedValue)) {
135
+ throw new Error(`Expected attribute ${String(name)} to be ${format(expectedValue)}, received ${format(actual)}`);
136
+ }
137
+ },
138
+ toBeInTheDocument() {
139
+ const node = assertDomNode(received, 'toBeInTheDocument');
140
+ if (!node.ownerDocument || !node.ownerDocument.documentElement.contains(node)) {
141
+ throw new Error('Expected element to be attached to the current document');
123
142
  }
124
- context.snapshotState.matchSnapshot(received, snapshotName);
125
143
  }
126
144
  };
127
145
  };
@@ -167,6 +185,17 @@ function format(value) {
167
185
  return util.inspect(value, { depth: 5, colors: false, maxArrayLength: 20 });
168
186
  }
169
187
 
188
+ function assertDomNode(received, matcherName) {
189
+ if (typeof Node === 'undefined' || !(received instanceof Node)) {
190
+ throw new Error(`${matcherName} expects a DOM node`);
191
+ }
192
+ return received;
193
+ }
194
+
195
+ function normalizeText(value) {
196
+ return String(value || '').replace(/\s+/g, ' ').trim();
197
+ }
198
+
170
199
  const expect = createExpect();
171
200
 
172
201
  module.exports = {