@scalvert/bin-tester 0.1.0 → 1.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 +124 -31
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +1 -1
- package/package.json +8 -3
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.
|
|
58
|
+
await project.writeDirJSON({
|
|
59
59
|
'some/file.txt': 'some content',
|
|
60
60
|
});
|
|
61
61
|
|
|
@@ -69,31 +69,124 @@ describe('Some tests', () => {
|
|
|
69
69
|
|
|
70
70
|
## API
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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.<TProject></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
|
+
* [.writeDirJSON(dirJSON)](#BinTesterProject+writeDirJSON) ⇒ <code>\*</code>
|
|
97
|
+
* [.dispose()](#BinTesterProject+dispose) ⇒ <code>void</code>
|
|
98
|
+
|
|
99
|
+
<a name="new_BinTesterProject_new"></a>
|
|
100
|
+
|
|
101
|
+
### new BinTesterProject(name, version, cb)
|
|
102
|
+
<p>Constructs an instance of a BinTesterProject.</p>
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
| Param | Type | Default | Description |
|
|
106
|
+
| --- | --- | --- | --- |
|
|
107
|
+
| name | <code>string</code> | <code>"fake-project"</code> | <p>The name of the project. Used within the package.json as the name property.</p> |
|
|
108
|
+
| version | <code>string</code> | | <p>The version of the project. Used within the package.json as the version property.</p> |
|
|
109
|
+
| cb | <code>function</code> | | <p>An optional callback for additional setup steps after the project is constructed.</p> |
|
|
110
|
+
|
|
111
|
+
<a name="BinTesterProject+gitInit"></a>
|
|
112
|
+
|
|
113
|
+
### binTesterProject.gitInit() ⇒ <code>\*</code>
|
|
114
|
+
<p>Runs <code>git init</code> inside a project.</p>
|
|
115
|
+
|
|
116
|
+
**Kind**: instance method of [<code>BinTesterProject</code>](#BinTesterProject)
|
|
117
|
+
**Returns**: <code>\*</code> - <p>{execa.ExecaChildProcess<string>}</p>
|
|
118
|
+
<a name="BinTesterProject+chdir"></a>
|
|
119
|
+
|
|
120
|
+
### binTesterProject.chdir()
|
|
121
|
+
<p>Changes a directory from inside the project.</p>
|
|
122
|
+
|
|
123
|
+
**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
|
+
<a name="BinTesterProject+dispose"></a>
|
|
137
|
+
|
|
138
|
+
### binTesterProject.dispose() ⇒ <code>void</code>
|
|
139
|
+
<p>Correctly disposes of the project, observing when the directory has been changed.</p>
|
|
140
|
+
|
|
141
|
+
**Kind**: instance method of [<code>BinTesterProject</code>](#BinTesterProject)
|
|
142
|
+
<a name="createBinTester"></a>
|
|
143
|
+
|
|
144
|
+
## createBinTester(options) ⇒ <code>CreateBinTesterResult.<TProject></code>
|
|
145
|
+
<p>Creates the bin tester API functions to use within tests.</p>
|
|
146
|
+
|
|
147
|
+
**Kind**: global function
|
|
148
|
+
**Returns**: <code>CreateBinTesterResult.<TProject></code> - <ul>
|
|
149
|
+
<li>A project instance.</li>
|
|
150
|
+
</ul>
|
|
151
|
+
|
|
152
|
+
| Param | Type | Description |
|
|
153
|
+
| --- | --- | --- |
|
|
154
|
+
| options | <code>BinTesterOptions.<TProject></code> | <p>An object of bin tester options</p> |
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
* [createBinTester(options)](#createBinTester) ⇒ <code>CreateBinTesterResult.<TProject></code>
|
|
158
|
+
* [~runBin(...args)](#createBinTester..runBin) ⇒ <code>execa.ExecaChildProcess.<string></code>
|
|
159
|
+
* [~setupProject()](#createBinTester..setupProject)
|
|
160
|
+
* [~setupTmpDir()](#createBinTester..setupTmpDir)
|
|
161
|
+
* [~teardownProject()](#createBinTester..teardownProject)
|
|
162
|
+
|
|
163
|
+
<a name="createBinTester..runBin"></a>
|
|
164
|
+
|
|
165
|
+
### createBinTester~runBin(...args) ⇒ <code>execa.ExecaChildProcess.<string></code>
|
|
166
|
+
**Kind**: inner method of [<code>createBinTester</code>](#createBinTester)
|
|
167
|
+
**Returns**: <code>execa.ExecaChildProcess.<string></code> - <p>An instance of execa's child process.</p>
|
|
168
|
+
|
|
169
|
+
| Param | Type | Description |
|
|
170
|
+
| --- | --- | --- |
|
|
171
|
+
| ...args | <code>RunBinArgs</code> | <p>Arguments or execa options.</p> |
|
|
172
|
+
|
|
173
|
+
<a name="createBinTester..setupProject"></a>
|
|
174
|
+
|
|
175
|
+
### createBinTester~setupProject()
|
|
176
|
+
<p>Sets up the specified project for use within tests.</p>
|
|
177
|
+
|
|
178
|
+
**Kind**: inner method of [<code>createBinTester</code>](#createBinTester)
|
|
179
|
+
<a name="createBinTester..setupTmpDir"></a>
|
|
180
|
+
|
|
181
|
+
### createBinTester~setupTmpDir()
|
|
182
|
+
<p>Sets up a tmp directory for use within tests.</p>
|
|
183
|
+
|
|
184
|
+
**Kind**: inner method of [<code>createBinTester</code>](#createBinTester)
|
|
185
|
+
<a name="createBinTester..teardownProject"></a>
|
|
186
|
+
|
|
187
|
+
### createBinTester~teardownProject()
|
|
188
|
+
<p>Tears the project down, ensuring the tmp directory is removed. Shoud be paired with setupProject.</p>
|
|
189
|
+
|
|
190
|
+
**Kind**: inner method of [<code>createBinTester</code>](#createBinTester)
|
|
191
|
+
|
|
192
|
+
<!--DOCS_END-->
|
package/dist/index.cjs
CHANGED
|
@@ -73,7 +73,7 @@ var BinTesterProject = class extends import_fixturify_project.Project {
|
|
|
73
73
|
await this.write();
|
|
74
74
|
process.chdir(this.baseDir);
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
writeDirJSON(dirJSON) {
|
|
77
77
|
this.files = (0, import_deepmerge.default)(this.files, dirJSON);
|
|
78
78
|
return this.write();
|
|
79
79
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ declare class BinTesterProject extends Project {
|
|
|
9
9
|
*
|
|
10
10
|
* @param {string} name - The name of the project. Used within the package.json as the name property.
|
|
11
11
|
* @param {string} version - The version of the project. Used within the package.json as the version property.
|
|
12
|
-
* @param {
|
|
12
|
+
* @param {Function} cb - An optional callback for additional setup steps after the project is constructed.
|
|
13
13
|
*/
|
|
14
14
|
constructor(name?: string, version?: string, cb?: (project: Project) => void);
|
|
15
15
|
/**
|
|
@@ -28,7 +28,7 @@ declare class BinTesterProject extends Project {
|
|
|
28
28
|
* @param {fixturify.DirJSON} dirJSON - A JSON object representing the directory structure to create.
|
|
29
29
|
* @returns {*} {Promise<void>}
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
writeDirJSON(dirJSON: fixturify.DirJSON): Promise<void>;
|
|
32
32
|
/**
|
|
33
33
|
* Correctly disposes of the project, observing when the directory has been changed.
|
|
34
34
|
*
|
|
@@ -49,7 +49,7 @@ interface BinTesterOptions<TProject> {
|
|
|
49
49
|
/**
|
|
50
50
|
* An optional function to use to create the project. Use this if you want to provide a custom implementation of a BinTesterProject.
|
|
51
51
|
*/
|
|
52
|
-
createProject?: () => TProject
|
|
52
|
+
createProject?: () => Promise<TProject>;
|
|
53
53
|
}
|
|
54
54
|
interface RunBin {
|
|
55
55
|
/**
|
|
@@ -90,7 +90,6 @@ declare type RunBinArgs = [...binArgs: string[], execaOptions: execa.Options<str
|
|
|
90
90
|
/**
|
|
91
91
|
* Creates the bin tester API functions to use within tests.
|
|
92
92
|
*
|
|
93
|
-
* @typedef TProject - The type of BinTesterProject used.
|
|
94
93
|
* @param {BinTesterOptions<TProject>} options - An object of bin tester options
|
|
95
94
|
* @returns {CreateBinTesterResult<TProject>} - A project instance.
|
|
96
95
|
*/
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalvert/bin-tester",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A test harness to invoke a CLI in a tmp directory",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -28,7 +28,7 @@
|
|
|
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": "
|
|
31
|
+
"docs:generate": "readme-api-generator ./src --ts",
|
|
32
32
|
"lint": "eslint .",
|
|
33
33
|
"prepublishOnly": "npm run build",
|
|
34
34
|
"test": "npm run lint && vitest run",
|
|
@@ -44,7 +44,12 @@
|
|
|
44
44
|
"fixturify-project": "^4.1.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@
|
|
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.0",
|
|
48
53
|
"@typescript-eslint/eslint-plugin": "^5.14.0",
|
|
49
54
|
"@typescript-eslint/parser": "^5.14.0",
|
|
50
55
|
"eslint": "^8.10.0",
|