@bsb/tests 9.5.6 → 9.5.8

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/bin/bsb-tests.cjs +40 -13
  2. package/package.json +2 -2
package/bin/bsb-tests.cjs CHANGED
@@ -47,6 +47,18 @@ const findFiles = (dir, filename, results = []) => {
47
47
 
48
48
  const readJson = (filePath) => JSON.parse(fs.readFileSync(filePath, "utf8"));
49
49
 
50
+ const resolvePackageBin = (packageName, binName) => {
51
+ const packageJsonPath = require.resolve(`${packageName}/package.json`);
52
+ const packageJson = readJson(packageJsonPath);
53
+ const binPath = typeof packageJson.bin === "string"
54
+ ? packageJson.bin
55
+ : packageJson.bin?.[binName];
56
+ if (!binPath) {
57
+ throw new Error(`Package ${packageName} does not declare bin ${binName}`);
58
+ }
59
+ return path.resolve(path.dirname(packageJsonPath), binPath);
60
+ };
61
+
50
62
  const resolvePluginModule = (pluginRoot, pluginPath, useTs) => {
51
63
  const base = path.resolve(pluginRoot, pluginPath || "");
52
64
  if (useTs) {
@@ -60,8 +72,22 @@ const resolvePluginModule = (pluginRoot, pluginPath, useTs) => {
60
72
  return path.join(swapped, "index.js");
61
73
  };
62
74
 
75
+ const hasBuiltPluginModule = (pluginRoot, pluginPath) => {
76
+ return fs.existsSync(resolvePluginModule(pluginRoot, pluginPath, false));
77
+ };
78
+
63
79
  const resolveLocalBaseEntry = (repoRoot, useTs) => {
64
- const baseRoot = path.join(repoRoot, "nodejs");
80
+ const nestedBaseRoot = path.join(repoRoot, "nodejs");
81
+ let baseRoot = null;
82
+ if (fs.existsSync(path.join(nestedBaseRoot, "package.json"))) {
83
+ baseRoot = nestedBaseRoot;
84
+ } else {
85
+ const packageJsonPath = path.join(repoRoot, "package.json");
86
+ if (fs.existsSync(packageJsonPath) && readJson(packageJsonPath).name === "@bsb/base") {
87
+ baseRoot = repoRoot;
88
+ }
89
+ }
90
+ if (!baseRoot) return null;
65
91
  const entryTs = path.join(baseRoot, "src", "index.ts");
66
92
  const entryJs = path.join(baseRoot, "lib", "index.js");
67
93
  if (useTs && fs.existsSync(entryTs)) return entryTs;
@@ -157,21 +183,20 @@ if (filtered.length === 0) {
157
183
  }
158
184
 
159
185
  const repoRoot = cwd;
160
- const mochaBin = require.resolve("mocha/bin/mocha.mjs");
161
- const nycBin = require.resolve("nyc/bin/nyc.js");
162
- const tsNodeRegister = require.resolve("ts-node/register");
163
- const setupHook = path.join(__dirname, "..", "src", "runner", "setup.ts");
164
- const pluginEventsRunner = path.join(__dirname, "..", "src", "runner", "plugin-events.ts");
165
- const pluginObservableRunner = path.join(__dirname, "..", "src", "runner", "plugin-observable.ts");
166
- const pluginCustomRunner = path.join(__dirname, "..", "src", "runner", "plugin-custom.ts");
167
- const eventsDefaultSpec = path.join(__dirname, "..", "src", "plugins", "events-default", "index.ts");
168
- const loggingDefaultSpec = path.join(__dirname, "..", "src", "plugins", "logging-default", "index.ts");
169
- const configDefaultSpec = path.join(__dirname, "..", "src", "plugins", "config-default", "index.ts");
170
- const observableDefaultSpec = path.join(__dirname, "..", "src", "plugins", "observable-default", "index.ts");
186
+ const mochaBin = resolvePackageBin("mocha", "mocha");
187
+ const setupHook = path.join(__dirname, "..", "lib", "runner", "setup.js");
188
+ const pluginEventsRunner = path.join(__dirname, "..", "lib", "runner", "plugin-events.js");
189
+ const pluginObservableRunner = path.join(__dirname, "..", "lib", "runner", "plugin-observable.js");
190
+ const pluginCustomRunner = path.join(__dirname, "..", "lib", "runner", "plugin-custom.js");
191
+ const eventsDefaultSpec = path.join(__dirname, "..", "lib", "plugins", "events-default", "index.js");
192
+ const loggingDefaultSpec = path.join(__dirname, "..", "lib", "plugins", "logging-default", "index.js");
193
+ const configDefaultSpec = path.join(__dirname, "..", "lib", "plugins", "config-default", "index.js");
194
+ const observableDefaultSpec = path.join(__dirname, "..", "lib", "plugins", "observable-default", "index.js");
171
195
 
172
196
  const runMocha = (env, spec, useTs, coverage, coverageInclude) => {
173
197
  const mochaArgs = [];
174
198
  if (useTs) {
199
+ const tsNodeRegister = require.resolve("ts-node/register");
175
200
  mochaArgs.push("--require", tsNodeRegister);
176
201
  }
177
202
  mochaArgs.push("--require", setupHook, spec);
@@ -184,6 +209,7 @@ const runMocha = (env, spec, useTs, coverage, coverageInclude) => {
184
209
  return result.status || 0;
185
210
  }
186
211
 
212
+ const nycBin = require.resolve("nyc/bin/nyc.js");
187
213
  const nycArgs = [
188
214
  "--all",
189
215
  "--check-coverage",
@@ -226,7 +252,7 @@ for (const plugin of filtered) {
226
252
  continue;
227
253
  }
228
254
 
229
- const useTs = forceTs || (!forceJs && fs.existsSync(path.join(plugin.pluginRoot, "src")));
255
+ const useTs = forceTs || (!forceJs && !hasBuiltPluginModule(plugin.pluginRoot, plugin.pluginPath) && fs.existsSync(path.join(plugin.pluginRoot, "src")));
230
256
  const pluginModule = resolvePluginModule(plugin.pluginRoot, plugin.pluginPath, useTs);
231
257
  if (!fs.existsSync(pluginModule)) {
232
258
  console.error("Plugin module not found:", pluginModule);
@@ -257,6 +283,7 @@ for (const plugin of filtered) {
257
283
  const ext = path.extname(resolved).toLowerCase();
258
284
  let result;
259
285
  if (ext === ".ts") {
286
+ const tsNodeRegister = require.resolve("ts-node/register");
260
287
  result = spawnSync(process.execPath, ["-r", tsNodeRegister, resolved], {
261
288
  stdio: "inherit",
262
289
  env: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsb/tests",
3
- "version": "9.5.6",
3
+ "version": "9.5.8",
4
4
  "description": "Shared test suites for BSB Node.js core and plugins",
5
5
  "license": "(AGPL-3.0-only OR Commercial)",
6
6
  "author": {
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@bsb/base": "^9.0.0",
32
- "mocha": "^12.0.0-beta-9.6",
32
+ "mocha": "^11.7.6",
33
33
  "nyc": "^17.1.0",
34
34
  "ts-node": "^10.9.2"
35
35
  },