@testsmith/testblocks 0.7.0 → 0.8.0

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.
Files changed (2) hide show
  1. package/dist/cli/index.js +71 -2
  2. package/package.json +1 -1
package/dist/cli/index.js CHANGED
@@ -41,6 +41,32 @@ const glob_1 = require("glob");
41
41
  const executor_1 = require("./executor");
42
42
  const reporters_1 = require("./reporters");
43
43
  const startServer_1 = require("../server/startServer");
44
+ const plugins_1 = require("../server/plugins");
45
+ const globals_1 = require("../server/globals");
46
+ /**
47
+ * Get the package version from package.json
48
+ */
49
+ function getVersion() {
50
+ try {
51
+ // Try to find package.json relative to the compiled CLI
52
+ const possiblePaths = [
53
+ path.join(__dirname, '../../package.json'), // dist/cli -> package.json
54
+ path.join(__dirname, '../../../package.json'), // nested node_modules
55
+ ];
56
+ for (const pkgPath of possiblePaths) {
57
+ if (fs.existsSync(pkgPath)) {
58
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
59
+ if (pkg.name === '@testsmith/testblocks' && pkg.version) {
60
+ return pkg.version;
61
+ }
62
+ }
63
+ }
64
+ }
65
+ catch {
66
+ // Ignore errors
67
+ }
68
+ return '0.0.0';
69
+ }
44
70
  /**
45
71
  * Search up the directory tree for globals.json starting from the given directory
46
72
  */
@@ -56,11 +82,26 @@ function findGlobalsFile(startDir) {
56
82
  }
57
83
  return null;
58
84
  }
85
+ /**
86
+ * Search up the directory tree for a plugins directory starting from the given directory
87
+ */
88
+ function findPluginsDir(startDir) {
89
+ let currentDir = path.resolve(startDir);
90
+ const root = path.parse(currentDir).root;
91
+ while (currentDir !== root) {
92
+ const pluginsPath = path.join(currentDir, 'plugins');
93
+ if (fs.existsSync(pluginsPath) && fs.statSync(pluginsPath).isDirectory()) {
94
+ return pluginsPath;
95
+ }
96
+ currentDir = path.dirname(currentDir);
97
+ }
98
+ return null;
99
+ }
59
100
  const program = new commander_1.Command();
60
101
  program
61
102
  .name('testblocks')
62
103
  .description('CLI runner for TestBlocks visual test automation')
63
- .version('1.0.0');
104
+ .version(getVersion());
64
105
  program
65
106
  .command('run')
66
107
  .description('Run test files')
@@ -72,6 +113,7 @@ program
72
113
  .option('-b, --base-url <url>', 'Base URL for relative URLs')
73
114
  .option('-v, --var <vars...>', 'Variables in key=value format')
74
115
  .option('-g, --globals <path>', 'Path to globals.json file', './globals.json')
116
+ .option('--plugins-dir <dir>', 'Plugins directory (auto-discovered if not specified)')
75
117
  .option('--fail-fast', 'Stop on first test failure', false)
76
118
  .option('-p, --parallel <count>', 'Number of parallel workers', '1')
77
119
  .option('--filter <pattern>', 'Only run tests matching pattern')
@@ -112,6 +154,33 @@ program
112
154
  console.warn(`Warning: Could not load globals from ${globalsPath}: ${e.message}`);
113
155
  }
114
156
  }
157
+ // Load plugins - search up directory tree from first test file if not explicitly specified
158
+ let pluginsDir = options.pluginsDir ? path.resolve(options.pluginsDir) : null;
159
+ // If plugins dir not specified, auto-discover from test file location or globals location
160
+ if (!pluginsDir && files.length > 0) {
161
+ const testDir = path.dirname(files[0]);
162
+ pluginsDir = findPluginsDir(testDir);
163
+ }
164
+ // Also check next to globals.json if still not found
165
+ if (!pluginsDir && fs.existsSync(globalsPath)) {
166
+ const globalsDir = path.dirname(globalsPath);
167
+ const pluginsDirNextToGlobals = path.join(globalsDir, 'plugins');
168
+ if (fs.existsSync(pluginsDirNextToGlobals) && fs.statSync(pluginsDirNextToGlobals).isDirectory()) {
169
+ pluginsDir = pluginsDirNextToGlobals;
170
+ }
171
+ }
172
+ // Load plugins if directory found
173
+ if (pluginsDir && fs.existsSync(pluginsDir)) {
174
+ (0, plugins_1.setPluginsDirectory)(pluginsDir);
175
+ await (0, plugins_1.loadAllPlugins)();
176
+ (0, plugins_1.initializeServerPlugins)();
177
+ }
178
+ // Load snippets from the globals directory (snippets/ folder next to globals.json)
179
+ if (fs.existsSync(globalsPath)) {
180
+ const globalsDir = path.dirname(globalsPath);
181
+ (0, globals_1.setGlobalsDirectory)(globalsDir);
182
+ (0, globals_1.loadAllSnippets)();
183
+ }
115
184
  // Parse CLI variables (these override globals)
116
185
  const cliVariables = {};
117
186
  if (options.var) {
@@ -273,7 +342,7 @@ program
273
342
  'test:junit': 'testblocks run tests/**/*.testblocks.json -r junit -o reports',
274
343
  },
275
344
  devDependencies: {
276
- '@testsmith/testblocks': '^0.7.0',
345
+ '@testsmith/testblocks': '^0.8.0',
277
346
  },
278
347
  };
279
348
  fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testsmith/testblocks",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Visual test automation tool with Blockly - API and Playwright testing",
5
5
  "author": "Roy de Kleijn",
6
6
  "license": "MIT",