|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | import { execSync } from 'node:child_process'; |
| 18 | +import { writeFileSync } from 'node:fs'; |
| 19 | +import { join } from 'node:path'; |
18 | 20 | import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; |
19 | 21 | import { expect } from 'chai'; |
20 | 22 | import { |
@@ -211,4 +213,32 @@ describe('webapp dev NUTs — Tier 2 CLI validation', () => { |
211 | 213 |
|
212 | 214 | expect(result.jsonOutput?.name).to.equal('DevServerUrlError'); |
213 | 215 | }); |
| 216 | + |
| 217 | + // ── Dev server startup errors ───────────────────────────────── |
| 218 | + |
| 219 | + // Webapp created but npm install never run → dev server fails because |
| 220 | + // dependencies (e.g. vite) are not installed. The command should exit |
| 221 | + // with a meaningful error that suggests installing dependencies. |
| 222 | + // This mirrors the real user flow: generate → dev (without install). |
| 223 | + it('should suggest installing dependencies when dev server fails (no npm install)', () => { |
| 224 | + const projectDir = createProjectWithWebapp(session, 'noInstall', 'myApp'); |
| 225 | + const appDir = webappPath(projectDir, 'myApp'); |
| 226 | + |
| 227 | + writeFileSync( |
| 228 | + join(appDir, 'package.json'), |
| 229 | + JSON.stringify({ name: 'test-webapp', scripts: { dev: 'vite' } }) |
| 230 | + ); |
| 231 | + writeManifest(projectDir, 'myApp', { |
| 232 | + dev: { command: 'npm run dev' }, |
| 233 | + }); |
| 234 | + |
| 235 | + const result = execCmd(`webapp dev --name myApp --target-org ${targetOrg} --json`, { |
| 236 | + ensureExitCode: 1, |
| 237 | + cwd: projectDir, |
| 238 | + }); |
| 239 | + |
| 240 | + expect(result.jsonOutput?.name).to.equal('DevServerError'); |
| 241 | + const output = JSON.stringify(result.jsonOutput ?? {}); |
| 242 | + expect(output).to.match(/npm install|yarn install|dependencies/i); |
| 243 | + }); |
214 | 244 | }); |
0 commit comments