@appsemble/cli 0.30.1 → 0.30.3

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.
@@ -5,232 +5,234 @@ import { AppsembleError, resolveFixture } from '@appsemble/node-utils';
5
5
  import { ts } from 'ts-json-schema-generator';
6
6
  import { beforeEach, describe, expect, it, vi } from 'vitest';
7
7
  import { getProjectImplementations } from './config.js';
8
- beforeEach(() => {
9
- vi.spyOn(process, 'cwd').mockReturnValue(resolveFixture('.'));
10
- });
11
- describe('getProjectImplementations', () => {
12
- it('should extract configuration from a TypeScript project', () => {
13
- const result = getProjectImplementations({
14
- name: '',
15
- layout: 'float',
16
- version: '1.33.7',
17
- webpack: '',
18
- output: '',
19
- dir: resolveFixture('getProjectImplementations/valid'),
20
- });
21
- expect(result).toStrictEqual({
22
- actions: { testAction: { description: undefined } },
23
- events: {
24
- emit: { testEmit: { description: undefined } },
25
- listen: { testListener: { description: undefined } },
26
- },
27
- messages: undefined,
28
- parameters: {
29
- $schema: 'http://json-schema.org/draft-07/schema#',
30
- additionalProperties: false,
31
- properties: {
32
- param1: { type: 'string' },
33
- param2: { type: 'number' },
34
- param3: { type: 'boolean' },
35
- param4: { type: 'string' },
36
- param5: {
37
- additionalProperties: false,
38
- properties: {
39
- nested1: { type: 'string' },
40
- nested2: { type: 'number' },
41
- nested3: { type: 'boolean' },
8
+ describe('config', () => {
9
+ beforeEach(() => {
10
+ vi.spyOn(process, 'cwd').mockReturnValue(resolveFixture('.'));
11
+ });
12
+ describe('getProjectImplementations', () => {
13
+ it('should extract configuration from a TypeScript project', () => {
14
+ const result = getProjectImplementations({
15
+ name: '',
16
+ layout: 'float',
17
+ version: '1.33.7',
18
+ webpack: '',
19
+ output: '',
20
+ dir: resolveFixture('getProjectImplementations/valid'),
21
+ });
22
+ expect(result).toStrictEqual({
23
+ actions: { testAction: { description: undefined } },
24
+ events: {
25
+ emit: { testEmit: { description: undefined } },
26
+ listen: { testListener: { description: undefined } },
27
+ },
28
+ messages: undefined,
29
+ parameters: {
30
+ $schema: 'http://json-schema.org/draft-07/schema#',
31
+ additionalProperties: false,
32
+ properties: {
33
+ param1: { type: 'string' },
34
+ param2: { type: 'number' },
35
+ param3: { type: 'boolean' },
36
+ param4: { type: 'string' },
37
+ param5: {
38
+ additionalProperties: false,
39
+ properties: {
40
+ nested1: { type: 'string' },
41
+ nested2: { type: 'number' },
42
+ nested3: { type: 'boolean' },
43
+ },
44
+ required: ['nested1', 'nested2', 'nested3'],
45
+ type: 'object',
42
46
  },
43
- required: ['nested1', 'nested2', 'nested3'],
44
- type: 'object',
47
+ param6: { items: { type: 'string' }, type: 'array' },
45
48
  },
46
- param6: { items: { type: 'string' }, type: 'array' },
49
+ required: ['param1', 'param2', 'param3', 'param5', 'param6'],
50
+ type: 'object',
47
51
  },
48
- required: ['param1', 'param2', 'param3', 'param5', 'param6'],
49
- type: 'object',
50
- },
52
+ });
51
53
  });
52
- });
53
- // Spying on TypeScript functions no longer works.
54
- // eslint-disable-next-line vitest/no-disabled-tests
55
- it.skip('should not use TypeScript if all metadata is present in the original config', () => {
56
- vi.spyOn(ts, 'createProgram');
57
- const input = {
58
- actions: {},
59
- events: { emit: { foo: {} }, listen: { bar: {} } },
60
- layout: 'float',
61
- parameters: { type: 'object' },
62
- version: '1.33.7',
63
- webpack: '',
64
- output: '',
65
- dir: resolveFixture('getProjectImplementations/valid'),
66
- name: '',
67
- };
68
- const result = getProjectImplementations(input);
69
- expect(result).toBe(input);
70
- expect(ts.createProgram).not.toHaveBeenCalled();
71
- });
72
- it('should prefer actions overrides over TypeScript actions', () => {
73
- const result = getProjectImplementations({
74
- actions: {},
75
- version: '1.33.7',
76
- webpack: '',
77
- output: '',
78
- dir: resolveFixture('getProjectImplementations/valid'),
79
- name: '',
54
+ // Spying on TypeScript functions no longer works.
55
+ // eslint-disable-next-line vitest/no-disabled-tests
56
+ it.skip('should not use TypeScript if all metadata is present in the original config', () => {
57
+ vi.spyOn(ts, 'createProgram');
58
+ const input = {
59
+ actions: {},
60
+ events: { emit: { foo: {} }, listen: { bar: {} } },
61
+ layout: 'float',
62
+ parameters: { type: 'object' },
63
+ version: '1.33.7',
64
+ webpack: '',
65
+ output: '',
66
+ dir: resolveFixture('getProjectImplementations/valid'),
67
+ name: '',
68
+ };
69
+ const result = getProjectImplementations(input);
70
+ expect(result).toBe(input);
71
+ expect(ts.createProgram).not.toHaveBeenCalled();
80
72
  });
81
- expect(result.actions).toStrictEqual({});
82
- });
83
- it('should prefer events overrides over TypeScript events', () => {
84
- const result = getProjectImplementations({
85
- events: { emit: { onSuccess: {} } },
86
- version: '1.33.7',
87
- webpack: '',
88
- output: '',
89
- dir: resolveFixture('getProjectImplementations/valid'),
90
- name: '',
73
+ it('should prefer actions overrides over TypeScript actions', () => {
74
+ const result = getProjectImplementations({
75
+ actions: {},
76
+ version: '1.33.7',
77
+ webpack: '',
78
+ output: '',
79
+ dir: resolveFixture('getProjectImplementations/valid'),
80
+ name: '',
81
+ });
82
+ expect(result.actions).toStrictEqual({});
91
83
  });
92
- expect(result.events).toStrictEqual({ emit: { onSuccess: {} } });
93
- });
94
- it('should prefer parameters overrides over TypeScript parameters', () => {
95
- const result = getProjectImplementations({
96
- parameters: { type: 'object' },
97
- version: '1.33.7',
98
- webpack: '',
99
- output: '',
100
- dir: resolveFixture('getProjectImplementations/valid'),
101
- name: '',
84
+ it('should prefer events overrides over TypeScript events', () => {
85
+ const result = getProjectImplementations({
86
+ events: { emit: { onSuccess: {} } },
87
+ version: '1.33.7',
88
+ webpack: '',
89
+ output: '',
90
+ dir: resolveFixture('getProjectImplementations/valid'),
91
+ name: '',
92
+ });
93
+ expect(result.events).toStrictEqual({ emit: { onSuccess: {} } });
102
94
  });
103
- expect(result.parameters).toStrictEqual({ type: 'object' });
104
- });
105
- it('should throw if duplicate Actions are found', () => {
106
- expect(() => getProjectImplementations({
107
- webpack: '',
108
- output: '',
109
- dir: resolveFixture('getProjectImplementations/duplicateActions'),
110
- name: '',
111
- version: '1.33.7',
112
- })).toThrow(new AppsembleError("Found duplicate interface 'Actions' in 'getProjectImplementations/duplicateActions/index.ts:31'"));
113
- });
114
- it('should throw if duplicate EventEmitters are found', () => {
115
- expect(() => getProjectImplementations({
116
- webpack: '',
117
- output: '',
118
- dir: resolveFixture('getProjectImplementations/duplicateEventEmitters'),
119
- name: '',
120
- version: '1.33.7',
121
- })).toThrow(new AppsembleError("Found duplicate interface 'EventEmitters' in 'getProjectImplementations/duplicateEventEmitters/index.ts:31'"));
122
- });
123
- it('should throw if duplicate EventListeners are found', () => {
124
- expect(() => getProjectImplementations({
125
- webpack: '',
126
- output: '',
127
- dir: resolveFixture('getProjectImplementations/duplicateEventListeners'),
128
- name: '',
129
- version: '1.33.7',
130
- })).toThrow(new AppsembleError("Found duplicate interface 'EventListeners' in 'getProjectImplementations/duplicateEventListeners/index.ts:31'"));
131
- });
132
- it('should throw if duplicate Parameters are found', () => {
133
- expect(() => getProjectImplementations({
134
- webpack: '',
135
- output: '',
136
- dir: resolveFixture('getProjectImplementations/duplicateParameters'),
137
- name: '',
138
- version: '1.33.7',
139
- })).toThrow(new AppsembleError("Found duplicate interface 'Parameters' in 'getProjectImplementations/duplicateParameters/index.ts:31'"));
140
- });
141
- it('should handle fontawesome icons', () => {
142
- const result = getProjectImplementations({
143
- webpack: '',
144
- output: '',
145
- dir: resolveFixture('getProjectImplementations/fontawesomeParameters'),
146
- name: '',
147
- version: '1.33.7',
95
+ it('should prefer parameters overrides over TypeScript parameters', () => {
96
+ const result = getProjectImplementations({
97
+ parameters: { type: 'object' },
98
+ version: '1.33.7',
99
+ webpack: '',
100
+ output: '',
101
+ dir: resolveFixture('getProjectImplementations/valid'),
102
+ name: '',
103
+ });
104
+ expect(result.parameters).toStrictEqual({ type: 'object' });
105
+ });
106
+ it('should throw if duplicate Actions are found', () => {
107
+ expect(() => getProjectImplementations({
108
+ webpack: '',
109
+ output: '',
110
+ dir: resolveFixture('getProjectImplementations/duplicateActions'),
111
+ name: '',
112
+ version: '1.33.7',
113
+ })).toThrow(new AppsembleError("Found duplicate interface 'Actions' in 'getProjectImplementations/duplicateActions/index.ts:31'"));
114
+ });
115
+ it('should throw if duplicate EventEmitters are found', () => {
116
+ expect(() => getProjectImplementations({
117
+ webpack: '',
118
+ output: '',
119
+ dir: resolveFixture('getProjectImplementations/duplicateEventEmitters'),
120
+ name: '',
121
+ version: '1.33.7',
122
+ })).toThrow(new AppsembleError("Found duplicate interface 'EventEmitters' in 'getProjectImplementations/duplicateEventEmitters/index.ts:31'"));
148
123
  });
149
- expect(result).toStrictEqual({
150
- actions: undefined,
151
- events: undefined,
152
- messages: undefined,
153
- parameters: {
154
- $schema: 'http://json-schema.org/draft-07/schema#',
155
- additionalProperties: false,
156
- properties: {
157
- icon: { description: 'This is an icon.', format: 'fontawesome', type: 'string' },
124
+ it('should throw if duplicate EventListeners are found', () => {
125
+ expect(() => getProjectImplementations({
126
+ webpack: '',
127
+ output: '',
128
+ dir: resolveFixture('getProjectImplementations/duplicateEventListeners'),
129
+ name: '',
130
+ version: '1.33.7',
131
+ })).toThrow(new AppsembleError("Found duplicate interface 'EventListeners' in 'getProjectImplementations/duplicateEventListeners/index.ts:31'"));
132
+ });
133
+ it('should throw if duplicate Parameters are found', () => {
134
+ expect(() => getProjectImplementations({
135
+ webpack: '',
136
+ output: '',
137
+ dir: resolveFixture('getProjectImplementations/duplicateParameters'),
138
+ name: '',
139
+ version: '1.33.7',
140
+ })).toThrow(new AppsembleError("Found duplicate interface 'Parameters' in 'getProjectImplementations/duplicateParameters/index.ts:31'"));
141
+ });
142
+ it('should handle fontawesome icons', () => {
143
+ const result = getProjectImplementations({
144
+ webpack: '',
145
+ output: '',
146
+ dir: resolveFixture('getProjectImplementations/fontawesomeParameters'),
147
+ name: '',
148
+ version: '1.33.7',
149
+ });
150
+ expect(result).toStrictEqual({
151
+ actions: undefined,
152
+ events: undefined,
153
+ messages: undefined,
154
+ parameters: {
155
+ $schema: 'http://json-schema.org/draft-07/schema#',
156
+ additionalProperties: false,
157
+ properties: {
158
+ icon: { description: 'This is an icon.', format: 'fontawesome', type: 'string' },
159
+ },
160
+ type: 'object',
158
161
  },
159
- type: 'object',
160
- },
162
+ });
161
163
  });
162
- });
163
- it('should handle TypeScript pre emit diagnostics', () => {
164
- function fn() {
165
- getProjectImplementations({
164
+ it('should handle TypeScript pre emit diagnostics', () => {
165
+ function fn() {
166
+ getProjectImplementations({
167
+ name: '',
168
+ layout: 'float',
169
+ version: '1.33.7',
170
+ webpack: '',
171
+ output: '',
172
+ dir: resolveFixture('getProjectImplementations/tsError'),
173
+ });
174
+ }
175
+ expect(fn).toThrow(AppsembleError);
176
+ expect(fn).toThrow(/'unused' is declared but its value is never read/);
177
+ });
178
+ it('should extract comments', () => {
179
+ const result = getProjectImplementations({
166
180
  name: '',
167
181
  layout: 'float',
168
182
  version: '1.33.7',
169
183
  webpack: '',
170
184
  output: '',
171
- dir: resolveFixture('getProjectImplementations/tsError'),
185
+ dir: resolveFixture('getProjectImplementations/comments'),
172
186
  });
173
- }
174
- expect(fn).toThrow(AppsembleError);
175
- expect(fn).toThrow(/'unused' is declared but its value is never read/);
176
- });
177
- it('should extract comments', () => {
178
- const result = getProjectImplementations({
179
- name: '',
180
- layout: 'float',
181
- version: '1.33.7',
182
- webpack: '',
183
- output: '',
184
- dir: resolveFixture('getProjectImplementations/comments'),
185
- });
186
- expect(result).toStrictEqual({
187
- actions: {
188
- comment: {
189
- description: 'Valid action comment',
190
- },
191
- duplicate: {
192
- description: 'Expected comment',
193
- },
194
- line: {
195
- description: undefined,
196
- },
197
- },
198
- events: {
199
- emit: {
200
- testEmit: {
201
- description: 'Test event emitter.',
187
+ expect(result).toStrictEqual({
188
+ actions: {
189
+ comment: {
190
+ description: 'Valid action comment',
191
+ },
192
+ duplicate: {
193
+ description: 'Expected comment',
194
+ },
195
+ line: {
196
+ description: undefined,
202
197
  },
203
198
  },
204
- listen: {
205
- testListener: {
206
- description: 'Test event listener.',
199
+ events: {
200
+ emit: {
201
+ testEmit: {
202
+ description: 'Test event emitter.',
203
+ },
204
+ },
205
+ listen: {
206
+ testListener: {
207
+ description: 'Test event listener.',
208
+ },
207
209
  },
208
210
  },
209
- },
210
- messages: undefined,
211
- parameters: {
212
- $schema: 'http://json-schema.org/draft-07/schema#',
213
- additionalProperties: false,
214
- properties: {
215
- param: {},
211
+ messages: undefined,
212
+ parameters: {
213
+ $schema: 'http://json-schema.org/draft-07/schema#',
214
+ additionalProperties: false,
215
+ properties: {
216
+ param: {},
217
+ },
218
+ required: ['param'],
219
+ type: 'object',
216
220
  },
217
- required: ['param'],
218
- type: 'object',
219
- },
221
+ });
220
222
  });
221
- });
222
- describe('official blocks', () => {
223
- const blocksDir = new URL('../../../blocks/', import.meta.url);
224
- it.each(readdirSync(blocksDir))('%s', (name) => {
225
- const dir = fileURLToPath(new URL(name, blocksDir));
226
- const result = getProjectImplementations({
227
- name,
228
- version: '',
229
- output: '',
230
- webpack: undefined,
231
- dir,
223
+ describe('official blocks', () => {
224
+ const blocksDir = new URL('../../../blocks/', import.meta.url);
225
+ it.each(readdirSync(blocksDir))('%s', (name) => {
226
+ const dir = fileURLToPath(new URL(name, blocksDir));
227
+ const result = getProjectImplementations({
228
+ name,
229
+ version: '',
230
+ output: '',
231
+ webpack: undefined,
232
+ dir,
233
+ });
234
+ expect(result).toMatchSnapshot();
232
235
  });
233
- expect(result).toMatchSnapshot();
234
236
  });
235
237
  });
236
238
  });