@hubspot/cli 7.10.0 → 7.10.1-experimental.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/bin/cli.js +5 -4
- package/commands/__tests__/getStarted.test.js +10 -0
- package/commands/__tests__/project.test.js +3 -0
- package/commands/account/__tests__/rename.test.js +10 -3
- package/commands/account/auth.js +10 -14
- package/commands/account/clean.js +11 -19
- package/commands/account/createOverride.js +15 -11
- package/commands/account/info.js +8 -5
- package/commands/account/list.js +15 -19
- package/commands/account/remove.js +23 -22
- package/commands/account/removeOverride.js +6 -6
- package/commands/account/rename.js +2 -2
- package/commands/account/use.js +19 -8
- package/commands/app/__tests__/migrate.test.js +8 -4
- package/commands/app/migrate.js +2 -2
- package/commands/auth.js +18 -14
- package/commands/config/migrate.js +5 -5
- package/commands/customObject/createSchema.js +2 -3
- package/commands/customObject/updateSchema.js +2 -3
- package/commands/getStarted.js +2 -3
- package/commands/hubdb/__tests__/list.test.js +1 -0
- package/commands/hubdb/list.js +2 -2
- package/commands/init.js +36 -32
- package/commands/project/__tests__/deploy.test.js +10 -5
- package/commands/project/__tests__/devUnifiedFlow.test.js +6 -4
- package/commands/project/__tests__/lint.test.js +709 -0
- package/commands/project/__tests__/logs.test.js +4 -0
- package/commands/project/__tests__/validate.test.js +286 -28
- package/commands/project/cloneApp.js +2 -2
- package/commands/project/deploy.js +16 -8
- package/commands/project/dev/deprecatedFlow.js +4 -5
- package/commands/project/dev/index.js +19 -7
- package/commands/project/dev/unifiedFlow.js +4 -5
- package/commands/project/lint.d.ts +6 -0
- package/commands/project/lint.js +178 -0
- package/commands/project/logs.js +2 -3
- package/commands/project/migrate.js +4 -13
- package/commands/project/profile/add.js +6 -7
- package/commands/project/profile/delete.js +2 -2
- package/commands/project/upload.js +10 -4
- package/commands/project/validate.js +73 -13
- package/commands/project.js +2 -0
- package/commands/sandbox/__tests__/create.test.js +14 -5
- package/commands/sandbox/create.js +4 -5
- package/commands/sandbox/delete.js +23 -20
- package/commands/testAccount/create.js +2 -2
- package/commands/testAccount/delete.js +9 -8
- package/lang/en.d.ts +48 -11
- package/lang/en.js +58 -15
- package/lib/__tests__/buildAccount.test.js +22 -30
- package/lib/__tests__/commonOpts.test.js +9 -13
- package/lib/__tests__/developerTestAccounts.test.js +29 -17
- package/lib/__tests__/importData.test.js +20 -10
- package/lib/__tests__/oauth.test.js +19 -8
- package/lib/__tests__/projectProfiles.test.js +273 -32
- package/lib/__tests__/sandboxSync.test.js +33 -11
- package/lib/__tests__/sandboxes.test.js +30 -19
- package/lib/__tests__/usageTracking.test.js +10 -10
- package/lib/__tests__/validation.test.js +32 -32
- package/lib/accountTypes.d.ts +9 -9
- package/lib/accountTypes.js +2 -4
- package/lib/app/__tests__/migrate.test.js +15 -0
- package/lib/app/__tests__/migrate_legacy.test.js +9 -0
- package/lib/app/migrate_legacy.d.ts +2 -2
- package/lib/buildAccount.d.ts +4 -4
- package/lib/buildAccount.js +7 -14
- package/lib/commonOpts.js +3 -3
- package/lib/configMigrate.d.ts +2 -2
- package/lib/configMigrate.js +42 -18
- package/lib/configOptions.js +3 -2
- package/lib/developerTestAccounts.d.ts +3 -3
- package/lib/developerTestAccounts.js +4 -7
- package/lib/doctor/DiagnosticInfoBuilder.d.ts +1 -1
- package/lib/doctor/DiagnosticInfoBuilder.js +9 -6
- package/lib/doctor/Doctor.js +4 -3
- package/lib/doctor/__tests__/Diagnosis.test.js +4 -3
- package/lib/doctor/__tests__/DiagnosticInfoBuilder.test.js +17 -9
- package/lib/doctor/__tests__/Doctor.test.js +14 -0
- package/lib/importData.js +8 -7
- package/lib/links.js +5 -5
- package/lib/middleware/{__test__ → __tests__}/commandTargetingUtils.test.js +3 -3
- package/lib/middleware/{__test__ → __tests__}/configMiddleware.test.js +23 -22
- package/lib/middleware/{__test__ → __tests__}/gitMiddleware.test.js +9 -7
- package/lib/middleware/autoUpdateMiddleware.js +34 -23
- package/lib/middleware/commandTargetingUtils.js +3 -2
- package/lib/middleware/configMiddleware.d.ts +6 -1
- package/lib/middleware/configMiddleware.js +36 -15
- package/lib/middleware/fireAlarmMiddleware.js +4 -15
- package/lib/middleware/gitMiddleware.js +8 -4
- package/lib/oauth.d.ts +2 -2
- package/lib/oauth.js +8 -10
- package/lib/projectProfiles.d.ts +4 -3
- package/lib/projectProfiles.js +78 -32
- package/lib/projects/__tests__/AppDevModeInterface.test.js +17 -6
- package/lib/projects/__tests__/DevServerManager.test.js +1 -0
- package/lib/projects/__tests__/LocalDevProcess.test.js +1 -0
- package/lib/projects/__tests__/deploy.test.js +1 -0
- package/lib/projects/__tests__/uieLinting.test.js +640 -0
- package/lib/projects/create/__tests__/v2.test.js +11 -0
- package/lib/projects/localDev/AppDevModeInterface.js +2 -2
- package/lib/projects/localDev/DevServerManager_DEPRECATED.js +2 -2
- package/lib/projects/localDev/LocalDevLogger.js +4 -4
- package/lib/projects/localDev/LocalDevManager_DEPRECATED.js +3 -3
- package/lib/projects/localDev/helpers/account.d.ts +10 -10
- package/lib/projects/localDev/helpers/account.js +6 -11
- package/lib/projects/uieLinting.d.ts +33 -0
- package/lib/projects/uieLinting.js +222 -0
- package/lib/projects/urls.js +5 -6
- package/lib/prompts/__tests__/downloadProjectPrompt.test.js +7 -5
- package/lib/prompts/accountNamePrompt.js +3 -3
- package/lib/prompts/accountsPrompt.d.ts +1 -1
- package/lib/prompts/accountsPrompt.js +6 -7
- package/lib/prompts/confirmImportDataPrompt.js +2 -2
- package/lib/prompts/downloadProjectPrompt.d.ts +1 -0
- package/lib/prompts/downloadProjectPrompt.js +5 -2
- package/lib/prompts/importDataTestAccountSelectPrompt.js +4 -5
- package/lib/prompts/personalAccessKeyPrompt.js +2 -2
- package/lib/prompts/projectDevTargetAccountPrompt.d.ts +3 -3
- package/lib/prompts/projectDevTargetAccountPrompt.js +5 -7
- package/lib/prompts/sandboxesPrompt.js +7 -8
- package/lib/prompts/setAsDefaultAccountPrompt.js +7 -6
- package/lib/sandboxSync.d.ts +2 -2
- package/lib/sandboxSync.js +3 -9
- package/lib/sandboxes.d.ts +4 -4
- package/lib/sandboxes.js +6 -11
- package/lib/serverlessLogs.js +2 -2
- package/lib/theme/__tests__/migrate.test.js +15 -0
- package/lib/ui/index.js +6 -3
- package/lib/usageTracking.js +15 -8
- package/lib/validation.js +13 -11
- package/mcp-server/tools/cms/HsCreateFunctionTool.js +4 -2
- package/mcp-server/tools/cms/HsCreateModuleTool.js +4 -2
- package/mcp-server/tools/cms/HsCreateTemplateTool.js +4 -2
- package/mcp-server/tools/cms/HsFunctionLogsTool.js +4 -2
- package/mcp-server/tools/cms/HsListFunctionsTool.js +3 -1
- package/mcp-server/tools/cms/HsListTool.js +3 -1
- package/mcp-server/tools/cms/__tests__/HsCreateFunctionTool.test.js +1 -0
- package/mcp-server/tools/index.js +4 -0
- package/mcp-server/tools/project/AddFeatureToProjectTool.js +4 -2
- package/mcp-server/tools/project/CreateProjectTool.js +4 -2
- package/mcp-server/tools/project/CreateTestAccountTool.js +17 -7
- package/mcp-server/tools/project/DeployProjectTool.js +3 -1
- package/mcp-server/tools/project/DocFetchTool.js +6 -4
- package/mcp-server/tools/project/DocsSearchTool.d.ts +1 -1
- package/mcp-server/tools/project/DocsSearchTool.js +10 -8
- package/mcp-server/tools/project/GetApiUsagePatternsByAppIdTool.d.ts +1 -1
- package/mcp-server/tools/project/GetApiUsagePatternsByAppIdTool.js +9 -7
- package/mcp-server/tools/project/GetApplicationInfoTool.js +8 -6
- package/mcp-server/tools/project/GetBuildLogsTool.d.ts +26 -0
- package/mcp-server/tools/project/GetBuildLogsTool.js +125 -0
- package/mcp-server/tools/project/GetBuildStatusTool.d.ts +26 -0
- package/mcp-server/tools/project/GetBuildStatusTool.js +166 -0
- package/mcp-server/tools/project/GetConfigValuesTool.d.ts +1 -1
- package/mcp-server/tools/project/GetConfigValuesTool.js +9 -7
- package/mcp-server/tools/project/GuidedWalkthroughTool.d.ts +1 -1
- package/mcp-server/tools/project/GuidedWalkthroughTool.js +5 -3
- package/mcp-server/tools/project/UploadProjectTools.js +3 -1
- package/mcp-server/tools/project/ValidateProjectTool.js +4 -2
- package/mcp-server/tools/project/__tests__/CreateTestAccountTool.test.js +12 -2
- package/mcp-server/tools/project/__tests__/DocFetchTool.test.js +5 -1
- package/mcp-server/tools/project/__tests__/DocsSearchTool.test.js +23 -11
- package/mcp-server/tools/project/__tests__/GetApiUsagePatternsByAppIdTool.test.js +7 -5
- package/mcp-server/tools/project/__tests__/GetApplicationInfoTool.test.js +7 -5
- package/mcp-server/tools/project/__tests__/GetBuildLogsTool.test.d.ts +1 -0
- package/mcp-server/tools/project/__tests__/GetBuildLogsTool.test.js +305 -0
- package/mcp-server/tools/project/__tests__/GetBuildStatusTool.test.d.ts +1 -0
- package/mcp-server/tools/project/__tests__/GetBuildStatusTool.test.js +240 -0
- package/mcp-server/tools/project/__tests__/GetConfigValuesTool.test.js +8 -6
- package/mcp-server/utils/__tests__/content.test.js +21 -20
- package/mcp-server/utils/__tests__/feedbackTracking.test.js +34 -28
- package/mcp-server/utils/config.d.ts +1 -0
- package/mcp-server/utils/config.js +10 -0
- package/mcp-server/utils/content.d.ts +1 -1
- package/mcp-server/utils/content.js +2 -2
- package/mcp-server/utils/feedbackTracking.d.ts +1 -1
- package/mcp-server/utils/feedbackTracking.js +3 -3
- package/mcp-server/utils/toolUsageTracking.js +4 -3
- package/package.json +9 -9
- package/ui/components/BoxWithTitle.d.ts +2 -1
- package/ui/components/BoxWithTitle.js +2 -2
- package/ui/components/StatusMessageBoxes.d.ts +5 -4
- package/ui/components/StatusMessageBoxes.js +8 -8
- package/lib/middleware/__test__/notificationsMiddleware.test.js +0 -8
- package/lib/middleware/notificationsMiddleware.d.ts +0 -1
- package/lib/middleware/notificationsMiddleware.js +0 -28
- package/lib/ui/boxen.d.ts +0 -5
- package/lib/ui/boxen.js +0 -26
- package/mcp-server/utils/__tests__/cliConfig.test.js +0 -110
- package/mcp-server/utils/cliConfig.d.ts +0 -1
- package/mcp-server/utils/cliConfig.js +0 -12
- /package/{lib/middleware/__test__/commandTargetingUtils.test.d.ts → commands/project/__tests__/lint.test.d.ts} +0 -0
- /package/lib/middleware/{__test__/configMiddleware.test.d.ts → __tests__/commandTargetingUtils.test.d.ts} +0 -0
- /package/lib/middleware/{__test__/gitMiddleware.test.d.ts → __tests__/configMiddleware.test.d.ts} +0 -0
- /package/lib/middleware/{__test__/notificationsMiddleware.test.d.ts → __tests__/gitMiddleware.test.d.ts} +0 -0
- /package/lib/middleware/{__test__ → __tests__}/requestMiddleware.test.d.ts +0 -0
- /package/lib/middleware/{__test__ → __tests__}/requestMiddleware.test.js +0 -0
- /package/lib/middleware/{__test__ → __tests__}/yargsChecksMiddleware.test.d.ts +0 -0
- /package/lib/middleware/{__test__ → __tests__}/yargsChecksMiddleware.test.js +0 -0
- /package/{mcp-server/utils/__tests__/cliConfig.test.d.ts → lib/projects/__tests__/uieLinting.test.d.ts} +0 -0
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
import yargs from 'yargs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { uiLogger } from '../../../lib/ui/logger.js';
|
|
4
|
+
import * as projectUtils from '../../../lib/projects/config.js';
|
|
5
|
+
import { EXIT_CODES } from '../../../lib/enums/exitCodes.js';
|
|
6
|
+
import { trackCommandUsage } from '../../../lib/usageTracking.js';
|
|
7
|
+
import * as dependencyManagement from '../../../lib/dependencyManagement.js';
|
|
8
|
+
import * as promptUtils from '../../../lib/prompts/promptUtils.js';
|
|
9
|
+
import * as linting from '../../../lib/projects/uieLinting.js';
|
|
10
|
+
import { REQUIRED_PACKAGES_AND_MIN_VERSIONS } from '../../../lib/projects/uieLinting.js';
|
|
11
|
+
import projectLintCommand from '../lint.js';
|
|
12
|
+
vi.mock('../../../lib/ui/logger.js');
|
|
13
|
+
vi.mock('../../../lib/ui/SpinniesManager.js');
|
|
14
|
+
vi.mock('../../../lib/projects/config');
|
|
15
|
+
vi.mock('../../../lib/dependencyManagement');
|
|
16
|
+
vi.mock('../../../lib/prompts/promptUtils');
|
|
17
|
+
vi.mock('../../../lib/projects/uieLinting');
|
|
18
|
+
vi.mock('../../../lib/usageTracking');
|
|
19
|
+
vi.mock('../../../lib/commonOpts');
|
|
20
|
+
const exampleSpy = vi.spyOn(yargs, 'example');
|
|
21
|
+
const processExitSpy = vi.spyOn(process, 'exit');
|
|
22
|
+
const getProjectConfigSpy = vi.spyOn(projectUtils, 'getProjectConfig');
|
|
23
|
+
const getProjectPackageJsonLocationsSpy = vi.spyOn(dependencyManagement, 'getProjectPackageJsonLocations');
|
|
24
|
+
const installPackagesSpy = vi.spyOn(dependencyManagement, 'installPackages');
|
|
25
|
+
const promptUserSpy = vi.spyOn(promptUtils, 'promptUser');
|
|
26
|
+
const areAllLintPackagesInstalledSpy = vi.spyOn(linting, 'areAllLintPackagesInstalled');
|
|
27
|
+
const getMissingLintPackagesSpy = vi.spyOn(linting, 'getMissingLintPackages');
|
|
28
|
+
const lintPackagesSpy = vi.spyOn(linting, 'lintPackages');
|
|
29
|
+
const displayLintResultsSpy = vi.spyOn(linting, 'displayLintResults');
|
|
30
|
+
const hasEslintConfigSpy = vi.spyOn(linting, 'hasEslintConfig');
|
|
31
|
+
const hasDeprecatedEslintConfigSpy = vi.spyOn(linting, 'hasDeprecatedEslintConfig');
|
|
32
|
+
const getDeprecatedEslintConfigFilesSpy = vi.spyOn(linting, 'getDeprecatedEslintConfigFiles');
|
|
33
|
+
const createEslintConfigSpy = vi.spyOn(linting, 'createEslintConfig');
|
|
34
|
+
describe('commands/project/lint', () => {
|
|
35
|
+
describe('command', () => {
|
|
36
|
+
it('should have the correct command structure', () => {
|
|
37
|
+
expect(projectLintCommand.command).toEqual('lint');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe('describe', () => {
|
|
41
|
+
it('should provide a description', () => {
|
|
42
|
+
expect(projectLintCommand.describe).toEqual(expect.stringMatching(/Lint the UI Extensions components in your project/));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe('builder', () => {
|
|
46
|
+
it('should provide examples', () => {
|
|
47
|
+
projectLintCommand.builder(yargs);
|
|
48
|
+
expect(exampleSpy).toHaveBeenCalledTimes(1);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('handler', () => {
|
|
52
|
+
let args;
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
args = {
|
|
55
|
+
derivedAccountId: 999999,
|
|
56
|
+
};
|
|
57
|
+
// @ts-expect-error Doesn't match the actual signature because then the linter complains about unused variables
|
|
58
|
+
processExitSpy.mockImplementation(() => { });
|
|
59
|
+
// Default to having config present unless overridden
|
|
60
|
+
hasEslintConfigSpy.mockReturnValue(true);
|
|
61
|
+
hasDeprecatedEslintConfigSpy.mockReturnValue(false);
|
|
62
|
+
// Default to linting succeeding unless overridden
|
|
63
|
+
lintPackagesSpy.mockResolvedValue({ success: true, results: [] });
|
|
64
|
+
displayLintResultsSpy.mockImplementation(() => { });
|
|
65
|
+
});
|
|
66
|
+
afterEach(() => {
|
|
67
|
+
vi.clearAllMocks();
|
|
68
|
+
});
|
|
69
|
+
it('should track the command usage', async () => {
|
|
70
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
71
|
+
projectDir: '/test/project',
|
|
72
|
+
projectConfig: null,
|
|
73
|
+
});
|
|
74
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([]);
|
|
75
|
+
await projectLintCommand.handler(args);
|
|
76
|
+
expect(trackCommandUsage).toHaveBeenCalledTimes(1);
|
|
77
|
+
expect(trackCommandUsage).toHaveBeenCalledWith('project-lint', undefined, args.derivedAccountId);
|
|
78
|
+
});
|
|
79
|
+
it('should handle exceptions', async () => {
|
|
80
|
+
const error = new Error('Something went super wrong');
|
|
81
|
+
getProjectConfigSpy.mockImplementationOnce(() => {
|
|
82
|
+
throw error;
|
|
83
|
+
});
|
|
84
|
+
await projectLintCommand.handler(args);
|
|
85
|
+
expect(uiLogger.error).toHaveBeenCalledTimes(1);
|
|
86
|
+
expect(uiLogger.error).toHaveBeenCalledWith(error.message);
|
|
87
|
+
expect(processExitSpy).toHaveBeenCalledTimes(1);
|
|
88
|
+
expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
89
|
+
});
|
|
90
|
+
it('should log an error and exit when the project config is not defined', async () => {
|
|
91
|
+
getProjectConfigSpy.mockResolvedValueOnce({
|
|
92
|
+
projectDir: null,
|
|
93
|
+
projectConfig: null,
|
|
94
|
+
});
|
|
95
|
+
await projectLintCommand.handler(args);
|
|
96
|
+
expect(uiLogger.error).toHaveBeenCalledTimes(1);
|
|
97
|
+
expect(uiLogger.error).toHaveBeenCalledWith('No project detected. Run this command from a project directory.');
|
|
98
|
+
expect(processExitSpy).toHaveBeenCalledTimes(1);
|
|
99
|
+
expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
100
|
+
});
|
|
101
|
+
it('should log an error and exit when the project config has no projectDir', async () => {
|
|
102
|
+
getProjectConfigSpy.mockResolvedValueOnce({
|
|
103
|
+
projectDir: null,
|
|
104
|
+
projectConfig: null,
|
|
105
|
+
});
|
|
106
|
+
await projectLintCommand.handler(args);
|
|
107
|
+
expect(uiLogger.error).toHaveBeenCalledTimes(1);
|
|
108
|
+
expect(uiLogger.error).toHaveBeenCalledWith('No project detected. Run this command from a project directory.');
|
|
109
|
+
expect(processExitSpy).toHaveBeenCalledTimes(1);
|
|
110
|
+
expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
111
|
+
});
|
|
112
|
+
it('should lint directories with all packages installed', async () => {
|
|
113
|
+
const projectDir = '/test/project';
|
|
114
|
+
const lintLocation = path.join(projectDir, 'component1');
|
|
115
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
116
|
+
projectDir,
|
|
117
|
+
projectConfig: null,
|
|
118
|
+
});
|
|
119
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
120
|
+
areAllLintPackagesInstalledSpy.mockReturnValueOnce(true);
|
|
121
|
+
await projectLintCommand.handler(args);
|
|
122
|
+
expect(lintPackagesSpy).toHaveBeenCalledWith([lintLocation], projectDir);
|
|
123
|
+
expect(promptUserSpy).not.toHaveBeenCalled();
|
|
124
|
+
expect(installPackagesSpy).not.toHaveBeenCalled();
|
|
125
|
+
});
|
|
126
|
+
it('should prompt for packages that are in package.json but not in node_modules', async () => {
|
|
127
|
+
const projectDir = '/test/project';
|
|
128
|
+
const lintLocation = path.join(projectDir, 'component1');
|
|
129
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
130
|
+
projectDir,
|
|
131
|
+
projectConfig: null,
|
|
132
|
+
});
|
|
133
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
134
|
+
areAllLintPackagesInstalledSpy
|
|
135
|
+
.mockReturnValueOnce(false) // Initial check
|
|
136
|
+
.mockReturnValueOnce(true); // After install
|
|
137
|
+
getMissingLintPackagesSpy.mockReturnValueOnce({
|
|
138
|
+
missingPackages: ['eslint', '@typescript-eslint/parser'],
|
|
139
|
+
});
|
|
140
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
141
|
+
shouldInstallPackages: true,
|
|
142
|
+
});
|
|
143
|
+
await projectLintCommand.handler(args);
|
|
144
|
+
expect(promptUserSpy).toHaveBeenCalledWith([
|
|
145
|
+
{
|
|
146
|
+
name: 'shouldInstallPackages',
|
|
147
|
+
type: 'confirm',
|
|
148
|
+
message: expect.stringContaining('component1'),
|
|
149
|
+
default: true,
|
|
150
|
+
},
|
|
151
|
+
]);
|
|
152
|
+
expect(installPackagesSpy).toHaveBeenCalledWith({
|
|
153
|
+
packages: Object.entries(REQUIRED_PACKAGES_AND_MIN_VERSIONS).map(([pkg, version]) => `${pkg}@^${version}`),
|
|
154
|
+
installLocations: [lintLocation],
|
|
155
|
+
dev: true,
|
|
156
|
+
});
|
|
157
|
+
expect(lintPackagesSpy).toHaveBeenCalledWith([lintLocation], projectDir);
|
|
158
|
+
});
|
|
159
|
+
it('should prompt to install packages not in package.json', async () => {
|
|
160
|
+
const projectDir = '/test/project';
|
|
161
|
+
const lintLocation = path.join(projectDir, 'component1');
|
|
162
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
163
|
+
projectDir,
|
|
164
|
+
projectConfig: null,
|
|
165
|
+
});
|
|
166
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
167
|
+
areAllLintPackagesInstalledSpy.mockReturnValue(false);
|
|
168
|
+
getMissingLintPackagesSpy.mockReturnValueOnce({
|
|
169
|
+
missingPackages: [
|
|
170
|
+
'eslint',
|
|
171
|
+
'@typescript-eslint/eslint-plugin',
|
|
172
|
+
'@typescript-eslint/parser',
|
|
173
|
+
],
|
|
174
|
+
});
|
|
175
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
176
|
+
shouldInstallPackages: false,
|
|
177
|
+
});
|
|
178
|
+
await projectLintCommand.handler(args);
|
|
179
|
+
expect(promptUserSpy).toHaveBeenCalledWith([
|
|
180
|
+
{
|
|
181
|
+
name: 'shouldInstallPackages',
|
|
182
|
+
type: 'confirm',
|
|
183
|
+
message: expect.stringContaining('The dependencies required'),
|
|
184
|
+
default: true,
|
|
185
|
+
},
|
|
186
|
+
]);
|
|
187
|
+
expect(uiLogger.warn).toHaveBeenCalledWith(expect.stringContaining('Skipping linting for the following directory'));
|
|
188
|
+
expect(lintPackagesSpy).not.toHaveBeenCalled();
|
|
189
|
+
});
|
|
190
|
+
it('should install packages when user confirms prompt', async () => {
|
|
191
|
+
const projectDir = '/test/project';
|
|
192
|
+
const lintLocation = path.join(projectDir, 'component1');
|
|
193
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
194
|
+
projectDir,
|
|
195
|
+
projectConfig: null,
|
|
196
|
+
});
|
|
197
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
198
|
+
areAllLintPackagesInstalledSpy
|
|
199
|
+
.mockReturnValueOnce(false) // Initial check
|
|
200
|
+
.mockReturnValueOnce(true); // After install
|
|
201
|
+
getMissingLintPackagesSpy.mockReturnValueOnce({
|
|
202
|
+
missingPackages: ['@typescript-eslint/parser'],
|
|
203
|
+
});
|
|
204
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
205
|
+
shouldInstallPackages: true,
|
|
206
|
+
});
|
|
207
|
+
await projectLintCommand.handler(args);
|
|
208
|
+
expect(installPackagesSpy).toHaveBeenCalledWith({
|
|
209
|
+
packages: Object.entries(REQUIRED_PACKAGES_AND_MIN_VERSIONS).map(([pkg, version]) => `${pkg}@^${version}`),
|
|
210
|
+
installLocations: [lintLocation],
|
|
211
|
+
dev: true,
|
|
212
|
+
});
|
|
213
|
+
expect(lintPackagesSpy).toHaveBeenCalledWith([lintLocation], projectDir);
|
|
214
|
+
});
|
|
215
|
+
it('should handle mixed scenarios: some directories ready, some needing packages', async () => {
|
|
216
|
+
const projectDir = '/test/project';
|
|
217
|
+
const lintLocation1 = path.join(projectDir, 'component1'); // All installed
|
|
218
|
+
const lintLocation2 = path.join(projectDir, 'component2'); // Needs packages
|
|
219
|
+
const lintLocation3 = path.join(projectDir, 'component3'); // Needs packages
|
|
220
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
221
|
+
projectDir,
|
|
222
|
+
projectConfig: null,
|
|
223
|
+
});
|
|
224
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([
|
|
225
|
+
lintLocation1,
|
|
226
|
+
lintLocation2,
|
|
227
|
+
lintLocation3,
|
|
228
|
+
]);
|
|
229
|
+
areAllLintPackagesInstalledSpy
|
|
230
|
+
.mockReturnValueOnce(true) // component1 is ready
|
|
231
|
+
.mockReturnValueOnce(false) // component2 needs work
|
|
232
|
+
.mockReturnValueOnce(false); // component3 needs work
|
|
233
|
+
getMissingLintPackagesSpy
|
|
234
|
+
.mockReturnValueOnce({
|
|
235
|
+
missingPackages: ['eslint'],
|
|
236
|
+
}) // component2
|
|
237
|
+
.mockReturnValueOnce({
|
|
238
|
+
missingPackages: ['@typescript-eslint/parser'],
|
|
239
|
+
}); // component3
|
|
240
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
241
|
+
shouldInstallPackages: false,
|
|
242
|
+
});
|
|
243
|
+
await projectLintCommand.handler(args);
|
|
244
|
+
// Should prompt for both component2 and component3
|
|
245
|
+
expect(promptUserSpy).toHaveBeenCalledWith([
|
|
246
|
+
{
|
|
247
|
+
name: 'shouldInstallPackages',
|
|
248
|
+
type: 'confirm',
|
|
249
|
+
message: expect.stringContaining('The dependencies required'),
|
|
250
|
+
default: true,
|
|
251
|
+
},
|
|
252
|
+
]);
|
|
253
|
+
// Should only lint component1 (user declined packages for 2 and 3)
|
|
254
|
+
expect(lintPackagesSpy).toHaveBeenCalledWith([lintLocation1], projectDir);
|
|
255
|
+
});
|
|
256
|
+
it('should show correct message for single directory', async () => {
|
|
257
|
+
const projectDir = '/test/project';
|
|
258
|
+
const lintLocation = path.join(projectDir, 'component1');
|
|
259
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
260
|
+
projectDir,
|
|
261
|
+
projectConfig: null,
|
|
262
|
+
});
|
|
263
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
264
|
+
areAllLintPackagesInstalledSpy.mockReturnValue(false);
|
|
265
|
+
getMissingLintPackagesSpy.mockReturnValueOnce({
|
|
266
|
+
missingPackages: ['eslint'],
|
|
267
|
+
});
|
|
268
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
269
|
+
shouldInstallPackages: false,
|
|
270
|
+
});
|
|
271
|
+
await projectLintCommand.handler(args);
|
|
272
|
+
expect(promptUserSpy).toHaveBeenCalledWith([
|
|
273
|
+
{
|
|
274
|
+
name: 'shouldInstallPackages',
|
|
275
|
+
type: 'confirm',
|
|
276
|
+
message: expect.stringContaining('The dependencies required'),
|
|
277
|
+
default: true,
|
|
278
|
+
},
|
|
279
|
+
]);
|
|
280
|
+
});
|
|
281
|
+
it('should show correct message for multiple directories', async () => {
|
|
282
|
+
const projectDir = '/test/project';
|
|
283
|
+
const lintLocation1 = path.join(projectDir, 'component1');
|
|
284
|
+
const lintLocation2 = path.join(projectDir, 'component2');
|
|
285
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
286
|
+
projectDir,
|
|
287
|
+
projectConfig: null,
|
|
288
|
+
});
|
|
289
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([
|
|
290
|
+
lintLocation1,
|
|
291
|
+
lintLocation2,
|
|
292
|
+
]);
|
|
293
|
+
areAllLintPackagesInstalledSpy.mockReturnValue(false);
|
|
294
|
+
getMissingLintPackagesSpy
|
|
295
|
+
.mockReturnValueOnce({
|
|
296
|
+
missingPackages: ['eslint', '@typescript-eslint/parser'],
|
|
297
|
+
})
|
|
298
|
+
.mockReturnValueOnce({
|
|
299
|
+
missingPackages: ['eslint'],
|
|
300
|
+
});
|
|
301
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
302
|
+
shouldInstallPackages: false,
|
|
303
|
+
});
|
|
304
|
+
await projectLintCommand.handler(args);
|
|
305
|
+
expect(promptUserSpy).toHaveBeenCalledWith([
|
|
306
|
+
{
|
|
307
|
+
name: 'shouldInstallPackages',
|
|
308
|
+
type: 'confirm',
|
|
309
|
+
message: expect.stringContaining('The dependencies required'),
|
|
310
|
+
default: true,
|
|
311
|
+
},
|
|
312
|
+
]);
|
|
313
|
+
});
|
|
314
|
+
it('should only lint directories where all packages are successfully installed', async () => {
|
|
315
|
+
const projectDir = '/test/project';
|
|
316
|
+
const lintLocation1 = path.join(projectDir, 'component1');
|
|
317
|
+
const lintLocation2 = path.join(projectDir, 'component2');
|
|
318
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
319
|
+
projectDir,
|
|
320
|
+
projectConfig: null,
|
|
321
|
+
});
|
|
322
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([
|
|
323
|
+
lintLocation1,
|
|
324
|
+
lintLocation2,
|
|
325
|
+
]);
|
|
326
|
+
areAllLintPackagesInstalledSpy
|
|
327
|
+
.mockReturnValueOnce(false) // component1 initial
|
|
328
|
+
.mockReturnValueOnce(false) // component2 initial
|
|
329
|
+
.mockReturnValueOnce(true) // component1 after install (success)
|
|
330
|
+
.mockReturnValueOnce(false); // component2 after install (failed)
|
|
331
|
+
getMissingLintPackagesSpy
|
|
332
|
+
.mockReturnValueOnce({
|
|
333
|
+
missingPackages: ['eslint'],
|
|
334
|
+
})
|
|
335
|
+
.mockReturnValueOnce({
|
|
336
|
+
missingPackages: ['eslint'],
|
|
337
|
+
});
|
|
338
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
339
|
+
shouldInstallPackages: true,
|
|
340
|
+
});
|
|
341
|
+
await projectLintCommand.handler(args);
|
|
342
|
+
// Should only lint component1 since component2 failed installation
|
|
343
|
+
expect(lintPackagesSpy).toHaveBeenCalledWith([lintLocation1], projectDir);
|
|
344
|
+
});
|
|
345
|
+
it('should not prompt if no packages need installation', async () => {
|
|
346
|
+
const projectDir = '/test/project';
|
|
347
|
+
const lintLocation1 = path.join(projectDir, 'component1');
|
|
348
|
+
const lintLocation2 = path.join(projectDir, 'component2');
|
|
349
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
350
|
+
projectDir,
|
|
351
|
+
projectConfig: null,
|
|
352
|
+
});
|
|
353
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([
|
|
354
|
+
lintLocation1,
|
|
355
|
+
lintLocation2,
|
|
356
|
+
]);
|
|
357
|
+
areAllLintPackagesInstalledSpy
|
|
358
|
+
.mockReturnValueOnce(true)
|
|
359
|
+
.mockReturnValueOnce(true);
|
|
360
|
+
await projectLintCommand.handler(args);
|
|
361
|
+
expect(promptUserSpy).not.toHaveBeenCalled();
|
|
362
|
+
expect(installPackagesSpy).not.toHaveBeenCalled();
|
|
363
|
+
expect(lintPackagesSpy).toHaveBeenCalledWith([lintLocation1, lintLocation2], projectDir);
|
|
364
|
+
});
|
|
365
|
+
it('should handle empty project (no packages)', async () => {
|
|
366
|
+
const projectDir = '/test/project';
|
|
367
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
368
|
+
projectDir,
|
|
369
|
+
projectConfig: null,
|
|
370
|
+
});
|
|
371
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([]);
|
|
372
|
+
await projectLintCommand.handler(args);
|
|
373
|
+
expect(lintPackagesSpy).not.toHaveBeenCalled();
|
|
374
|
+
expect(promptUserSpy).not.toHaveBeenCalled();
|
|
375
|
+
expect(installPackagesSpy).not.toHaveBeenCalled();
|
|
376
|
+
});
|
|
377
|
+
it('should use relative paths in prompt messages', async () => {
|
|
378
|
+
const projectDir = '/test/project';
|
|
379
|
+
const lintLocation = path.join(projectDir, 'src', 'app', 'component1');
|
|
380
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
381
|
+
projectDir,
|
|
382
|
+
projectConfig: null,
|
|
383
|
+
});
|
|
384
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
385
|
+
areAllLintPackagesInstalledSpy.mockReturnValue(false);
|
|
386
|
+
getMissingLintPackagesSpy.mockReturnValueOnce({
|
|
387
|
+
missingPackages: ['eslint'],
|
|
388
|
+
});
|
|
389
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
390
|
+
shouldInstallPackages: false,
|
|
391
|
+
});
|
|
392
|
+
await projectLintCommand.handler(args);
|
|
393
|
+
expect(promptUserSpy).toHaveBeenCalledWith([
|
|
394
|
+
{
|
|
395
|
+
name: 'shouldInstallPackages',
|
|
396
|
+
type: 'confirm',
|
|
397
|
+
message: expect.stringContaining('src/app/component1'),
|
|
398
|
+
default: true,
|
|
399
|
+
},
|
|
400
|
+
]);
|
|
401
|
+
});
|
|
402
|
+
it('should prompt to create ESLint config if not present', async () => {
|
|
403
|
+
const projectDir = '/test/project';
|
|
404
|
+
const lintLocation = path.join(projectDir, 'component1');
|
|
405
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
406
|
+
projectDir,
|
|
407
|
+
projectConfig: null,
|
|
408
|
+
});
|
|
409
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
410
|
+
areAllLintPackagesInstalledSpy.mockReturnValue(true);
|
|
411
|
+
hasEslintConfigSpy.mockReturnValue(false);
|
|
412
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
413
|
+
shouldCreateConfig: true,
|
|
414
|
+
});
|
|
415
|
+
await projectLintCommand.handler(args);
|
|
416
|
+
expect(hasEslintConfigSpy).toHaveBeenCalledWith(lintLocation);
|
|
417
|
+
expect(promptUserSpy).toHaveBeenCalledWith([
|
|
418
|
+
{
|
|
419
|
+
name: 'shouldCreateConfig',
|
|
420
|
+
type: 'confirm',
|
|
421
|
+
message: expect.stringContaining('ESLint configuration file not found'),
|
|
422
|
+
default: true,
|
|
423
|
+
},
|
|
424
|
+
]);
|
|
425
|
+
expect(createEslintConfigSpy).toHaveBeenCalledWith(lintLocation);
|
|
426
|
+
expect(lintPackagesSpy).toHaveBeenCalledWith([lintLocation], projectDir);
|
|
427
|
+
});
|
|
428
|
+
it('should exit if user declines to create ESLint config', async () => {
|
|
429
|
+
const projectDir = '/test/project';
|
|
430
|
+
const lintLocation = path.join(projectDir, 'component1');
|
|
431
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
432
|
+
projectDir,
|
|
433
|
+
projectConfig: null,
|
|
434
|
+
});
|
|
435
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
436
|
+
areAllLintPackagesInstalledSpy.mockReturnValue(true);
|
|
437
|
+
hasEslintConfigSpy.mockReturnValue(false);
|
|
438
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
439
|
+
shouldCreateConfig: false,
|
|
440
|
+
});
|
|
441
|
+
await projectLintCommand.handler(args);
|
|
442
|
+
expect(createEslintConfigSpy).not.toHaveBeenCalled();
|
|
443
|
+
expect(lintPackagesSpy).not.toHaveBeenCalled();
|
|
444
|
+
expect(uiLogger.error).toHaveBeenCalledWith('ESLint configuration is required to run the lint command. Run the command again to create the configuration.');
|
|
445
|
+
expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
446
|
+
});
|
|
447
|
+
it('should not prompt for config if it already exists', async () => {
|
|
448
|
+
const projectDir = '/test/project';
|
|
449
|
+
const lintLocation = path.join(projectDir, 'component1');
|
|
450
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
451
|
+
projectDir,
|
|
452
|
+
projectConfig: null,
|
|
453
|
+
});
|
|
454
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
455
|
+
areAllLintPackagesInstalledSpy.mockReturnValue(true);
|
|
456
|
+
hasEslintConfigSpy.mockReturnValue(true);
|
|
457
|
+
await projectLintCommand.handler(args);
|
|
458
|
+
expect(promptUserSpy).not.toHaveBeenCalled();
|
|
459
|
+
expect(createEslintConfigSpy).not.toHaveBeenCalled();
|
|
460
|
+
expect(lintPackagesSpy).toHaveBeenCalledWith([lintLocation], projectDir);
|
|
461
|
+
});
|
|
462
|
+
it('should handle multiple directories without configs', async () => {
|
|
463
|
+
const projectDir = '/test/project';
|
|
464
|
+
const lintLocation1 = path.join(projectDir, 'component1');
|
|
465
|
+
const lintLocation2 = path.join(projectDir, 'component2');
|
|
466
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
467
|
+
projectDir,
|
|
468
|
+
projectConfig: null,
|
|
469
|
+
});
|
|
470
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([
|
|
471
|
+
lintLocation1,
|
|
472
|
+
lintLocation2,
|
|
473
|
+
]);
|
|
474
|
+
areAllLintPackagesInstalledSpy.mockReturnValue(true);
|
|
475
|
+
hasEslintConfigSpy.mockReturnValue(false);
|
|
476
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
477
|
+
shouldCreateConfig: true,
|
|
478
|
+
});
|
|
479
|
+
await projectLintCommand.handler(args);
|
|
480
|
+
expect(createEslintConfigSpy).toHaveBeenCalledTimes(2);
|
|
481
|
+
expect(createEslintConfigSpy).toHaveBeenCalledWith(lintLocation1);
|
|
482
|
+
expect(createEslintConfigSpy).toHaveBeenCalledWith(lintLocation2);
|
|
483
|
+
});
|
|
484
|
+
it('should warn and create new config if deprecated config exists', async () => {
|
|
485
|
+
const projectDir = '/test/project';
|
|
486
|
+
const lintLocation = path.join(projectDir, 'component1');
|
|
487
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
488
|
+
projectDir,
|
|
489
|
+
projectConfig: null,
|
|
490
|
+
});
|
|
491
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
492
|
+
areAllLintPackagesInstalledSpy.mockReturnValue(true);
|
|
493
|
+
hasEslintConfigSpy.mockReturnValue(false); // No modern config initially
|
|
494
|
+
hasDeprecatedEslintConfigSpy.mockReturnValue(true);
|
|
495
|
+
getDeprecatedEslintConfigFilesSpy.mockReturnValue([
|
|
496
|
+
'.eslintrc.js',
|
|
497
|
+
'.eslintrc.json',
|
|
498
|
+
]);
|
|
499
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
500
|
+
shouldCreateConfig: true,
|
|
501
|
+
});
|
|
502
|
+
await projectLintCommand.handler(args);
|
|
503
|
+
expect(hasEslintConfigSpy).toHaveBeenCalledWith(lintLocation);
|
|
504
|
+
expect(hasDeprecatedEslintConfigSpy).toHaveBeenCalledWith(lintLocation);
|
|
505
|
+
expect(getDeprecatedEslintConfigFilesSpy).toHaveBeenCalledWith(lintLocation);
|
|
506
|
+
expect(uiLogger.warn).toHaveBeenCalledWith(expect.stringContaining('Deprecated ESLint configuration'));
|
|
507
|
+
// Should prompt because !hasModernConfig is checked
|
|
508
|
+
expect(promptUserSpy).toHaveBeenCalledWith([
|
|
509
|
+
{
|
|
510
|
+
name: 'shouldCreateConfig',
|
|
511
|
+
type: 'confirm',
|
|
512
|
+
message: expect.stringContaining('component1'),
|
|
513
|
+
default: true,
|
|
514
|
+
},
|
|
515
|
+
]);
|
|
516
|
+
// Creates config once from prompt
|
|
517
|
+
expect(createEslintConfigSpy).toHaveBeenCalledWith(lintLocation);
|
|
518
|
+
expect(createEslintConfigSpy).toHaveBeenCalledTimes(1);
|
|
519
|
+
expect(lintPackagesSpy).toHaveBeenCalledWith([lintLocation], projectDir);
|
|
520
|
+
});
|
|
521
|
+
it('should handle multiple directories with deprecated configs', async () => {
|
|
522
|
+
const projectDir = '/test/project';
|
|
523
|
+
const lintLocation1 = path.join(projectDir, 'component1');
|
|
524
|
+
const lintLocation2 = path.join(projectDir, 'component2');
|
|
525
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
526
|
+
projectDir,
|
|
527
|
+
projectConfig: null,
|
|
528
|
+
});
|
|
529
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([
|
|
530
|
+
lintLocation1,
|
|
531
|
+
lintLocation2,
|
|
532
|
+
]);
|
|
533
|
+
areAllLintPackagesInstalledSpy.mockReturnValue(true);
|
|
534
|
+
hasEslintConfigSpy.mockReturnValue(false); // No modern configs initially
|
|
535
|
+
hasDeprecatedEslintConfigSpy.mockReturnValue(true);
|
|
536
|
+
getDeprecatedEslintConfigFilesSpy
|
|
537
|
+
.mockReturnValueOnce(['.eslintrc.js'])
|
|
538
|
+
.mockReturnValueOnce(['.eslintrc.json']);
|
|
539
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
540
|
+
shouldCreateConfig: true,
|
|
541
|
+
});
|
|
542
|
+
await projectLintCommand.handler(args);
|
|
543
|
+
expect(hasEslintConfigSpy).toHaveBeenCalledTimes(2);
|
|
544
|
+
expect(hasDeprecatedEslintConfigSpy).toHaveBeenCalledTimes(2);
|
|
545
|
+
expect(uiLogger.warn).toHaveBeenCalledWith(expect.stringContaining('Deprecated ESLint configuration'));
|
|
546
|
+
// Should prompt for both locations since both lack modern config
|
|
547
|
+
expect(promptUserSpy).toHaveBeenCalledWith([
|
|
548
|
+
{
|
|
549
|
+
name: 'shouldCreateConfig',
|
|
550
|
+
type: 'confirm',
|
|
551
|
+
message: expect.stringContaining('component1'),
|
|
552
|
+
default: true,
|
|
553
|
+
},
|
|
554
|
+
]);
|
|
555
|
+
// Creates configs from prompt
|
|
556
|
+
expect(createEslintConfigSpy).toHaveBeenCalledTimes(2);
|
|
557
|
+
expect(createEslintConfigSpy).toHaveBeenCalledWith(lintLocation1);
|
|
558
|
+
expect(createEslintConfigSpy).toHaveBeenCalledWith(lintLocation2);
|
|
559
|
+
});
|
|
560
|
+
it('should not warn about deprecated configs if none exist', async () => {
|
|
561
|
+
const projectDir = '/test/project';
|
|
562
|
+
const lintLocation = path.join(projectDir, 'component1');
|
|
563
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
564
|
+
projectDir,
|
|
565
|
+
projectConfig: null,
|
|
566
|
+
});
|
|
567
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
568
|
+
areAllLintPackagesInstalledSpy.mockReturnValue(true);
|
|
569
|
+
hasDeprecatedEslintConfigSpy.mockReturnValue(false);
|
|
570
|
+
hasEslintConfigSpy.mockReturnValue(true);
|
|
571
|
+
await projectLintCommand.handler(args);
|
|
572
|
+
expect(getDeprecatedEslintConfigFilesSpy).not.toHaveBeenCalled();
|
|
573
|
+
expect(lintPackagesSpy).toHaveBeenCalledWith([lintLocation], projectDir);
|
|
574
|
+
});
|
|
575
|
+
it('should handle mixed scenario: some dirs with deprecated configs, others without any config', async () => {
|
|
576
|
+
const projectDir = '/test/project';
|
|
577
|
+
const lintLocation1 = path.join(projectDir, 'component1'); // Has deprecated config
|
|
578
|
+
const lintLocation2 = path.join(projectDir, 'component2'); // Has no config
|
|
579
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
580
|
+
projectDir,
|
|
581
|
+
projectConfig: null,
|
|
582
|
+
});
|
|
583
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([
|
|
584
|
+
lintLocation1,
|
|
585
|
+
lintLocation2,
|
|
586
|
+
]);
|
|
587
|
+
areAllLintPackagesInstalledSpy.mockReturnValue(true);
|
|
588
|
+
hasEslintConfigSpy.mockReturnValue(false); // No modern configs initially
|
|
589
|
+
hasDeprecatedEslintConfigSpy.mockImplementation(dir => {
|
|
590
|
+
return dir === lintLocation1; // Only location1 has deprecated config
|
|
591
|
+
});
|
|
592
|
+
getDeprecatedEslintConfigFilesSpy.mockReturnValue(['.eslintrc.js']);
|
|
593
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
594
|
+
shouldCreateConfig: true,
|
|
595
|
+
});
|
|
596
|
+
await projectLintCommand.handler(args);
|
|
597
|
+
// Should check both locations
|
|
598
|
+
expect(hasEslintConfigSpy).toHaveBeenCalledTimes(2);
|
|
599
|
+
expect(hasDeprecatedEslintConfigSpy).toHaveBeenCalledTimes(2);
|
|
600
|
+
// Should warn about deprecated config in location1
|
|
601
|
+
expect(uiLogger.warn).toHaveBeenCalledWith(expect.stringContaining('Deprecated ESLint configuration'));
|
|
602
|
+
// Should prompt for both locations (both lack modern config)
|
|
603
|
+
expect(promptUserSpy).toHaveBeenCalledWith([
|
|
604
|
+
{
|
|
605
|
+
name: 'shouldCreateConfig',
|
|
606
|
+
type: 'confirm',
|
|
607
|
+
message: expect.stringContaining('component'),
|
|
608
|
+
default: true,
|
|
609
|
+
},
|
|
610
|
+
]);
|
|
611
|
+
// Should create configs for both from prompt
|
|
612
|
+
expect(createEslintConfigSpy).toHaveBeenCalledWith(lintLocation1);
|
|
613
|
+
expect(createEslintConfigSpy).toHaveBeenCalledWith(lintLocation2);
|
|
614
|
+
expect(createEslintConfigSpy).toHaveBeenCalledTimes(2);
|
|
615
|
+
expect(lintPackagesSpy).toHaveBeenCalledWith([lintLocation1, lintLocation2], projectDir);
|
|
616
|
+
});
|
|
617
|
+
it('should install missing packages without prompting when --install-missing-deps is true', async () => {
|
|
618
|
+
const projectDir = '/test/project';
|
|
619
|
+
const lintLocation = path.join(projectDir, 'component1');
|
|
620
|
+
args.installMissingDeps = true;
|
|
621
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
622
|
+
projectDir,
|
|
623
|
+
projectConfig: null,
|
|
624
|
+
});
|
|
625
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
626
|
+
areAllLintPackagesInstalledSpy
|
|
627
|
+
.mockReturnValueOnce(false) // Initial check
|
|
628
|
+
.mockReturnValueOnce(true); // After install
|
|
629
|
+
getMissingLintPackagesSpy.mockReturnValueOnce({
|
|
630
|
+
missingPackages: ['eslint', '@typescript-eslint/parser'],
|
|
631
|
+
});
|
|
632
|
+
await projectLintCommand.handler(args);
|
|
633
|
+
expect(promptUserSpy).not.toHaveBeenCalled();
|
|
634
|
+
expect(installPackagesSpy).toHaveBeenCalledWith({
|
|
635
|
+
packages: Object.entries(REQUIRED_PACKAGES_AND_MIN_VERSIONS).map(([pkg, version]) => `${pkg}@^${version}`),
|
|
636
|
+
installLocations: [lintLocation],
|
|
637
|
+
dev: true,
|
|
638
|
+
});
|
|
639
|
+
expect(lintPackagesSpy).toHaveBeenCalledWith([lintLocation], projectDir);
|
|
640
|
+
});
|
|
641
|
+
it('should skip installing missing packages without prompting when --install-missing-deps is false', async () => {
|
|
642
|
+
const projectDir = '/test/project';
|
|
643
|
+
const lintLocation = path.join(projectDir, 'component1');
|
|
644
|
+
args.installMissingDeps = false;
|
|
645
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
646
|
+
projectDir,
|
|
647
|
+
projectConfig: null,
|
|
648
|
+
});
|
|
649
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
650
|
+
areAllLintPackagesInstalledSpy.mockReturnValueOnce(false);
|
|
651
|
+
getMissingLintPackagesSpy.mockReturnValueOnce({
|
|
652
|
+
missingPackages: ['eslint', '@typescript-eslint/parser'],
|
|
653
|
+
});
|
|
654
|
+
await projectLintCommand.handler(args);
|
|
655
|
+
expect(promptUserSpy).not.toHaveBeenCalled();
|
|
656
|
+
expect(installPackagesSpy).not.toHaveBeenCalled();
|
|
657
|
+
expect(uiLogger.warn).toHaveBeenCalledWith(expect.stringContaining('component1'));
|
|
658
|
+
expect(lintPackagesSpy).not.toHaveBeenCalled();
|
|
659
|
+
});
|
|
660
|
+
it('should prompt for installation when --install-missing-deps is not provided', async () => {
|
|
661
|
+
const projectDir = '/test/project';
|
|
662
|
+
const lintLocation = path.join(projectDir, 'component1');
|
|
663
|
+
// installMissingDeps is undefined
|
|
664
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
665
|
+
projectDir,
|
|
666
|
+
projectConfig: null,
|
|
667
|
+
});
|
|
668
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
669
|
+
areAllLintPackagesInstalledSpy
|
|
670
|
+
.mockReturnValueOnce(false) // Initial check
|
|
671
|
+
.mockReturnValueOnce(true); // After install
|
|
672
|
+
getMissingLintPackagesSpy.mockReturnValueOnce({
|
|
673
|
+
missingPackages: ['eslint', '@typescript-eslint/parser'],
|
|
674
|
+
});
|
|
675
|
+
promptUserSpy.mockResolvedValueOnce({
|
|
676
|
+
shouldInstallPackages: true,
|
|
677
|
+
});
|
|
678
|
+
await projectLintCommand.handler(args);
|
|
679
|
+
expect(promptUserSpy).toHaveBeenCalledWith([
|
|
680
|
+
{
|
|
681
|
+
name: 'shouldInstallPackages',
|
|
682
|
+
type: 'confirm',
|
|
683
|
+
message: expect.stringContaining('component1'),
|
|
684
|
+
default: true,
|
|
685
|
+
},
|
|
686
|
+
]);
|
|
687
|
+
expect(installPackagesSpy).toHaveBeenCalledWith({
|
|
688
|
+
packages: Object.entries(REQUIRED_PACKAGES_AND_MIN_VERSIONS).map(([pkg, version]) => `${pkg}@^${version}`),
|
|
689
|
+
installLocations: [lintLocation],
|
|
690
|
+
dev: true,
|
|
691
|
+
});
|
|
692
|
+
expect(lintPackagesSpy).toHaveBeenCalledWith([lintLocation], projectDir);
|
|
693
|
+
});
|
|
694
|
+
it('should exit with error code when linting fails', async () => {
|
|
695
|
+
const projectDir = '/test/project';
|
|
696
|
+
const lintLocation = path.join(projectDir, 'component1');
|
|
697
|
+
getProjectConfigSpy.mockResolvedValue({
|
|
698
|
+
projectDir,
|
|
699
|
+
projectConfig: null,
|
|
700
|
+
});
|
|
701
|
+
getProjectPackageJsonLocationsSpy.mockResolvedValue([lintLocation]);
|
|
702
|
+
areAllLintPackagesInstalledSpy.mockReturnValue(true);
|
|
703
|
+
lintPackagesSpy.mockResolvedValueOnce({ success: false, results: [] }); // Linting fails
|
|
704
|
+
await projectLintCommand.handler(args);
|
|
705
|
+
expect(lintPackagesSpy).toHaveBeenCalledWith([lintLocation], projectDir);
|
|
706
|
+
expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
707
|
+
});
|
|
708
|
+
});
|
|
709
|
+
});
|