release-it 19.0.0-next.0 → 19.0.0-next.2
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/lib/cli.js +2 -5
- package/lib/config.js +42 -7
- package/lib/index.js +30 -14
- package/lib/log.js +12 -11
- package/lib/plugin/GitBase.js +2 -1
- package/lib/plugin/GitRelease.js +5 -5
- package/lib/plugin/Plugin.js +6 -4
- package/lib/plugin/factory.js +11 -11
- package/lib/plugin/git/Git.js +5 -6
- package/lib/plugin/github/GitHub.js +13 -16
- package/lib/plugin/github/util.js +1 -1
- package/lib/plugin/gitlab/GitLab.js +6 -4
- package/lib/plugin/npm/npm.js +4 -0
- package/lib/util.js +71 -42
- package/package.json +27 -29
- package/schema/gitlab.json +4 -0
- package/schema/release-it.json +4 -0
- package/test/cli.js +6 -5
- package/test/config.js +232 -122
- package/test/git.init.js +220 -218
- package/test/git.js +359 -364
- package/test/github.js +565 -480
- package/test/gitlab.js +374 -335
- package/test/log.js +141 -138
- package/test/npm.js +315 -373
- package/test/plugin-name.js +7 -6
- package/test/plugins.js +200 -211
- package/test/prompt.js +26 -32
- package/test/shell.js +63 -60
- package/test/spinner.js +20 -24
- package/test/stub/github.js +113 -123
- package/test/stub/gitlab.js +74 -52
- package/test/tasks.interactive.js +217 -165
- package/test/tasks.js +394 -413
- package/test/util/helpers.js +4 -3
- package/test/util/index.js +35 -11
- package/test/utils.js +33 -32
- package/test/version.js +192 -176
- package/test/util/setup.js +0 -3
package/test/plugin-name.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import test from '
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
2
3
|
import { getPluginName } from '../lib/plugin/factory.js';
|
|
3
4
|
|
|
4
|
-
test('pluginName can return correct name for variants',
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
test('pluginName can return correct name for variants', async () => {
|
|
6
|
+
assert.equal(getPluginName('plain-plugin'), 'plain-plugin');
|
|
7
|
+
assert.equal(getPluginName('@some/scoped-plugin'), '@some/scoped-plugin');
|
|
8
|
+
assert.equal(getPluginName('@some/nested/scoped-plugin'), '@some/nested/scoped-plugin');
|
|
9
|
+
assert.equal(getPluginName('./relative-plugin.cjs'), 'relative-plugin');
|
|
9
10
|
});
|
package/test/plugins.js
CHANGED
|
@@ -1,243 +1,232 @@
|
|
|
1
1
|
import { resolve, join } from 'node:path';
|
|
2
2
|
import childProcess from 'node:child_process';
|
|
3
3
|
import fs, { appendFileSync, mkdirSync } from 'node:fs';
|
|
4
|
-
import test from '
|
|
5
|
-
import
|
|
6
|
-
import Log from '../lib/log.js';
|
|
7
|
-
import Spinner from '../lib/spinner.js';
|
|
4
|
+
import test, { afterEach, describe } from 'node:test';
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
8
6
|
import Config from '../lib/config.js';
|
|
9
7
|
import { execOpts, parseGitUrl } from '../lib/util.js';
|
|
10
8
|
import runTasks from '../lib/index.js';
|
|
11
9
|
import MyPlugin from './stub/plugin.js';
|
|
12
10
|
import ReplacePlugin from './stub/plugin-replace.js';
|
|
13
11
|
import ContextPlugin from './stub/plugin-context.js';
|
|
14
|
-
import { mkTmpDir } from './util/helpers.js';
|
|
12
|
+
import { getArgs, mkTmpDir } from './util/helpers.js';
|
|
15
13
|
import ShellStub from './stub/shell.js';
|
|
14
|
+
import { LogStub, SpinnerStub } from './util/index.js';
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
ci: true,
|
|
23
|
-
config: false
|
|
24
|
-
};
|
|
16
|
+
describe('plugins', () => {
|
|
17
|
+
const testConfig = {
|
|
18
|
+
ci: true,
|
|
19
|
+
config: false
|
|
20
|
+
};
|
|
25
21
|
|
|
26
|
-
const log =
|
|
27
|
-
const spinner =
|
|
28
|
-
spinner.show.callsFake(({ enabled = true, task }) => (enabled ? task() : noop));
|
|
22
|
+
const log = new LogStub();
|
|
23
|
+
const spinner = new SpinnerStub();
|
|
29
24
|
|
|
30
|
-
const getContainer = options => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
log,
|
|
35
|
-
spinner,
|
|
36
|
-
config,
|
|
37
|
-
shell
|
|
25
|
+
const getContainer = options => {
|
|
26
|
+
const config = new Config(Object.assign({}, testConfig, options));
|
|
27
|
+
const shell = new ShellStub({ container: { log, config } });
|
|
28
|
+
return { log, spinner, config, shell };
|
|
38
29
|
};
|
|
39
|
-
};
|
|
40
30
|
|
|
41
|
-
test.before(t => {
|
|
42
|
-
t.timeout(60 * 1000);
|
|
43
31
|
childProcess.execSync('npm link', execOpts);
|
|
44
|
-
});
|
|
45
32
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
t.context = { dir };
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test.serial.afterEach(() => {
|
|
53
|
-
sandbox.resetHistory();
|
|
54
|
-
});
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
log.resetCalls();
|
|
35
|
+
});
|
|
55
36
|
|
|
56
|
-
test
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
37
|
+
test('should instantiate plugins and execute all release-cycle methods', async () => {
|
|
38
|
+
const pluginDir = mkTmpDir();
|
|
39
|
+
const dir = mkTmpDir();
|
|
40
|
+
process.chdir(pluginDir);
|
|
41
|
+
|
|
42
|
+
appendFileSync(
|
|
43
|
+
join(pluginDir, 'package.json'),
|
|
44
|
+
JSON.stringify({ name: 'my-plugin', version: '1.0.0', type: 'module' })
|
|
45
|
+
);
|
|
46
|
+
childProcess.execSync(`npm link release-it`, execOpts);
|
|
47
|
+
const content = "import { Plugin } from 'release-it'; " + MyPlugin.toString() + '; export default MyPlugin;';
|
|
48
|
+
|
|
49
|
+
appendFileSync(join(pluginDir, 'index.js'), content);
|
|
50
|
+
process.chdir(dir);
|
|
51
|
+
mkdirSync(resolve('my/plugin'), { recursive: true });
|
|
52
|
+
process.chdir('my/plugin');
|
|
53
|
+
|
|
54
|
+
appendFileSync(join(dir, 'my', 'plugin', 'index.js'), content);
|
|
55
|
+
process.chdir(dir);
|
|
56
|
+
|
|
57
|
+
appendFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'project', version: '1.0.0', type: 'module' }));
|
|
58
|
+
childProcess.execSync(`npm install ${pluginDir}`, execOpts);
|
|
59
|
+
childProcess.execSync(`npm link release-it`, execOpts);
|
|
60
|
+
|
|
61
|
+
const config = {
|
|
62
|
+
plugins: {
|
|
63
|
+
'my-plugin': {
|
|
64
|
+
name: 'foo'
|
|
65
|
+
},
|
|
66
|
+
'./my/plugin/index.js': [
|
|
67
|
+
'named-plugin',
|
|
68
|
+
{
|
|
69
|
+
name: 'bar'
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const container = getContainer(config);
|
|
75
|
+
|
|
76
|
+
const result = await runTasks({}, container);
|
|
77
|
+
|
|
78
|
+
assert.deepEqual(
|
|
79
|
+
container.log.info.mock.calls.map(call => call.arguments),
|
|
80
|
+
[
|
|
81
|
+
['my-plugin:foo:init'],
|
|
82
|
+
['named-plugin:bar:init'],
|
|
83
|
+
['my-plugin:foo:getName'],
|
|
84
|
+
['my-plugin:foo:getLatestVersion'],
|
|
85
|
+
['my-plugin:foo:getIncrement'],
|
|
86
|
+
['my-plugin:foo:getIncrementedVersionCI'],
|
|
87
|
+
['named-plugin:bar:getIncrementedVersionCI'],
|
|
88
|
+
['my-plugin:foo:beforeBump'],
|
|
89
|
+
['named-plugin:bar:beforeBump'],
|
|
90
|
+
['my-plugin:foo:bump:1.3.0'],
|
|
91
|
+
['named-plugin:bar:bump:1.3.0'],
|
|
92
|
+
['my-plugin:foo:beforeRelease'],
|
|
93
|
+
['named-plugin:bar:beforeRelease'],
|
|
94
|
+
['my-plugin:foo:release'],
|
|
95
|
+
['named-plugin:bar:release'],
|
|
96
|
+
['my-plugin:foo:afterRelease'],
|
|
97
|
+
['named-plugin:bar:afterRelease']
|
|
91
98
|
]
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
['named-plugin:bar:init'],
|
|
101
|
-
['my-plugin:foo:getName'],
|
|
102
|
-
['my-plugin:foo:getLatestVersion'],
|
|
103
|
-
['my-plugin:foo:getIncrement'],
|
|
104
|
-
['my-plugin:foo:getIncrementedVersionCI'],
|
|
105
|
-
['named-plugin:bar:getIncrementedVersionCI'],
|
|
106
|
-
['my-plugin:foo:beforeBump'],
|
|
107
|
-
['named-plugin:bar:beforeBump'],
|
|
108
|
-
['my-plugin:foo:bump:1.3.0'],
|
|
109
|
-
['named-plugin:bar:bump:1.3.0'],
|
|
110
|
-
['my-plugin:foo:beforeRelease'],
|
|
111
|
-
['named-plugin:bar:beforeRelease'],
|
|
112
|
-
['my-plugin:foo:release'],
|
|
113
|
-
['named-plugin:bar:release'],
|
|
114
|
-
['my-plugin:foo:afterRelease'],
|
|
115
|
-
['named-plugin:bar:afterRelease']
|
|
116
|
-
]);
|
|
117
|
-
|
|
118
|
-
t.deepEqual(result, {
|
|
119
|
-
changelog: undefined,
|
|
120
|
-
name: 'new-project-name',
|
|
121
|
-
latestVersion: '1.2.3',
|
|
122
|
-
version: '1.3.0'
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
assert.deepEqual(result, {
|
|
102
|
+
changelog: undefined,
|
|
103
|
+
name: 'new-project-name',
|
|
104
|
+
latestVersion: '1.2.3',
|
|
105
|
+
version: '1.3.0'
|
|
106
|
+
});
|
|
123
107
|
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test.serial('should instantiate plugins and execute all release-cycle methods for scoped plugins', async t => {
|
|
127
|
-
const { dir } = t.context;
|
|
128
|
-
|
|
129
|
-
const pluginDir = mkTmpDir();
|
|
130
|
-
process.chdir(pluginDir);
|
|
131
|
-
|
|
132
|
-
fs.writeFileSync(
|
|
133
|
-
join(pluginDir, 'package.json'),
|
|
134
|
-
JSON.stringify({ name: '@scoped/my-plugin', version: '1.0.0', type: 'module' })
|
|
135
|
-
);
|
|
136
|
-
childProcess.execSync(`npm link release-it`, execOpts);
|
|
137
|
-
const content = "import { Plugin } from 'release-it'; " + MyPlugin.toString() + '; export default MyPlugin;';
|
|
138
|
-
|
|
139
|
-
fs.writeFileSync(join(pluginDir, 'index.js'), content);
|
|
140
|
-
process.chdir(dir);
|
|
141
|
-
|
|
142
|
-
fs.writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'project', version: '1.0.0', type: 'module' }));
|
|
143
|
-
childProcess.execSync(`npm install ${pluginDir}`, execOpts);
|
|
144
|
-
childProcess.execSync(`npm link release-it`, execOpts);
|
|
145
108
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
109
|
+
test('should instantiate plugins and execute all release-cycle methods for scoped plugins', async () => {
|
|
110
|
+
const pluginDir = mkTmpDir();
|
|
111
|
+
const dir = mkTmpDir();
|
|
112
|
+
process.chdir(pluginDir);
|
|
113
|
+
|
|
114
|
+
fs.writeFileSync(
|
|
115
|
+
join(pluginDir, 'package.json'),
|
|
116
|
+
JSON.stringify({ name: '@scoped/my-plugin', version: '1.0.0', type: 'module' })
|
|
117
|
+
);
|
|
118
|
+
childProcess.execSync(`npm link release-it`, execOpts);
|
|
119
|
+
const content = "import { Plugin } from 'release-it'; " + MyPlugin.toString() + '; export default MyPlugin;';
|
|
120
|
+
|
|
121
|
+
fs.writeFileSync(join(pluginDir, 'index.js'), content);
|
|
122
|
+
process.chdir(dir);
|
|
123
|
+
|
|
124
|
+
fs.writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'project', version: '1.0.0', type: 'module' }));
|
|
125
|
+
childProcess.execSync(`npm install ${pluginDir}`, execOpts);
|
|
126
|
+
childProcess.execSync(`npm link release-it`, execOpts);
|
|
127
|
+
|
|
128
|
+
const config = {
|
|
129
|
+
plugins: {
|
|
130
|
+
'@scoped/my-plugin': {
|
|
131
|
+
name: 'foo'
|
|
132
|
+
}
|
|
150
133
|
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
134
|
+
};
|
|
135
|
+
const container = getContainer(config);
|
|
136
|
+
|
|
137
|
+
const result = await runTasks({}, container);
|
|
138
|
+
|
|
139
|
+
assert.deepEqual(
|
|
140
|
+
container.log.info.mock.calls.map(call => call.arguments),
|
|
141
|
+
[
|
|
142
|
+
['@scoped/my-plugin:foo:init'],
|
|
143
|
+
['@scoped/my-plugin:foo:getName'],
|
|
144
|
+
['@scoped/my-plugin:foo:getLatestVersion'],
|
|
145
|
+
['@scoped/my-plugin:foo:getIncrement'],
|
|
146
|
+
['@scoped/my-plugin:foo:getIncrementedVersionCI'],
|
|
147
|
+
['@scoped/my-plugin:foo:beforeBump'],
|
|
148
|
+
['@scoped/my-plugin:foo:bump:1.3.0'],
|
|
149
|
+
['@scoped/my-plugin:foo:beforeRelease'],
|
|
150
|
+
['@scoped/my-plugin:foo:release'],
|
|
151
|
+
['@scoped/my-plugin:foo:afterRelease']
|
|
152
|
+
]
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
assert.deepEqual(result, {
|
|
156
|
+
changelog: undefined,
|
|
157
|
+
name: 'new-project-name',
|
|
158
|
+
latestVersion: '1.2.3',
|
|
159
|
+
version: '1.3.0'
|
|
160
|
+
});
|
|
175
161
|
});
|
|
176
|
-
});
|
|
177
162
|
|
|
178
|
-
test
|
|
179
|
-
|
|
163
|
+
test('should disable core plugins', async () => {
|
|
164
|
+
const dir = mkTmpDir();
|
|
165
|
+
process.chdir(dir);
|
|
180
166
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
167
|
+
fs.appendFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'project', version: '1.0.0' }));
|
|
168
|
+
const content =
|
|
169
|
+
"import { Plugin } from 'release-it'; " + ReplacePlugin.toString() + '; export default ReplacePlugin;';
|
|
184
170
|
|
|
185
|
-
|
|
186
|
-
|
|
171
|
+
fs.appendFileSync(join(dir, 'replace-plugin.mjs'), content);
|
|
172
|
+
childProcess.execSync(`npm link release-it`, execOpts);
|
|
187
173
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
174
|
+
const config = {
|
|
175
|
+
plugins: {
|
|
176
|
+
'./replace-plugin.mjs': {}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const container = getContainer(config);
|
|
194
180
|
|
|
195
|
-
|
|
181
|
+
const result = await runTasks({}, container);
|
|
196
182
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
183
|
+
assert.deepEqual(result, {
|
|
184
|
+
changelog: undefined,
|
|
185
|
+
name: undefined,
|
|
186
|
+
latestVersion: '0.0.0',
|
|
187
|
+
version: undefined
|
|
188
|
+
});
|
|
202
189
|
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
test.serial('should expose context to execute commands', async t => {
|
|
206
|
-
const { dir } = t.context;
|
|
207
190
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
191
|
+
test('should expose context to execute commands', async t => {
|
|
192
|
+
const dir = mkTmpDir();
|
|
193
|
+
process.chdir(dir);
|
|
194
|
+
|
|
195
|
+
fs.appendFileSync(
|
|
196
|
+
join(dir, 'package.json'),
|
|
197
|
+
JSON.stringify({ name: 'pkg-name', version: '1.0.0', type: 'module' })
|
|
198
|
+
);
|
|
199
|
+
const content =
|
|
200
|
+
"import { Plugin } from 'release-it'; " + ContextPlugin.toString() + '; export default ContextPlugin;';
|
|
201
|
+
|
|
202
|
+
fs.appendFileSync(join(dir, 'context-plugin.js'), content);
|
|
203
|
+
childProcess.execSync(`npm link release-it`, execOpts);
|
|
204
|
+
|
|
205
|
+
const repo = parseGitUrl('https://github.com/user/pkg');
|
|
206
|
+
|
|
207
|
+
const container = getContainer({ plugins: { './context-plugin.js': {} } });
|
|
208
|
+
const exec = t.mock.method(container.shell, 'execFormattedCommand');
|
|
209
|
+
|
|
210
|
+
container.config.setContext({ repo });
|
|
211
|
+
container.config.setContext({ tagName: '1.0.1' });
|
|
212
|
+
|
|
213
|
+
await runTasks({}, container);
|
|
214
|
+
|
|
215
|
+
const pluginExecArgs = getArgs(exec, 'echo');
|
|
216
|
+
|
|
217
|
+
assert.deepEqual(pluginExecArgs, [
|
|
218
|
+
'echo false',
|
|
219
|
+
'echo false',
|
|
220
|
+
`echo pkg-name user 1.0.0 1.0.1`,
|
|
221
|
+
`echo pkg-name user 1.0.0 1.0.1`,
|
|
222
|
+
`echo user pkg user/pkg 1.0.1`,
|
|
223
|
+
`echo user pkg user/pkg 1.0.1`,
|
|
224
|
+
`echo user pkg user/pkg 1.0.1`,
|
|
225
|
+
`echo user pkg user/pkg 1.0.1`,
|
|
226
|
+
`echo pkg 1.0.0 1.0.1 1.0.1`,
|
|
227
|
+
`echo pkg 1.0.0 1.0.1 1.0.1`,
|
|
228
|
+
`echo pkg 1.0.0 1.0.1 1.0.1`,
|
|
229
|
+
`echo pkg 1.0.0 1.0.1 1.0.1`
|
|
230
|
+
]);
|
|
231
|
+
});
|
|
243
232
|
});
|
package/test/prompt.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import test from '
|
|
2
|
-
import
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
3
|
import Prompt from '../lib/prompt.js';
|
|
4
4
|
import Config from '../lib/config.js';
|
|
5
5
|
import git from '../lib/plugin/git/prompts.js';
|
|
@@ -13,31 +13,25 @@ const prompts = { git, github, gitlab, npm };
|
|
|
13
13
|
const yes = ([options]) => Promise.resolve({ [options.name]: true });
|
|
14
14
|
const no = ([options]) => Promise.resolve({ [options.name]: false });
|
|
15
15
|
|
|
16
|
-
test.beforeEach(t => {
|
|
17
|
-
t.context.getInquirer = stub => ({
|
|
18
|
-
prompt: stub
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
16
|
test('should not create prompt if disabled', async t => {
|
|
23
|
-
const task =
|
|
24
|
-
const
|
|
25
|
-
const inquirer =
|
|
17
|
+
const task = t.mock.fn();
|
|
18
|
+
const promptMock = t.mock.fn(yes);
|
|
19
|
+
const inquirer = { prompt: promptMock };
|
|
26
20
|
const prompt = factory(Prompt, { container: { inquirer } });
|
|
27
21
|
prompt.register(prompts.git);
|
|
28
22
|
await prompt.show({ enabled: false, prompt: 'push', task });
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
assert.equal(promptMock.mock.callCount(), 0);
|
|
24
|
+
assert.equal(task.mock.callCount(), 0);
|
|
31
25
|
});
|
|
32
26
|
|
|
33
27
|
test('should create prompt', async t => {
|
|
34
|
-
const
|
|
35
|
-
const inquirer =
|
|
28
|
+
const promptMock = t.mock.fn(yes);
|
|
29
|
+
const inquirer = { prompt: promptMock };
|
|
36
30
|
const prompt = factory(Prompt, { container: { inquirer } });
|
|
37
31
|
prompt.register(prompts.git);
|
|
38
32
|
await prompt.show({ prompt: 'push' });
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
assert.equal(promptMock.mock.callCount(), 1);
|
|
34
|
+
assert.deepEqual(promptMock.mock.calls[0].arguments[0][0], {
|
|
41
35
|
type: 'confirm',
|
|
42
36
|
message: 'Push?',
|
|
43
37
|
name: 'push',
|
|
@@ -57,41 +51,41 @@ test('should create prompt', async t => {
|
|
|
57
51
|
['npm', 'otp', 'Please enter OTP for npm:']
|
|
58
52
|
].map(async ([namespace, prompt, message]) => {
|
|
59
53
|
test(`should create prompt and render template message (${namespace}.${prompt})`, async t => {
|
|
60
|
-
const
|
|
54
|
+
const promptMock = t.mock.fn(yes);
|
|
61
55
|
const config = new Config({
|
|
62
56
|
isPreRelease: true,
|
|
63
57
|
git: { tagName: 'v${version}' },
|
|
64
58
|
npm: { name: 'my-pkg', tag: 'next' }
|
|
65
59
|
});
|
|
66
60
|
config.setContext({ version: '1.0.0', tagName: '1.0.0' });
|
|
67
|
-
const inquirer =
|
|
61
|
+
const inquirer = { prompt: promptMock };
|
|
68
62
|
const p = factory(Prompt, { container: { inquirer } });
|
|
69
63
|
p.register(prompts[namespace], namespace);
|
|
70
64
|
await p.show({ namespace, prompt, context: config.getContext() });
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
assert.equal(promptMock.mock.callCount(), 1);
|
|
66
|
+
assert.equal(promptMock.mock.calls[0].arguments[0][0].message, message);
|
|
73
67
|
});
|
|
74
68
|
});
|
|
75
69
|
|
|
76
70
|
test('should execute task after positive answer', async t => {
|
|
77
|
-
const task =
|
|
78
|
-
const
|
|
79
|
-
const inquirer =
|
|
71
|
+
const task = t.mock.fn();
|
|
72
|
+
const promptMock = t.mock.fn(yes);
|
|
73
|
+
const inquirer = { prompt: promptMock };
|
|
80
74
|
const prompt = factory(Prompt, { container: { inquirer } });
|
|
81
75
|
prompt.register(prompts.git);
|
|
82
76
|
await prompt.show({ prompt: 'push', task });
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
77
|
+
assert.equal(promptMock.mock.callCount(), 1);
|
|
78
|
+
assert.equal(task.mock.callCount(), 1);
|
|
79
|
+
assert.equal(task.mock.calls[0].arguments[0], true);
|
|
86
80
|
});
|
|
87
81
|
|
|
88
82
|
test('should not execute task after negative answer', async t => {
|
|
89
|
-
const task =
|
|
90
|
-
const
|
|
91
|
-
const inquirer =
|
|
83
|
+
const task = t.mock.fn();
|
|
84
|
+
const promptMock = t.mock.fn(no);
|
|
85
|
+
const inquirer = { prompt: promptMock };
|
|
92
86
|
const prompt = factory(Prompt, { container: { inquirer } });
|
|
93
87
|
prompt.register(prompts.git);
|
|
94
88
|
await prompt.show({ prompt: 'push', task });
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
assert.equal(promptMock.mock.callCount(), 1);
|
|
90
|
+
assert.equal(task.mock.callCount(), 0);
|
|
97
91
|
});
|