@scalvert/bin-tester 1.0.0 → 2.1.1

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/README.md CHANGED
@@ -93,7 +93,6 @@ describe('Some tests', () => {
93
93
  * [new BinTesterProject(name, version, cb)](#new_BinTesterProject_new)
94
94
  * [.gitInit()](#BinTesterProject+gitInit) ⇒ <code>\*</code>
95
95
  * [.chdir()](#BinTesterProject+chdir)
96
- * [.writeDirJSON(dirJSON)](#BinTesterProject+writeDirJSON) ⇒ <code>\*</code>
97
96
  * [.dispose()](#BinTesterProject+dispose) ⇒ <code>void</code>
98
97
 
99
98
  <a name="new_BinTesterProject_new"></a>
@@ -121,18 +120,6 @@ describe('Some tests', () => {
121
120
  <p>Changes a directory from inside the project.</p>
122
121
 
123
122
  **Kind**: instance method of [<code>BinTesterProject</code>](#BinTesterProject)
124
- <a name="BinTesterProject+writeDirJSON"></a>
125
-
126
- ### binTesterProject.writeDirJSON(dirJSON) ⇒ <code>\*</code>
127
- <p>Writes a directory struture in the project directory.</p>
128
-
129
- **Kind**: instance method of [<code>BinTesterProject</code>](#BinTesterProject)
130
- **Returns**: <code>\*</code> - <p>{Promise<void>}</p>
131
-
132
- | Param | Type | Description |
133
- | --- | --- | --- |
134
- | dirJSON | <code>fixturify.DirJSON</code> | <p>A JSON object representing the directory structure to create.</p> |
135
-
136
123
  <a name="BinTesterProject+dispose"></a>
137
124
 
138
125
  ### binTesterProject.dispose() ⇒ <code>void</code>
package/dist/index.cjs CHANGED
@@ -18,27 +18,20 @@ var __spreadValues = (a, b) => {
18
18
  }
19
19
  return a;
20
20
  };
21
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
22
21
  var __export = (target, all) => {
23
22
  for (var name in all)
24
23
  __defProp(target, name, { get: all[name], enumerable: true });
25
24
  };
26
- var __reExport = (target, module2, copyDefault, desc) => {
27
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
28
- for (let key of __getOwnPropNames(module2))
29
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
30
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
25
+ var __copyProps = (to, from, except, desc) => {
26
+ if (from && typeof from === "object" || typeof from === "function") {
27
+ for (let key of __getOwnPropNames(from))
28
+ if (!__hasOwnProp.call(to, key) && key !== except)
29
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
30
  }
32
- return target;
31
+ return to;
33
32
  };
34
- var __toESM = (module2, isNodeMode) => {
35
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
36
- };
37
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
38
- return (module2, temp) => {
39
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
40
- };
41
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
35
 
43
36
  // src/index.ts
44
37
  var src_exports = {};
@@ -46,6 +39,7 @@ __export(src_exports, {
46
39
  BinTesterProject: () => BinTesterProject,
47
40
  createBinTester: () => createBinTester
48
41
  });
42
+ module.exports = __toCommonJS(src_exports);
49
43
 
50
44
  // src/create-bin-tester.ts
51
45
  var import_execa2 = __toESM(require("execa"), 1);
@@ -53,7 +47,6 @@ var import_execa2 = __toESM(require("execa"), 1);
53
47
  // src/project.ts
54
48
  var import_execa = __toESM(require("execa"), 1);
55
49
  var import_fixturify_project = require("fixturify-project");
56
- var import_deepmerge = __toESM(require("deepmerge"), 1);
57
50
  var ROOT = process.cwd();
58
51
  var BinTesterProject = class extends import_fixturify_project.Project {
59
52
  constructor(name = "fake-project", version, cb) {
@@ -73,10 +66,6 @@ var BinTesterProject = class extends import_fixturify_project.Project {
73
66
  await this.write();
74
67
  process.chdir(this.baseDir);
75
68
  }
76
- writeDirJSON(dirJSON) {
77
- this.files = (0, import_deepmerge.default)(this.files, dirJSON);
78
- return this.write();
79
- }
80
69
  dispose() {
81
70
  if (this._dirChanged) {
82
71
  process.chdir(ROOT);
@@ -87,8 +76,7 @@ var BinTesterProject = class extends import_fixturify_project.Project {
87
76
 
88
77
  // src/create-bin-tester.ts
89
78
  var DEFAULT_BIN_TESTER_OPTIONS = {
90
- staticArgs: [],
91
- projectConstructor: BinTesterProject
79
+ staticArgs: []
92
80
  };
93
81
  function parseArgs(args) {
94
82
  if (args.length > 0 && typeof args[args.length - 1] === "object") {
@@ -109,7 +97,8 @@ function createBinTester(options) {
109
97
  const mergedOptions = __spreadValues(__spreadValues({}, DEFAULT_BIN_TESTER_OPTIONS), options);
110
98
  function runBin(...args) {
111
99
  const mergedRunOptions = parseArgs(args);
112
- return (0, import_execa2.default)(process.execPath, [mergedOptions.binPath, ...mergedOptions.staticArgs, ...mergedRunOptions.args], __spreadValues({
100
+ const binPath = typeof mergedOptions.binPath === "function" ? mergedOptions.binPath(project) : mergedOptions.binPath;
101
+ return (0, import_execa2.default)(process.execPath, [binPath, ...mergedOptions.staticArgs, ...mergedRunOptions.args], __spreadValues({
113
102
  reject: false,
114
103
  cwd: project.baseDir
115
104
  }, mergedRunOptions.execaOptions));
@@ -135,7 +124,6 @@ function createBinTester(options) {
135
124
  setupTmpDir
136
125
  };
137
126
  }
138
- module.exports = __toCommonJS(src_exports);
139
127
  // Annotate the CommonJS export names for ESM import in node:
140
128
  0 && (module.exports = {
141
129
  BinTesterProject,
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import execa from 'execa';
2
- import fixturify from 'fixturify';
3
2
  import { Project } from 'fixturify-project';
4
3
 
5
4
  declare class BinTesterProject extends Project {
@@ -22,13 +21,6 @@ declare class BinTesterProject extends Project {
22
21
  * Changes a directory from inside the project.
23
22
  */
24
23
  chdir(): Promise<void>;
25
- /**
26
- * Writes a directory struture in the project directory.
27
- *
28
- * @param {fixturify.DirJSON} dirJSON - A JSON object representing the directory structure to create.
29
- * @returns {*} {Promise<void>}
30
- */
31
- writeDirJSON(dirJSON: fixturify.DirJSON): Promise<void>;
32
24
  /**
33
25
  * Correctly disposes of the project, observing when the directory has been changed.
34
26
  *
@@ -41,7 +33,7 @@ interface BinTesterOptions<TProject> {
41
33
  /**
42
34
  * The absolute path to the bin to invoke
43
35
  */
44
- binPath: string;
36
+ binPath: string | (<TProject extends BinTesterProject>(project: TProject) => string);
45
37
  /**
46
38
  * An array of static arguments that will be used every time when running the bin
47
39
  */
@@ -60,13 +52,29 @@ interface RunBin {
60
52
  */
61
53
  (): execa.ExecaChildProcess<string>;
62
54
  /**
63
- * A runBin implementation that takes varargs.
55
+ * A runBin implementation that takes string varargs.
56
+ *
57
+ * @param {...RunBinArgs} args
58
+ * @returns {*} {execa.ExecaChildProcess<string>}
59
+ * @memberof RunBin
60
+ */
61
+ (...args: [...binArgs: string[]]): execa.ExecaChildProcess<string>;
62
+ /**
63
+ * A runBin implementation that takes an execa.Options<string> object.
64
+ *
65
+ * @param {...RunBinArgs} args
66
+ * @returns {*} {execa.ExecaChildProcess<string>}
67
+ * @memberof RunBin
68
+ */
69
+ (...args: [execaOptions: execa.Options<string>]): execa.ExecaChildProcess<string>;
70
+ /**
71
+ * A runBin implementation that takes string or an execa.Options<string> object varargs.
64
72
  *
65
73
  * @param {...RunBinArgs} args
66
74
  * @returns {*} {execa.ExecaChildProcess<string>}
67
75
  * @memberof RunBin
68
76
  */
69
- (...args: RunBinArgs): execa.ExecaChildProcess<string>;
77
+ (...args: [...binArgs: string[], execaOptions: execa.Options<string>]): execa.ExecaChildProcess<string>;
70
78
  }
71
79
  interface CreateBinTesterResult<TProject extends BinTesterProject> {
72
80
  /**
@@ -86,7 +94,6 @@ interface CreateBinTesterResult<TProject extends BinTesterProject> {
86
94
  */
87
95
  teardownProject: () => void;
88
96
  }
89
- declare type RunBinArgs = [...binArgs: string[], execaOptions: execa.Options<string>];
90
97
  /**
91
98
  * Creates the bin tester API functions to use within tests.
92
99
  *
package/dist/index.js CHANGED
@@ -21,7 +21,6 @@ import execa2 from "execa";
21
21
  // src/project.ts
22
22
  import execa from "execa";
23
23
  import { Project } from "fixturify-project";
24
- import deepmerge from "deepmerge";
25
24
  var ROOT = process.cwd();
26
25
  var BinTesterProject = class extends Project {
27
26
  constructor(name = "fake-project", version, cb) {
@@ -41,10 +40,6 @@ var BinTesterProject = class extends Project {
41
40
  await this.write();
42
41
  process.chdir(this.baseDir);
43
42
  }
44
- writeDirJSON(dirJSON) {
45
- this.files = deepmerge(this.files, dirJSON);
46
- return this.write();
47
- }
48
43
  dispose() {
49
44
  if (this._dirChanged) {
50
45
  process.chdir(ROOT);
@@ -55,8 +50,7 @@ var BinTesterProject = class extends Project {
55
50
 
56
51
  // src/create-bin-tester.ts
57
52
  var DEFAULT_BIN_TESTER_OPTIONS = {
58
- staticArgs: [],
59
- projectConstructor: BinTesterProject
53
+ staticArgs: []
60
54
  };
61
55
  function parseArgs(args) {
62
56
  if (args.length > 0 && typeof args[args.length - 1] === "object") {
@@ -77,7 +71,8 @@ function createBinTester(options) {
77
71
  const mergedOptions = __spreadValues(__spreadValues({}, DEFAULT_BIN_TESTER_OPTIONS), options);
78
72
  function runBin(...args) {
79
73
  const mergedRunOptions = parseArgs(args);
80
- return execa2(process.execPath, [mergedOptions.binPath, ...mergedOptions.staticArgs, ...mergedRunOptions.args], __spreadValues({
74
+ const binPath = typeof mergedOptions.binPath === "function" ? mergedOptions.binPath(project) : mergedOptions.binPath;
75
+ return execa2(process.execPath, [binPath, ...mergedOptions.staticArgs, ...mergedRunOptions.args], __spreadValues({
81
76
  reject: false,
82
77
  cwd: project.baseDir
83
78
  }, mergedRunOptions.execaOptions));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalvert/bin-tester",
3
- "version": "1.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "A test harness to invoke a CLI in a tmp directory",
5
5
  "keywords": [
6
6
  "cli",
@@ -31,7 +31,8 @@
31
31
  "docs:generate": "readme-api-generator ./src --ts",
32
32
  "lint": "eslint .",
33
33
  "prepublishOnly": "npm run build",
34
- "test": "npm run lint && vitest run",
34
+ "test": "npm run lint && npm run test:vitest",
35
+ "test:vitest": "vitest run",
35
36
  "test:watch": "vitest",
36
37
  "watch": "npm run build -- --watch src"
37
38
  },
@@ -39,9 +40,8 @@
39
40
  "dist"
40
41
  ],
41
42
  "dependencies": {
42
- "deepmerge": "^4.2.2",
43
43
  "execa": "^5.1.1",
44
- "fixturify-project": "^4.1.0"
44
+ "fixturify-project": "^5.0.2"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@babel/plugin-proposal-class-properties": "^7.16.7",
@@ -49,7 +49,7 @@
49
49
  "@babel/plugin-transform-typescript": "^7.16.8",
50
50
  "@babel/preset-env": "^7.16.11",
51
51
  "@babel/preset-typescript": "^7.16.7",
52
- "@scalvert/readme-api-generator": "^0.2.0",
52
+ "@scalvert/readme-api-generator": "^0.2.4",
53
53
  "@typescript-eslint/eslint-plugin": "^5.14.0",
54
54
  "@typescript-eslint/parser": "^5.14.0",
55
55
  "eslint": "^8.10.0",
@@ -66,10 +66,10 @@
66
66
  "type-fest": "^2.12.0",
67
67
  "typescript": "^4.6.2",
68
68
  "vite": "^2.8.6",
69
- "vitest": "^0.6.0"
69
+ "vitest": "^0.9.3"
70
70
  },
71
71
  "engines": {
72
- "node": ">=14"
72
+ "node": "^12.22.0 || >=14"
73
73
  },
74
74
  "publishConfig": {
75
75
  "registry": "https://registry.npmjs.org",