@hubspot/ui-extensions-dev-server 0.10.2 → 1.0.1
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 +23 -4
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -45
- package/dist/lib/DevModeInterface.d.ts +2 -2
- package/dist/lib/DevModeInterface.js +12 -28
- package/dist/lib/DevModeParentInterface.d.ts +2 -2
- package/dist/lib/DevModeParentInterface.js +138 -154
- package/dist/lib/DevModeUnifiedInterface.d.ts +2 -2
- package/dist/lib/DevModeUnifiedInterface.js +28 -49
- package/dist/lib/DevServerState.d.ts +9 -5
- package/dist/lib/DevServerState.js +37 -18
- package/dist/lib/ExtensionsWebSocket.d.ts +25 -0
- package/dist/lib/ExtensionsWebSocket.js +110 -0
- package/dist/lib/__mocks__/config.d.ts +2 -0
- package/dist/lib/__mocks__/config.js +5 -0
- package/dist/lib/__mocks__/isExtensionFile.d.ts +5 -0
- package/dist/lib/__mocks__/isExtensionFile.js +11 -0
- package/dist/lib/__tests__/DevModeInterface.spec.d.ts +1 -0
- package/dist/lib/__tests__/DevModeInterface.spec.js +155 -0
- package/dist/lib/__tests__/DevModeParentInterface.spec.d.ts +1 -0
- package/dist/lib/__tests__/DevModeParentInterface.spec.js +179 -0
- package/dist/lib/__tests__/DevModeUnifiedInterface.spec.d.ts +1 -0
- package/dist/lib/__tests__/DevModeUnifiedInterface.spec.js +236 -0
- package/dist/lib/__tests__/ExtensionsWebSocket.spec.d.ts +1 -0
- package/dist/lib/__tests__/ExtensionsWebSocket.spec.js +304 -0
- package/dist/lib/__tests__/ast.spec.d.ts +1 -0
- package/dist/lib/__tests__/ast.spec.js +737 -0
- package/dist/lib/__tests__/build.spec.d.ts +1 -0
- package/dist/lib/__tests__/build.spec.js +159 -0
- package/dist/lib/__tests__/config.spec.d.ts +1 -0
- package/dist/lib/__tests__/config.spec.js +291 -0
- package/dist/lib/__tests__/dev.spec.d.ts +1 -0
- package/dist/lib/__tests__/dev.spec.js +80 -0
- package/dist/lib/__tests__/extensionsService.spec.d.ts +1 -0
- package/dist/lib/__tests__/extensionsService.spec.js +150 -0
- package/dist/lib/__tests__/factories.d.ts +48 -0
- package/dist/lib/__tests__/factories.js +32 -0
- package/dist/lib/__tests__/fixtures/extensionConfig.d.ts +182 -0
- package/dist/lib/__tests__/fixtures/extensionConfig.js +304 -0
- package/dist/lib/__tests__/fixtures/urls.d.ts +4 -0
- package/dist/lib/__tests__/fixtures/urls.js +4 -0
- package/dist/lib/__tests__/parsing-utils.spec.d.ts +1 -0
- package/dist/lib/__tests__/parsing-utils.spec.js +467 -0
- package/dist/lib/__tests__/plugins/codeBlockingPlugin.spec.d.ts +1 -0
- package/dist/lib/__tests__/plugins/codeBlockingPlugin.spec.js +112 -0
- package/dist/lib/__tests__/plugins/codeCheckingPlugin.spec.d.ts +1 -0
- package/dist/lib/__tests__/plugins/codeCheckingPlugin.spec.js +82 -0
- package/dist/lib/__tests__/plugins/devBuildPlugin.spec.d.ts +1 -0
- package/dist/lib/__tests__/plugins/devBuildPlugin.spec.js +256 -0
- package/dist/lib/__tests__/plugins/friendlyLoggingPlugin.spec.d.ts +1 -0
- package/dist/lib/__tests__/plugins/friendlyLoggingPlugin.spec.js +65 -0
- package/dist/lib/__tests__/plugins/manifestPlugin.spec.d.ts +1 -0
- package/dist/lib/__tests__/plugins/manifestPlugin.spec.js +455 -0
- package/dist/lib/__tests__/plugins/relevantModulesPlugin.spec.d.ts +1 -0
- package/dist/lib/__tests__/plugins/relevantModulesPlugin.spec.js +81 -0
- package/dist/lib/__tests__/server.spec.d.ts +1 -0
- package/dist/lib/__tests__/server.spec.js +152 -0
- package/dist/lib/__tests__/test-utils/ast.d.ts +1 -0
- package/dist/lib/__tests__/test-utils/ast.js +4 -0
- package/dist/lib/__tests__/utils.spec.d.ts +1 -0
- package/dist/lib/__tests__/utils.spec.js +176 -0
- package/dist/lib/ast.d.ts +1 -1
- package/dist/lib/ast.js +22 -29
- package/dist/lib/bin/cli.js +52 -72
- package/dist/lib/build.d.ts +1 -1
- package/dist/lib/build.js +60 -78
- package/dist/lib/config.d.ts +1 -1
- package/dist/lib/config.js +31 -34
- package/dist/lib/constants.d.ts +0 -2
- package/dist/lib/constants.js +20 -27
- package/dist/lib/dev.d.ts +1 -1
- package/dist/lib/dev.js +52 -69
- package/dist/lib/extensionsService.d.ts +1 -1
- package/dist/lib/extensionsService.js +21 -15
- package/dist/lib/parsing-utils.d.ts +1 -1
- package/dist/lib/parsing-utils.js +7 -11
- package/dist/lib/plugins/codeBlockingPlugin.d.ts +1 -1
- package/dist/lib/plugins/codeBlockingPlugin.js +5 -8
- package/dist/lib/plugins/codeCheckingPlugin.d.ts +1 -1
- package/dist/lib/plugins/codeCheckingPlugin.js +10 -11
- package/dist/lib/plugins/devBuildPlugin.d.ts +2 -2
- package/dist/lib/plugins/devBuildPlugin.js +74 -99
- package/dist/lib/plugins/friendlyLoggingPlugin.d.ts +2 -2
- package/dist/lib/plugins/friendlyLoggingPlugin.js +4 -12
- package/dist/lib/plugins/manifestPlugin.d.ts +1 -1
- package/dist/lib/plugins/manifestPlugin.js +46 -26
- package/dist/lib/plugins/relevantModulesPlugin.d.ts +2 -2
- package/dist/lib/plugins/relevantModulesPlugin.js +4 -7
- package/dist/lib/server.d.ts +7 -2
- package/dist/lib/server.js +85 -84
- package/dist/lib/types.d.ts +1 -1
- package/dist/lib/types.js +4 -7
- package/dist/lib/utils.d.ts +1 -1
- package/dist/lib/utils.js +23 -40
- package/package.json +44 -31
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeAll, afterAll, beforeEach, } from 'vitest';
|
|
2
|
+
import DevModeInterface from "../DevModeInterface.js";
|
|
3
|
+
import { cardConfig } from "./fixtures/extensionConfig.js";
|
|
4
|
+
import { DevServerState } from "../DevServerState.js";
|
|
5
|
+
import { EXPRESS_DEFAULT_PORT, EXPRESS_SERVER_ID, PLATFORM_VERSION, } from "../constants.js";
|
|
6
|
+
import { urls } from "./fixtures/urls.js";
|
|
7
|
+
import { localConfig } from "../__mocks__/config.js";
|
|
8
|
+
vi.mock('../config.ts', () => ({
|
|
9
|
+
loadLocalConfig: vi.fn(() => localConfig),
|
|
10
|
+
buildSourceId: vi.fn(),
|
|
11
|
+
getUrlSafeFileName: vi.fn(),
|
|
12
|
+
}));
|
|
13
|
+
vi.mock('../dev.ts', () => ({
|
|
14
|
+
startDevMode: vi.fn(() => {
|
|
15
|
+
return function () { };
|
|
16
|
+
}),
|
|
17
|
+
}));
|
|
18
|
+
import { loadLocalConfig } from "../config.js";
|
|
19
|
+
import { startDevMode } from "../dev.js";
|
|
20
|
+
const accountId = 12345;
|
|
21
|
+
describe('DevModeUnifiedInterface', () => {
|
|
22
|
+
let consoleMock;
|
|
23
|
+
let logger;
|
|
24
|
+
beforeAll(() => {
|
|
25
|
+
consoleMock = vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
|
26
|
+
});
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
vi.clearAllMocks();
|
|
29
|
+
DevModeInterface._reset();
|
|
30
|
+
DevModeInterface.logger = logger;
|
|
31
|
+
logger = {
|
|
32
|
+
info: vi.fn(),
|
|
33
|
+
debug: vi.fn(),
|
|
34
|
+
warn: vi.fn(),
|
|
35
|
+
error: vi.fn(),
|
|
36
|
+
};
|
|
37
|
+
DevModeInterface.logger = logger;
|
|
38
|
+
});
|
|
39
|
+
afterAll(() => {
|
|
40
|
+
consoleMock.mockRestore();
|
|
41
|
+
});
|
|
42
|
+
describe('start', () => {
|
|
43
|
+
it('should not start the dev server again if it has already been started', () => {
|
|
44
|
+
const requestPorts = vi.fn();
|
|
45
|
+
DevModeInterface.isRunning = true;
|
|
46
|
+
DevModeInterface.start({ requestPorts });
|
|
47
|
+
expect(logger.debug).toHaveBeenCalledWith('Dev server is already running, not starting again');
|
|
48
|
+
expect(requestPorts).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
it('should use the values returned from requestPorts for the service ports', async () => {
|
|
51
|
+
DevModeInterface.configs = [cardConfig];
|
|
52
|
+
DevModeInterface.urls = urls;
|
|
53
|
+
const ports = {
|
|
54
|
+
[EXPRESS_SERVER_ID]: 8675309,
|
|
55
|
+
};
|
|
56
|
+
const requestPorts = vi.fn().mockReturnValue(ports);
|
|
57
|
+
await DevModeInterface.start({
|
|
58
|
+
accountId,
|
|
59
|
+
requestPorts,
|
|
60
|
+
});
|
|
61
|
+
expect(requestPorts).toHaveBeenCalledTimes(1);
|
|
62
|
+
expect(DevModeInterface.devServerState.expressPort).toBe(ports[EXPRESS_SERVER_ID]);
|
|
63
|
+
});
|
|
64
|
+
it('should use the default ports when the call to requestPorts fails', async () => {
|
|
65
|
+
DevModeInterface.logger = logger;
|
|
66
|
+
DevModeInterface.configs = [cardConfig];
|
|
67
|
+
DevModeInterface.urls = urls;
|
|
68
|
+
const requestPorts = vi.fn().mockImplementation(() => {
|
|
69
|
+
throw new Error("AH AH AH, YOU DIDN'T SAY THE MAGIC WORD");
|
|
70
|
+
});
|
|
71
|
+
await DevModeInterface.start({
|
|
72
|
+
accountId,
|
|
73
|
+
requestPorts,
|
|
74
|
+
});
|
|
75
|
+
expect(requestPorts).toHaveBeenCalledTimes(1);
|
|
76
|
+
expect(logger.debug).toHaveBeenCalledWith('Call to port manager failed, using default ports');
|
|
77
|
+
expect(DevModeInterface.devServerState.expressPort).toBe(EXPRESS_DEFAULT_PORT);
|
|
78
|
+
});
|
|
79
|
+
it('should load the local config', async () => {
|
|
80
|
+
DevModeInterface.configs = [cardConfig];
|
|
81
|
+
DevModeInterface.urls = urls;
|
|
82
|
+
const accountId = 12345;
|
|
83
|
+
await DevModeInterface.start({
|
|
84
|
+
accountId,
|
|
85
|
+
});
|
|
86
|
+
expect(loadLocalConfig).toHaveBeenCalledTimes(1);
|
|
87
|
+
expect(loadLocalConfig).toHaveBeenCalledWith(DevModeInterface.configs[0].path, DevModeInterface.logger);
|
|
88
|
+
expect(DevModeInterface.devServerState?.localDevUrlMapping).toEqual(localConfig.proxy);
|
|
89
|
+
});
|
|
90
|
+
it('should not call startDevMode if it is unable to load the extension config', async () => {
|
|
91
|
+
DevModeInterface.configs = undefined;
|
|
92
|
+
const errorMessage = 'Unable to load the required extension configuration files';
|
|
93
|
+
await expect(DevModeInterface.start({})).rejects.toThrowError(errorMessage);
|
|
94
|
+
expect(startDevMode).not.toHaveBeenCalled();
|
|
95
|
+
});
|
|
96
|
+
it('should call startDevMode', async () => {
|
|
97
|
+
DevModeInterface.configs = [cardConfig];
|
|
98
|
+
DevModeInterface.logger = logger;
|
|
99
|
+
DevModeInterface.urls = urls;
|
|
100
|
+
await DevModeInterface.start({
|
|
101
|
+
accountId,
|
|
102
|
+
});
|
|
103
|
+
const expectedState = new DevServerState({
|
|
104
|
+
localDevUrlMapping: localConfig.proxy,
|
|
105
|
+
extensionConfigs: [cardConfig],
|
|
106
|
+
accountId,
|
|
107
|
+
platformVersion: PLATFORM_VERSION.V20231,
|
|
108
|
+
expressPort: EXPRESS_DEFAULT_PORT,
|
|
109
|
+
logger,
|
|
110
|
+
urls,
|
|
111
|
+
appConfig: cardConfig.appConfig,
|
|
112
|
+
});
|
|
113
|
+
expect(startDevMode).toHaveBeenCalledTimes(1);
|
|
114
|
+
expect(startDevMode).toHaveBeenCalledWith(expectedState);
|
|
115
|
+
});
|
|
116
|
+
it('should assign the method returned from startDevMode to shutdown', async () => {
|
|
117
|
+
DevModeInterface.configs = [cardConfig];
|
|
118
|
+
DevModeInterface.urls = urls;
|
|
119
|
+
const shutdown = async () => { };
|
|
120
|
+
vi.mocked(startDevMode).mockImplementationOnce(async () => shutdown);
|
|
121
|
+
DevModeInterface.isRunning = false;
|
|
122
|
+
await DevModeInterface.start({});
|
|
123
|
+
expect(DevModeInterface.shutdown).toStrictEqual(shutdown);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe('fileChange', () => {
|
|
127
|
+
it('should call onUploadRequired when it is defined and a cardConfig is edited', () => {
|
|
128
|
+
const cardConfigPath = cardConfig.extensionConfigPath;
|
|
129
|
+
DevModeInterface.devServerState = new DevServerState({
|
|
130
|
+
extensionConfigs: [cardConfig],
|
|
131
|
+
accountId,
|
|
132
|
+
expressPort: 1234,
|
|
133
|
+
platformVersion: PLATFORM_VERSION.V20251,
|
|
134
|
+
logger,
|
|
135
|
+
urls,
|
|
136
|
+
});
|
|
137
|
+
DevModeInterface.onUploadRequired = vi.fn();
|
|
138
|
+
DevModeInterface.fileChange(cardConfigPath, '');
|
|
139
|
+
expect(DevModeInterface.onUploadRequired).toHaveBeenCalledTimes(1);
|
|
140
|
+
});
|
|
141
|
+
it('should not call onUploadRequired when it is not a card config', () => {
|
|
142
|
+
DevModeInterface.devServerState = undefined;
|
|
143
|
+
DevModeInterface.onUploadRequired = vi.fn();
|
|
144
|
+
DevModeInterface.fileChange('some/other/file.jsx', '');
|
|
145
|
+
expect(DevModeInterface.onUploadRequired).not.toHaveBeenCalled();
|
|
146
|
+
});
|
|
147
|
+
it('should not call onUploadRequired extensionConfigPath is undefined', () => {
|
|
148
|
+
DevModeInterface.onUploadRequired = vi.fn();
|
|
149
|
+
DevModeInterface.fileChange('some/other/file.jsx', '');
|
|
150
|
+
expect(DevModeInterface.onUploadRequired).not.toHaveBeenCalled();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
describe('cleanup', () => {
|
|
154
|
+
it('should call shutdown when cleanup is invoked', async () => {
|
|
155
|
+
const shutdown = vi
|
|
156
|
+
.fn()
|
|
157
|
+
.mockImplementation(() => Promise.resolve());
|
|
158
|
+
DevModeInterface.isRunning = true;
|
|
159
|
+
DevModeInterface.shutdown = shutdown;
|
|
160
|
+
await DevModeInterface.cleanup();
|
|
161
|
+
expect(shutdown).toHaveBeenCalledTimes(1);
|
|
162
|
+
});
|
|
163
|
+
it('should reset the dev server state', async () => {
|
|
164
|
+
const shutdown = vi
|
|
165
|
+
.fn()
|
|
166
|
+
.mockImplementation(() => Promise.resolve());
|
|
167
|
+
DevModeInterface.isRunning = true;
|
|
168
|
+
DevModeInterface.shutdown = shutdown;
|
|
169
|
+
await DevModeInterface.cleanup();
|
|
170
|
+
expect(DevModeInterface.configs).toBeUndefined();
|
|
171
|
+
expect(DevModeInterface.devServerState).toBeUndefined();
|
|
172
|
+
expect(DevModeInterface.onUploadRequired).toBeUndefined();
|
|
173
|
+
expect(DevModeInterface.shutdown).toBeUndefined();
|
|
174
|
+
expect(DevModeInterface.urls).toBeUndefined();
|
|
175
|
+
expect(DevModeInterface.isConfigured).toBe(false);
|
|
176
|
+
expect(DevModeInterface.isRunning).toBe(false);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach, } from 'vitest';
|
|
2
|
+
import DevModeUnifiedInterface from "../DevModeUnifiedInterface.js";
|
|
3
|
+
import { DevModeParentInterface } from "../DevModeParentInterface.js";
|
|
4
|
+
import * as config from "../config.js";
|
|
5
|
+
import { cardConfig, cardConfigTwo, transformedUnifiedAppConfig, transformedUnifiedAppConfigTwoCards, transformedUnifiedCardOneConfig, transformedUnifiedCardTwoConfig, unifiedAppConfig, unifiedCardOneConfig, unifiedCardTwoConfig, settingsExtensionConfig, settingsExtensionTransformedData, appHomesConfig, appHomesTransformedData, } from "./fixtures/extensionConfig.js";
|
|
6
|
+
import inquirer from 'inquirer';
|
|
7
|
+
import { urls } from "./fixtures/urls.js";
|
|
8
|
+
vi.mock('../config.ts', async () => {
|
|
9
|
+
const actual = await vi.importActual('../config.ts');
|
|
10
|
+
return {
|
|
11
|
+
...actual,
|
|
12
|
+
loadExtensionConfig: vi.fn(),
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
vi.mock('inquirer', () => ({
|
|
16
|
+
default: {
|
|
17
|
+
createPromptModule: vi.fn(),
|
|
18
|
+
},
|
|
19
|
+
}));
|
|
20
|
+
describe('DevModeUnifiedInterface', () => {
|
|
21
|
+
describe('setup', () => {
|
|
22
|
+
let parentSetupSpy;
|
|
23
|
+
let mockPromptModule;
|
|
24
|
+
let setActiveApp;
|
|
25
|
+
let logger;
|
|
26
|
+
const cardKey = `${unifiedAppConfig.uid}::${cardConfig.data.uid}`;
|
|
27
|
+
const components = {
|
|
28
|
+
application_name: unifiedAppConfig,
|
|
29
|
+
card_one: unifiedCardOneConfig,
|
|
30
|
+
};
|
|
31
|
+
const expectedConfig = {
|
|
32
|
+
...transformedUnifiedCardOneConfig,
|
|
33
|
+
appConfig: transformedUnifiedAppConfig,
|
|
34
|
+
};
|
|
35
|
+
const cardOneChoiceName = `${unifiedAppConfig.config.name}/${unifiedCardOneConfig.config.name}`;
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
DevModeUnifiedInterface._reset();
|
|
38
|
+
logger = {
|
|
39
|
+
info: vi.fn(),
|
|
40
|
+
debug: vi.fn(),
|
|
41
|
+
warn: vi.fn(),
|
|
42
|
+
error: vi.fn(),
|
|
43
|
+
};
|
|
44
|
+
DevModeUnifiedInterface.logger = logger;
|
|
45
|
+
mockPromptModule = vi.fn().mockResolvedValue({
|
|
46
|
+
extensions: [expectedConfig],
|
|
47
|
+
});
|
|
48
|
+
vi.mocked(inquirer.createPromptModule).mockReturnValue(mockPromptModule);
|
|
49
|
+
setActiveApp = vi.fn(() => {
|
|
50
|
+
return Promise.resolve();
|
|
51
|
+
});
|
|
52
|
+
parentSetupSpy = vi.spyOn(DevModeParentInterface.prototype, 'parentSetup');
|
|
53
|
+
vi.mocked(config.loadExtensionConfig).mockReturnValue({
|
|
54
|
+
[cardKey]: cardConfig,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
afterEach(() => {
|
|
58
|
+
vi.clearAllMocks();
|
|
59
|
+
});
|
|
60
|
+
it('should throw an error if no extensions are parsed from the provided arguments', async () => {
|
|
61
|
+
const badComponents = {
|
|
62
|
+
'not a valid application': {
|
|
63
|
+
config: {
|
|
64
|
+
name: 'I do not have an extensions object',
|
|
65
|
+
},
|
|
66
|
+
path: '/path/to/my/application',
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
await expect(DevModeUnifiedInterface.setup({
|
|
70
|
+
// @ts-expect-error - We're trying to trigger an error with bad data
|
|
71
|
+
components: badComponents,
|
|
72
|
+
logger,
|
|
73
|
+
setActiveApp,
|
|
74
|
+
urls,
|
|
75
|
+
})).rejects.toThrowError('No extensions to run');
|
|
76
|
+
});
|
|
77
|
+
it('should directly set configs when there is only one choice', async () => {
|
|
78
|
+
await DevModeUnifiedInterface.setup({
|
|
79
|
+
components,
|
|
80
|
+
logger,
|
|
81
|
+
setActiveApp,
|
|
82
|
+
urls,
|
|
83
|
+
});
|
|
84
|
+
expect(parentSetupSpy).toHaveBeenCalledWith({
|
|
85
|
+
choices: [
|
|
86
|
+
{
|
|
87
|
+
name: cardOneChoiceName,
|
|
88
|
+
value: expectedConfig,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
components,
|
|
92
|
+
logger,
|
|
93
|
+
setActiveApp,
|
|
94
|
+
urls,
|
|
95
|
+
});
|
|
96
|
+
expect(DevModeUnifiedInterface.configs).toStrictEqual([expectedConfig]);
|
|
97
|
+
});
|
|
98
|
+
it('should prompt the user when there is more than one choice', async () => {
|
|
99
|
+
const twoCardComponents = {
|
|
100
|
+
...components,
|
|
101
|
+
card_two: unifiedCardTwoConfig,
|
|
102
|
+
};
|
|
103
|
+
const cardOneKey = `${unifiedAppConfig.uid}::${unifiedCardOneConfig.uid}`;
|
|
104
|
+
const cardTwoKey = `${unifiedAppConfig.uid}::${unifiedCardTwoConfig.uid}`;
|
|
105
|
+
vi.mocked(config.loadExtensionConfig).mockReturnValue({
|
|
106
|
+
[cardOneKey]: cardConfig,
|
|
107
|
+
[cardTwoKey]: cardConfigTwo,
|
|
108
|
+
});
|
|
109
|
+
await DevModeUnifiedInterface.setup({
|
|
110
|
+
components: twoCardComponents,
|
|
111
|
+
logger,
|
|
112
|
+
setActiveApp,
|
|
113
|
+
urls,
|
|
114
|
+
});
|
|
115
|
+
expect(parentSetupSpy).toHaveBeenCalledWith({
|
|
116
|
+
choices: [
|
|
117
|
+
{
|
|
118
|
+
name: cardOneChoiceName,
|
|
119
|
+
value: {
|
|
120
|
+
...transformedUnifiedCardOneConfig,
|
|
121
|
+
appConfig: transformedUnifiedAppConfigTwoCards,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: `${unifiedAppConfig.config.name}/${unifiedCardTwoConfig.config.name}`,
|
|
126
|
+
value: {
|
|
127
|
+
...transformedUnifiedCardTwoConfig,
|
|
128
|
+
appConfig: transformedUnifiedAppConfigTwoCards,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
components: twoCardComponents,
|
|
133
|
+
logger,
|
|
134
|
+
setActiveApp,
|
|
135
|
+
urls,
|
|
136
|
+
});
|
|
137
|
+
expect(mockPromptModule).toHaveBeenCalledTimes(1);
|
|
138
|
+
expect(DevModeUnifiedInterface.configs).toStrictEqual([expectedConfig]);
|
|
139
|
+
});
|
|
140
|
+
it('should call setActiveApp with the correct arg', async () => {
|
|
141
|
+
await DevModeUnifiedInterface.setup({
|
|
142
|
+
components,
|
|
143
|
+
logger,
|
|
144
|
+
setActiveApp,
|
|
145
|
+
urls,
|
|
146
|
+
});
|
|
147
|
+
expect(setActiveApp).toHaveBeenCalledTimes(1);
|
|
148
|
+
expect(setActiveApp).toHaveBeenCalledWith(unifiedAppConfig.uid);
|
|
149
|
+
});
|
|
150
|
+
it('should not run setup if it has already been configured', async () => {
|
|
151
|
+
DevModeUnifiedInterface.isConfigured = true;
|
|
152
|
+
await DevModeUnifiedInterface.setup({
|
|
153
|
+
components,
|
|
154
|
+
logger,
|
|
155
|
+
setActiveApp,
|
|
156
|
+
urls,
|
|
157
|
+
});
|
|
158
|
+
expect(logger.debug).toHaveBeenCalledWith('Dev server has already been configured, skipping');
|
|
159
|
+
expect(DevModeUnifiedInterface.configs).toBeUndefined();
|
|
160
|
+
});
|
|
161
|
+
it('should generate the correct configs for a settings card', async () => {
|
|
162
|
+
const settingsComponents = {
|
|
163
|
+
application_name: unifiedAppConfig,
|
|
164
|
+
card_one: unifiedCardOneConfig,
|
|
165
|
+
card_settings: settingsExtensionConfig,
|
|
166
|
+
};
|
|
167
|
+
mockPromptModule = vi.fn().mockResolvedValue({
|
|
168
|
+
extensions: [expectedConfig, settingsExtensionTransformedData],
|
|
169
|
+
});
|
|
170
|
+
vi.mocked(inquirer.createPromptModule).mockReturnValue(mockPromptModule);
|
|
171
|
+
await DevModeUnifiedInterface.setup({
|
|
172
|
+
components: settingsComponents,
|
|
173
|
+
logger,
|
|
174
|
+
setActiveApp,
|
|
175
|
+
urls,
|
|
176
|
+
});
|
|
177
|
+
expect(mockPromptModule).toHaveBeenCalledTimes(1);
|
|
178
|
+
expect(DevModeUnifiedInterface.configs).toStrictEqual([
|
|
179
|
+
expectedConfig,
|
|
180
|
+
settingsExtensionTransformedData,
|
|
181
|
+
]);
|
|
182
|
+
expect(DevModeUnifiedInterface.configs?.[1]).toHaveProperty('data.title', 'Settings');
|
|
183
|
+
});
|
|
184
|
+
it('should generate the correct configs for a pages extension', async () => {
|
|
185
|
+
const pagesComponents = {
|
|
186
|
+
application_name: unifiedAppConfig,
|
|
187
|
+
card_one: unifiedCardOneConfig,
|
|
188
|
+
app_homes: appHomesConfig,
|
|
189
|
+
};
|
|
190
|
+
mockPromptModule = vi.fn().mockResolvedValue({
|
|
191
|
+
extensions: [expectedConfig, appHomesTransformedData],
|
|
192
|
+
});
|
|
193
|
+
vi.mocked(inquirer.createPromptModule).mockReturnValue(mockPromptModule);
|
|
194
|
+
await DevModeUnifiedInterface.setup({
|
|
195
|
+
components: pagesComponents,
|
|
196
|
+
logger,
|
|
197
|
+
setActiveApp,
|
|
198
|
+
urls,
|
|
199
|
+
});
|
|
200
|
+
expect(mockPromptModule).toHaveBeenCalledTimes(1);
|
|
201
|
+
expect(DevModeUnifiedInterface.configs).toStrictEqual([
|
|
202
|
+
expectedConfig,
|
|
203
|
+
appHomesTransformedData,
|
|
204
|
+
]);
|
|
205
|
+
expect(DevModeUnifiedInterface.configs?.[1]).toHaveProperty('data.title', 'App Home');
|
|
206
|
+
});
|
|
207
|
+
it('should use profileData variables when provided', async () => {
|
|
208
|
+
const profileData = {
|
|
209
|
+
API_KEY: 'test-key-123',
|
|
210
|
+
DEBUG_MODE: true,
|
|
211
|
+
MAX_RETRIES: 5,
|
|
212
|
+
};
|
|
213
|
+
await DevModeUnifiedInterface.setup({
|
|
214
|
+
components,
|
|
215
|
+
profileData,
|
|
216
|
+
logger,
|
|
217
|
+
setActiveApp,
|
|
218
|
+
urls,
|
|
219
|
+
});
|
|
220
|
+
const appConfig = DevModeUnifiedInterface.configs?.[0]
|
|
221
|
+
?.appConfig;
|
|
222
|
+
expect(appConfig?.variables).toStrictEqual(profileData);
|
|
223
|
+
});
|
|
224
|
+
it('should use empty object for variables when no profileData provided', async () => {
|
|
225
|
+
await DevModeUnifiedInterface.setup({
|
|
226
|
+
components,
|
|
227
|
+
logger,
|
|
228
|
+
setActiveApp,
|
|
229
|
+
urls,
|
|
230
|
+
});
|
|
231
|
+
const appConfig = DevModeUnifiedInterface.configs?.[0]
|
|
232
|
+
?.appConfig;
|
|
233
|
+
expect(appConfig?.variables).toStrictEqual({});
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|