@nera-static/test-utils 1.0.2 → 1.1.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.1.0] - 2026-11-28
9
+
10
+ ### Added
11
+
12
+ - `nera(cwd, args, { root })` runs the CLI repo's own bin when `root` is the `@nera-static/nera` repo itself (its `package.json` names that package), before looking in `node_modules`, so the CLI's tests need no symlinked root to run the code under test. Any other `root` resolves as before.
13
+
8
14
  ## [1.0.2] - 2026-11-28
9
15
 
10
16
  ### Fixed
package/README.md CHANGED
@@ -209,7 +209,7 @@ These need `@nera-static/nera`.
209
209
 
210
210
  #### `nera(cwd, args, { root = cwd } = {})` → `Promise<{ code, stdout, stderr }>`
211
211
 
212
- Runs the installed `nera` CLI with `args` (`['build', '--check']`) in the existing absolute directory `cwd`, without colours (`NO_COLOR=1`, `FORCE_COLOR=0`). It never rejects on a non-zero exit: the exit code is part of the result. The CLI is the one installed for `root`, found from there upwards as Node resolves a package; pass your repo root when `cwd` has no `node_modules` of its own.
212
+ Runs the installed `nera` CLI with `args` (`['build', '--check']`) in the existing absolute directory `cwd`, without colours (`NO_COLOR=1`, `FORCE_COLOR=0`). It never rejects on a non-zero exit: the exit code is part of the result. The CLI is the one installed for `root`, found from there upwards as Node resolves a package; pass your repo root when `cwd` has no `node_modules` of its own. A `root` whose own `package.json` is `@nera-static/nera` (the CLI repo testing itself) runs that repo's `bin.nera` instead, so `nera(cwd, args, { root: repoRoot })` there runs the code under test.
213
213
 
214
214
  #### `scaffoldStarter(repoRoot, name, args = [])` → `Promise<string>`
215
215
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nera-static/test-utils",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Shared test helpers, test suites and the canonical vitest preset for Nera plugins, themes, starters and tools.",
5
5
  "type": "module",
6
6
  "exports": {
package/src/cli.js CHANGED
@@ -37,25 +37,56 @@ const UNCLEAN_LOG = /warn|⚠|❌|deprecat|Views folder not found/i
37
37
 
38
38
  const isDir = (dir) => typeof dir === 'string' && path.isAbsolute(dir) && fs.existsSync(dir) && fs.statSync(dir).isDirectory()
39
39
 
40
+ const CLI_PACKAGE = '@nera-static/nera'
41
+
42
+ /**
43
+ * The name in `dir`'s own `package.json`, or null when it has none or the
44
+ * file is missing or not JSON: only the CLI repo's identity is read here,
45
+ * and a site's broken manifest is its build's business, not this check's.
46
+ *
47
+ * @param {string} dir the dir whose `package.json` to read
48
+ * @returns {string | null}
49
+ */
50
+ function packageName(dir) {
51
+ try {
52
+ const { name } = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'))
53
+ return typeof name === 'string' ? name : null
54
+ } catch {
55
+ return null
56
+ }
57
+ }
58
+
40
59
  /**
41
- * The bin file of the `@nera-static/nera` installed for `root`: the first
42
- * `node_modules/@nera-static/nera` from `root` upwards, as Node resolves a
43
- * package, read without importing it.
60
+ * The absolute bin file the `@nera-static/nera` manifest at `manifest`
61
+ * names, with `hint` saying how to repair a manifest that names none.
62
+ *
63
+ * @param {string} manifest absolute path of the package's `package.json`
64
+ * @param {string} hint the repair the error names
65
+ * @returns {string}
66
+ */
67
+ function binOf(manifest, hint) {
68
+ const { bin } = JSON.parse(fs.readFileSync(manifest, 'utf-8'))
69
+ const file = typeof bin === 'string' ? bin : bin?.nera
70
+ if (typeof file !== 'string') throw new Error(`nera(): ${manifest} names no "nera" bin. ${hint}`)
71
+ return path.join(path.dirname(manifest), file)
72
+ }
73
+
74
+ /**
75
+ * The bin file of the `@nera-static/nera` for `root`: `root`'s own bin when
76
+ * `root` is the CLI repo itself (its `package.json` is `@nera-static/nera`),
77
+ * else the first `node_modules/@nera-static/nera` from `root` upwards, as
78
+ * Node resolves a package, read without importing it.
44
79
  *
45
80
  * @param {string} root the dir to resolve from
46
81
  * @returns {string} absolute path of the CLI's bin file
47
82
  */
48
83
  function resolveCli(root) {
84
+ if (packageName(root) === CLI_PACKAGE) {
85
+ return binOf(path.join(root, 'package.json'), 'Add it to the package\'s bin field: "bin": { "nera": "bin/nera.js" }')
86
+ }
49
87
  for (let dir = root; ; dir = path.dirname(dir)) {
50
88
  const manifest = path.join(dir, 'node_modules', '@nera-static', 'nera', 'package.json')
51
- if (fs.existsSync(manifest)) {
52
- const { bin } = JSON.parse(fs.readFileSync(manifest, 'utf-8'))
53
- const file = typeof bin === 'string' ? bin : bin?.nera
54
- if (typeof file !== 'string') {
55
- throw new Error(`nera(): ${manifest} names no "nera" bin. Reinstall it: npm install --save-dev @nera-static/nera`)
56
- }
57
- return path.join(path.dirname(manifest), file)
58
- }
89
+ if (fs.existsSync(manifest)) return binOf(manifest, 'Reinstall it: npm install --save-dev @nera-static/nera')
59
90
  if (path.dirname(dir) === dir) break
60
91
  }
61
92
  throw new Error(
@@ -71,6 +102,8 @@ function resolveCli(root) {
71
102
  * The CLI is the one installed for `root` (by default `cwd`), found from
72
103
  * there upwards as Node resolves a package. Pass the repo root when `cwd`
73
104
  * has no `node_modules` of its own, e.g. the temp dir `nera new` runs in.
105
+ * A `root` that is the `@nera-static/nera` repo itself runs its own bin,
106
+ * so the CLI's tests run the code under test.
74
107
  *
75
108
  * @param {string} cwd absolute dir to run in
76
109
  * @param {string[]} args CLI arguments, e.g. `['build', '--check']`