@scalvert/bin-tester 0.2.0 → 2.0.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/README.md CHANGED
@@ -47,15 +47,15 @@ describe('Some tests', () => {
47
47
  });
48
48
 
49
49
  // Run the bin and do something with the result
50
- test('a test', () => {
50
+ test('a test', async () => {
51
51
  const result = await runBin();
52
52
 
53
53
  expect(result.stdout).toBe('Did some stuff');
54
54
  });
55
55
 
56
- test('another test', () => {
56
+ test('another test', async () => {
57
57
  // Write a file with contents to the tmp directory
58
- await project.writeJSON({
58
+ await project.writeDirJSON({
59
59
  'some/file.txt': 'some content',
60
60
  });
61
61
 
@@ -69,31 +69,111 @@ describe('Some tests', () => {
69
69
 
70
70
  ## API
71
71
 
72
- ```ts
73
- class BinTesterProject extends Project {
74
- private _dirChanged;
75
- constructor(name: string, version?: string, cb?: (project: Project) => void);
76
- gitInit(): execa.ExecaChildProcess<string>;
77
- chdir(): void;
78
- dispose(): void;
79
- }
80
-
81
- interface BinTesterOptions {
82
- binPath: string;
83
- projectConstructor?: any;
84
- }
85
-
86
- interface RunOptions {
87
- args?: string[];
88
- execaOptions?: execa.Options<string>;
89
- }
90
-
91
- interface createBinTesterResult<TProject extends BinTesterProject> {
92
- runBin: (runOptions?: RunOptions) => execa.ExecaChildProcess<string>;
93
- setupProject: () => Promise<TProject>;
94
- setupTmpDir: () => Promise<string>;
95
- teardownProject: () => void;
96
- }
97
-
98
- function createBinTester<TProject extends BinTesterProject>(options: BinTesterOptions): createBinTesterResult<TProject>;
99
- ```
72
+ <!--DOCS_START-->
73
+ ## Classes
74
+
75
+ <dl>
76
+ <dt><a href="#BinTesterProject">BinTesterProject</a></dt>
77
+ <dd></dd>
78
+ </dl>
79
+
80
+ ## Functions
81
+
82
+ <dl>
83
+ <dt><a href="#createBinTester">createBinTester(options)</a> ⇒ <code>CreateBinTesterResult.&lt;TProject&gt;</code></dt>
84
+ <dd><p>Creates the bin tester API functions to use within tests.</p></dd>
85
+ </dl>
86
+
87
+ <a name="BinTesterProject"></a>
88
+
89
+ ## BinTesterProject
90
+ **Kind**: global class
91
+
92
+ * [BinTesterProject](#BinTesterProject)
93
+ * [new BinTesterProject(name, version, cb)](#new_BinTesterProject_new)
94
+ * [.gitInit()](#BinTesterProject+gitInit) <code>\*</code>
95
+ * [.chdir()](#BinTesterProject+chdir)
96
+ * [.dispose()](#BinTesterProject+dispose) ⇒ <code>void</code>
97
+
98
+ <a name="new_BinTesterProject_new"></a>
99
+
100
+ ### new BinTesterProject(name, version, cb)
101
+ <p>Constructs an instance of a BinTesterProject.</p>
102
+
103
+
104
+ | Param | Type | Default | Description |
105
+ | --- | --- | --- | --- |
106
+ | name | <code>string</code> | <code>&quot;fake-project&quot;</code> | <p>The name of the project. Used within the package.json as the name property.</p> |
107
+ | version | <code>string</code> | | <p>The version of the project. Used within the package.json as the version property.</p> |
108
+ | cb | <code>function</code> | | <p>An optional callback for additional setup steps after the project is constructed.</p> |
109
+
110
+ <a name="BinTesterProject+gitInit"></a>
111
+
112
+ ### binTesterProject.gitInit() ⇒ <code>\*</code>
113
+ <p>Runs <code>git init</code> inside a project.</p>
114
+
115
+ **Kind**: instance method of [<code>BinTesterProject</code>](#BinTesterProject)
116
+ **Returns**: <code>\*</code> - <p>{execa.ExecaChildProcess<string>}</p>
117
+ <a name="BinTesterProject+chdir"></a>
118
+
119
+ ### binTesterProject.chdir()
120
+ <p>Changes a directory from inside the project.</p>
121
+
122
+ **Kind**: instance method of [<code>BinTesterProject</code>](#BinTesterProject)
123
+ <a name="BinTesterProject+dispose"></a>
124
+
125
+ ### binTesterProject.dispose() ⇒ <code>void</code>
126
+ <p>Correctly disposes of the project, observing when the directory has been changed.</p>
127
+
128
+ **Kind**: instance method of [<code>BinTesterProject</code>](#BinTesterProject)
129
+ <a name="createBinTester"></a>
130
+
131
+ ## createBinTester(options) ⇒ <code>CreateBinTesterResult.&lt;TProject&gt;</code>
132
+ <p>Creates the bin tester API functions to use within tests.</p>
133
+
134
+ **Kind**: global function
135
+ **Returns**: <code>CreateBinTesterResult.&lt;TProject&gt;</code> - <ul>
136
+ <li>A project instance.</li>
137
+ </ul>
138
+
139
+ | Param | Type | Description |
140
+ | --- | --- | --- |
141
+ | options | <code>BinTesterOptions.&lt;TProject&gt;</code> | <p>An object of bin tester options</p> |
142
+
143
+
144
+ * [createBinTester(options)](#createBinTester) ⇒ <code>CreateBinTesterResult.&lt;TProject&gt;</code>
145
+ * [~runBin(...args)](#createBinTester..runBin) ⇒ <code>execa.ExecaChildProcess.&lt;string&gt;</code>
146
+ * [~setupProject()](#createBinTester..setupProject)
147
+ * [~setupTmpDir()](#createBinTester..setupTmpDir)
148
+ * [~teardownProject()](#createBinTester..teardownProject)
149
+
150
+ <a name="createBinTester..runBin"></a>
151
+
152
+ ### createBinTester~runBin(...args) ⇒ <code>execa.ExecaChildProcess.&lt;string&gt;</code>
153
+ **Kind**: inner method of [<code>createBinTester</code>](#createBinTester)
154
+ **Returns**: <code>execa.ExecaChildProcess.&lt;string&gt;</code> - <p>An instance of execa's child process.</p>
155
+
156
+ | Param | Type | Description |
157
+ | --- | --- | --- |
158
+ | ...args | <code>RunBinArgs</code> | <p>Arguments or execa options.</p> |
159
+
160
+ <a name="createBinTester..setupProject"></a>
161
+
162
+ ### createBinTester~setupProject()
163
+ <p>Sets up the specified project for use within tests.</p>
164
+
165
+ **Kind**: inner method of [<code>createBinTester</code>](#createBinTester)
166
+ <a name="createBinTester..setupTmpDir"></a>
167
+
168
+ ### createBinTester~setupTmpDir()
169
+ <p>Sets up a tmp directory for use within tests.</p>
170
+
171
+ **Kind**: inner method of [<code>createBinTester</code>](#createBinTester)
172
+ <a name="createBinTester..teardownProject"></a>
173
+
174
+ ### createBinTester~teardownProject()
175
+ <p>Tears the project down, ensuring the tmp directory is removed. Shoud be paired with setupProject.</p>
176
+
177
+ **Kind**: inner method of [<code>createBinTester</code>](#createBinTester)
178
+
179
+ <!--DOCS_END-->
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
- writeJSON(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") {
@@ -135,7 +123,6 @@ function createBinTester(options) {
135
123
  setupTmpDir
136
124
  };
137
125
  }
138
- module.exports = __toCommonJS(src_exports);
139
126
  // Annotate the CommonJS export names for ESM import in node:
140
127
  0 && (module.exports = {
141
128
  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 {
@@ -9,7 +8,7 @@ declare class BinTesterProject extends Project {
9
8
  *
10
9
  * @param {string} name - The name of the project. Used within the package.json as the name property.
11
10
  * @param {string} version - The version of the project. Used within the package.json as the version property.
12
- * @param {(project: Project) => void} cb - An optional callback for additional setup steps after the project is constructed.
11
+ * @param {Function} cb - An optional callback for additional setup steps after the project is constructed.
13
12
  */
14
13
  constructor(name?: string, version?: string, cb?: (project: Project) => void);
15
14
  /**
@@ -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
- writeJSON(dirJSON: fixturify.DirJSON): Promise<void>;
32
24
  /**
33
25
  * Correctly disposes of the project, observing when the directory has been changed.
34
26
  *
@@ -49,7 +41,7 @@ interface BinTesterOptions<TProject> {
49
41
  /**
50
42
  * An optional function to use to create the project. Use this if you want to provide a custom implementation of a BinTesterProject.
51
43
  */
52
- createProject?: () => TProject;
44
+ createProject?: () => Promise<TProject>;
53
45
  }
54
46
  interface RunBin {
55
47
  /**
@@ -90,7 +82,6 @@ declare type RunBinArgs = [...binArgs: string[], execaOptions: execa.Options<str
90
82
  /**
91
83
  * Creates the bin tester API functions to use within tests.
92
84
  *
93
- * @typedef TProject - The type of BinTesterProject used.
94
85
  * @param {BinTesterOptions<TProject>} options - An object of bin tester options
95
86
  * @returns {CreateBinTesterResult<TProject>} - A project instance.
96
87
  */
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
- writeJSON(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") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalvert/bin-tester",
3
- "version": "0.2.0",
3
+ "version": "2.0.0",
4
4
  "description": "A test harness to invoke a CLI in a tmp directory",
5
5
  "keywords": [
6
6
  "cli",
@@ -28,10 +28,11 @@
28
28
  "types": "./dist/index.d.ts",
29
29
  "scripts": {
30
30
  "build": "tsup src/index.ts --format cjs,esm --dts --clean",
31
- "docs:generate": "npm run build && readme-api-generator dist/index.js",
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,12 +40,16 @@
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
- "@scalvert/readme-api-generator": "^0.1.0",
47
+ "@babel/plugin-proposal-class-properties": "^7.16.7",
48
+ "@babel/plugin-proposal-object-rest-spread": "^7.17.3",
49
+ "@babel/plugin-transform-typescript": "^7.16.8",
50
+ "@babel/preset-env": "^7.16.11",
51
+ "@babel/preset-typescript": "^7.16.7",
52
+ "@scalvert/readme-api-generator": "^0.2.4",
48
53
  "@typescript-eslint/eslint-plugin": "^5.14.0",
49
54
  "@typescript-eslint/parser": "^5.14.0",
50
55
  "eslint": "^8.10.0",
@@ -61,7 +66,7 @@
61
66
  "type-fest": "^2.12.0",
62
67
  "typescript": "^4.6.2",
63
68
  "vite": "^2.8.6",
64
- "vitest": "^0.6.0"
69
+ "vitest": "^0.9.3"
65
70
  },
66
71
  "engines": {
67
72
  "node": ">=14"