-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive-dev-server.test.js
More file actions
173 lines (142 loc) · 6.04 KB
/
interactive-dev-server.test.js
File metadata and controls
173 lines (142 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { expect } = require('chai');
const sinon = require('sinon');
// Inquirer v12 CJS export is { default: { prompt, ... } }; use default so stubs apply to what lib uses
const inquirer = require('inquirer').default || require('inquirer');
const { inquireRunDevServer } = require('../lib/bootstrap/interactive');
const messages = require('../messages/index.json');
describe('Interactive Dev Server Tests', () => {
let sandbox;
beforeEach(() => {
sandbox = sinon.createSandbox();
});
afterEach(() => {
sandbox.restore();
});
describe('#inquireRunDevServer', () => {
it('should return true when user selects yes', async () => {
sandbox.stub(inquirer, 'prompt').resolves({ runDevServer: true });
const result = await inquireRunDevServer();
expect(result).to.be.true;
expect(inquirer.prompt.calledOnce).to.be.true;
const promptArgs = inquirer.prompt.getCall(0).args[0];
expect(promptArgs.type).to.equal('confirm');
expect(promptArgs.name).to.equal('runDevServer');
expect(promptArgs.message).to.equal(messages.CLI_BOOTSTRAP_RUN_DEV_SERVER_ENQUIRY);
expect(promptArgs.default).to.be.true;
});
it('should return false when user selects no', async () => {
sandbox.stub(inquirer, 'prompt').resolves({ runDevServer: false });
const result = await inquireRunDevServer();
expect(result).to.be.false;
expect(inquirer.prompt.calledOnce).to.be.true;
});
it('should have correct message asking about install and run', () => {
expect(messages.CLI_BOOTSTRAP_RUN_DEV_SERVER_ENQUIRY).to.include('install dependencies and run the app locally');
expect(messages.CLI_BOOTSTRAP_RUN_DEV_SERVER_ENQUIRY).to.include('npm install && npm run dev');
});
it('should respect --run-dev-server flag in command parsing', async () => {
// This test would require more complex mocking of the command parsing
// For now, we can verify the flag is properly defined
const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
expect(BootstrapCommand.flags).to.have.property('run-dev-server');
expect(BootstrapCommand.flags['run-dev-server'].description).to.include('development server after setup');
});
});
describe('Edge Cases and Interactive Functions', () => {
it('should handle all interactive functions', async () => {
const {
inquireApp,
inquireCloneDirectory,
inquireAppType,
inquireLivePreviewSupport,
inquireGithubAccessToken,
} = require('../lib/bootstrap/interactive');
// Test inquireApp with exit selection
sandbox
.stub(inquirer, 'prompt')
.onFirstCall()
.resolves({ app: 'Exit' })
.onSecondCall()
.resolves({ path: 'Other' })
.onThirdCall()
.resolves({ path: '/custom/path' })
.onCall(3)
.resolves({ type: 'sampleapp' })
.onCall(4)
.resolves({ livePreviewEnabled: false })
.onCall(5)
.resolves({ token: 'test-token' });
try {
await inquireApp([{ displayName: 'Test App', value: 'test' }]);
expect.fail('Should have thrown an error for Exit');
} catch (error) {
expect(error.message).to.equal('Exit');
}
// Test inquireCloneDirectory with "Other" option
const customPath = await inquireCloneDirectory();
expect(customPath).to.equal('/custom/path');
// Test inquireAppType
const appType = await inquireAppType();
expect(appType).to.equal('sampleapp');
// Test inquireLivePreviewSupport
const livePreview = await inquireLivePreviewSupport();
expect(livePreview).to.be.false;
// Test inquireGithubAccessToken
const token = await inquireGithubAccessToken();
expect(token).to.equal('test-token');
});
it('should handle inquireRunDevServer with different scenarios', async () => {
// Test with default true
sandbox.stub(inquirer, 'prompt').resolves({ runDevServer: true });
const result1 = await inquireRunDevServer();
expect(result1).to.be.true;
// Test with false
sandbox.restore();
sandbox = sinon.createSandbox();
sandbox.stub(inquirer, 'prompt').resolves({ runDevServer: false });
const result2 = await inquireRunDevServer();
expect(result2).to.be.false;
});
it('should verify run-dev-server flag integration with command', () => {
const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
const flag = BootstrapCommand.flags['run-dev-server'];
expect(flag).to.exist;
expect(flag.type).to.equal('boolean');
expect(flag.default).to.be.false;
expect(flag.description).to.include('development server');
});
it('should handle error cases in inquireRunDevServer', async () => {
const error = new Error('Prompt error');
sandbox.stub(inquirer, 'prompt').rejects(error);
try {
await inquireRunDevServer();
expect.fail('Should have thrown an error');
} catch (err) {
expect(err).to.equal(error);
}
});
it('should verify message content for run dev server enquiry', () => {
expect(messages.CLI_BOOTSTRAP_RUN_DEV_SERVER_ENQUIRY).to.exist;
expect(messages.CLI_BOOTSTRAP_RUN_DEV_SERVER_ENQUIRY).to.be.a('string');
expect(messages.CLI_BOOTSTRAP_RUN_DEV_SERVER_ENQUIRY.length).to.be.greaterThan(0);
});
it('should handle multiple consecutive calls to inquireRunDevServer', async () => {
sandbox
.stub(inquirer, 'prompt')
.onFirstCall()
.resolves({ runDevServer: true })
.onSecondCall()
.resolves({ runDevServer: false })
.onThirdCall()
.resolves({ runDevServer: true });
const result1 = await inquireRunDevServer();
expect(result1).to.be.true;
const result2 = await inquireRunDevServer();
expect(result2).to.be.false;
const result3 = await inquireRunDevServer();
expect(result3).to.be.true;
});
});
});