@lwc/sfdc-lwc-compiler 13.3.7-alpha.4 → 13.3.8

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.
@@ -1,837 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /*
4
- * Copyright (c) 2024, Salesforce, Inc.
5
- * All rights reserved.
6
- * SPDX-License-Identifier: MIT
7
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8
- */
9
- const vitest_1 = require("vitest");
10
- const errors_1 = require("@lwc/errors");
11
- const sarif_1 = require("../sarif");
12
- (0, vitest_1.describe)('sarif utilities', () => {
13
- (0, vitest_1.describe)('toSarifLevel (internal function - tested via convertDiagnosticsToSarif)', () => {
14
- (0, vitest_1.it)('converts Fatal (0) to error', () => {
15
- const diagnostics = [{
16
- code: 1001,
17
- message: 'Fatal error',
18
- level: errors_1.DiagnosticLevel.Fatal,
19
- }];
20
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
21
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.level).toBe('error');
22
- });
23
- (0, vitest_1.it)('converts Error (1) to error', () => {
24
- const diagnostics = [{
25
- code: 1002,
26
- message: 'Error message',
27
- level: errors_1.DiagnosticLevel.Error,
28
- }];
29
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
30
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.level).toBe('error');
31
- });
32
- (0, vitest_1.it)('converts Warning (2) to warning', () => {
33
- const diagnostics = [{
34
- code: 1003,
35
- message: 'Warning message',
36
- level: errors_1.DiagnosticLevel.Warning,
37
- }];
38
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
39
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.level).toBe('warning');
40
- });
41
- (0, vitest_1.it)('converts Log (3) to note', () => {
42
- const diagnostics = [{
43
- code: 1004,
44
- message: 'Log message',
45
- level: errors_1.DiagnosticLevel.Log,
46
- }];
47
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
48
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.level).toBe('note');
49
- });
50
- (0, vitest_1.it)('converts undefined level to note', () => {
51
- const diagnostics = [{
52
- code: 1005,
53
- message: 'Unknown level',
54
- level: undefined,
55
- }];
56
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
57
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.level).toBe('note');
58
- });
59
- (0, vitest_1.it)('converts out of range level to note', () => {
60
- const diagnostics = [{
61
- code: 1006,
62
- message: 'Invalid level',
63
- level: 999,
64
- }];
65
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
66
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.level).toBe('note');
67
- });
68
- });
69
- (0, vitest_1.describe)('ruleIdFromDiagnostic (internal function - tested via convertDiagnosticsToSarif)', () => {
70
- (0, vitest_1.it)('converts numeric code to LWC prefix format', () => {
71
- const diagnostics = [{
72
- code: 1234,
73
- message: 'Test error',
74
- level: errors_1.DiagnosticLevel.Error,
75
- }];
76
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
77
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.ruleId).toBe('LWC1234');
78
- });
79
- (0, vitest_1.it)('converts string code as-is', () => {
80
- const diagnostics = [{
81
- code: 'CUSTOM_ERROR',
82
- message: 'Custom error',
83
- level: errors_1.DiagnosticLevel.Error,
84
- }];
85
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
86
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.ruleId).toBe('CUSTOM_ERROR');
87
- });
88
- (0, vitest_1.it)('handles undefined code', () => {
89
- const diagnostics = [{
90
- code: undefined,
91
- message: 'No code',
92
- level: errors_1.DiagnosticLevel.Error,
93
- }];
94
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
95
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.ruleId).toBeUndefined();
96
- });
97
- (0, vitest_1.it)('handles null code', () => {
98
- const diagnostics = [{
99
- code: null,
100
- message: 'Null code',
101
- level: errors_1.DiagnosticLevel.Error,
102
- }];
103
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
104
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.ruleId).toBeUndefined();
105
- });
106
- (0, vitest_1.it)('handles zero code', () => {
107
- const diagnostics = [{
108
- code: 0,
109
- message: 'Zero code',
110
- level: errors_1.DiagnosticLevel.Error,
111
- }];
112
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
113
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.ruleId).toBe('LWC0');
114
- });
115
- (0, vitest_1.it)('handles negative code', () => {
116
- const diagnostics = [{
117
- code: -5,
118
- message: 'Negative code',
119
- level: errors_1.DiagnosticLevel.Error,
120
- }];
121
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
122
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.ruleId).toBe('LWC-5');
123
- });
124
- (0, vitest_1.it)('handles empty string code', () => {
125
- const diagnostics = [{
126
- code: '',
127
- message: 'Empty string code',
128
- level: errors_1.DiagnosticLevel.Error,
129
- }];
130
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
131
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.ruleId).toBe('');
132
- });
133
- (0, vitest_1.it)('handles numeric string code', () => {
134
- const diagnostics = [{
135
- code: '1234',
136
- message: 'Numeric string',
137
- level: errors_1.DiagnosticLevel.Error,
138
- }];
139
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
140
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.ruleId).toBe('1234');
141
- });
142
- });
143
- (0, vitest_1.describe)('collectAllDiagnostics (internal function - tested via convertCompilerOutputToSarif)', () => {
144
- (0, vitest_1.it)('collects only top-level diagnostics', () => {
145
- const output = {
146
- success: true,
147
- version: '1.0.0',
148
- diagnostics: [
149
- { code: 1001, message: 'Error 1', level: errors_1.DiagnosticLevel.Error },
150
- { code: 1002, message: 'Error 2', level: errors_1.DiagnosticLevel.Error },
151
- ],
152
- timings: {},
153
- };
154
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
155
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(2);
156
- });
157
- (0, vitest_1.it)('collects only bundle-level diagnostics', () => {
158
- const output = {
159
- success: true,
160
- version: '1.0.0',
161
- diagnostics: [],
162
- results: [
163
- {
164
- code: 'bundle code',
165
- map: null,
166
- imports: [],
167
- outputConfig: {},
168
- diagnostics: [
169
- { code: 2001, message: 'Bundle error 1', level: errors_1.DiagnosticLevel.Error },
170
- { code: 2002, message: 'Bundle error 2', level: errors_1.DiagnosticLevel.Warning },
171
- ],
172
- timings: {},
173
- },
174
- ],
175
- timings: {},
176
- };
177
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
178
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(2);
179
- });
180
- (0, vitest_1.it)('merges top-level and bundle diagnostics', () => {
181
- const output = {
182
- success: false,
183
- version: '1.0.0',
184
- diagnostics: [
185
- { code: 1001, message: 'Top error', level: errors_1.DiagnosticLevel.Error },
186
- ],
187
- results: [
188
- {
189
- code: 'bundle code',
190
- map: null,
191
- imports: [],
192
- outputConfig: {},
193
- diagnostics: [
194
- { code: 2001, message: 'Bundle error', level: errors_1.DiagnosticLevel.Error },
195
- ],
196
- timings: {},
197
- },
198
- ],
199
- timings: {},
200
- };
201
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
202
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(2);
203
- });
204
- (0, vitest_1.it)('de-duplicates identical diagnostics', () => {
205
- const diagnostic = {
206
- code: 1001,
207
- message: 'Duplicate error',
208
- level: errors_1.DiagnosticLevel.Error,
209
- filename: 'test.js',
210
- location: { line: 1, column: 5 },
211
- };
212
- const output = {
213
- success: false,
214
- version: '1.0.0',
215
- diagnostics: [diagnostic],
216
- results: [
217
- {
218
- code: 'bundle code',
219
- map: null,
220
- imports: [],
221
- outputConfig: {},
222
- diagnostics: [diagnostic],
223
- timings: {},
224
- },
225
- ],
226
- timings: {},
227
- };
228
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
229
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(1);
230
- });
231
- (0, vitest_1.it)('keeps diagnostics with different codes', () => {
232
- const output = {
233
- success: false,
234
- version: '1.0.0',
235
- diagnostics: [
236
- { code: 1001, message: 'Same message', level: errors_1.DiagnosticLevel.Error, filename: 'test.js', location: { line: 1, column: 5 } },
237
- { code: 1002, message: 'Same message', level: errors_1.DiagnosticLevel.Error, filename: 'test.js', location: { line: 1, column: 5 } },
238
- ],
239
- timings: {},
240
- };
241
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
242
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(2);
243
- });
244
- (0, vitest_1.it)('keeps diagnostics with different messages', () => {
245
- const output = {
246
- success: false,
247
- version: '1.0.0',
248
- diagnostics: [
249
- { code: 1001, message: 'Message 1', level: errors_1.DiagnosticLevel.Error, filename: 'test.js', location: { line: 1, column: 5 } },
250
- { code: 1001, message: 'Message 2', level: errors_1.DiagnosticLevel.Error, filename: 'test.js', location: { line: 1, column: 5 } },
251
- ],
252
- timings: {},
253
- };
254
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
255
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(2);
256
- });
257
- (0, vitest_1.it)('keeps diagnostics with different filenames', () => {
258
- const output = {
259
- success: false,
260
- version: '1.0.0',
261
- diagnostics: [
262
- { code: 1001, message: 'Same error', level: errors_1.DiagnosticLevel.Error, filename: 'test1.js', location: { line: 1, column: 5 } },
263
- { code: 1001, message: 'Same error', level: errors_1.DiagnosticLevel.Error, filename: 'test2.js', location: { line: 1, column: 5 } },
264
- ],
265
- timings: {},
266
- };
267
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
268
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(2);
269
- });
270
- (0, vitest_1.it)('keeps diagnostics with different locations', () => {
271
- const output = {
272
- success: false,
273
- version: '1.0.0',
274
- diagnostics: [
275
- { code: 1001, message: 'Same error', level: errors_1.DiagnosticLevel.Error, filename: 'test.js', location: { line: 1, column: 5 } },
276
- { code: 1001, message: 'Same error', level: errors_1.DiagnosticLevel.Error, filename: 'test.js', location: { line: 2, column: 10 } },
277
- ],
278
- timings: {},
279
- };
280
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
281
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(2);
282
- });
283
- (0, vitest_1.it)('handles undefined top-level diagnostics', () => {
284
- const output = {
285
- success: true,
286
- version: '1.0.0',
287
- diagnostics: undefined,
288
- results: [
289
- {
290
- code: 'bundle code',
291
- map: null,
292
- imports: [],
293
- outputConfig: {},
294
- diagnostics: [
295
- { code: 2001, message: 'Bundle error', level: errors_1.DiagnosticLevel.Error },
296
- ],
297
- timings: {},
298
- },
299
- ],
300
- timings: {},
301
- };
302
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
303
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(1);
304
- });
305
- (0, vitest_1.it)('handles undefined results', () => {
306
- const output = {
307
- success: true,
308
- version: '1.0.0',
309
- diagnostics: [
310
- { code: 1001, message: 'Top error', level: errors_1.DiagnosticLevel.Error },
311
- ],
312
- results: undefined,
313
- timings: {},
314
- };
315
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
316
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(1);
317
- });
318
- (0, vitest_1.it)('handles both diagnostics and results undefined', () => {
319
- const output = {
320
- success: true,
321
- version: '1.0.0',
322
- diagnostics: undefined,
323
- results: undefined,
324
- timings: {},
325
- };
326
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
327
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(0);
328
- });
329
- (0, vitest_1.it)('handles bundle with undefined diagnostics', () => {
330
- const output = {
331
- success: true,
332
- version: '1.0.0',
333
- diagnostics: [],
334
- results: [
335
- {
336
- code: 'bundle code',
337
- map: null,
338
- imports: [],
339
- outputConfig: {},
340
- diagnostics: undefined,
341
- timings: {},
342
- },
343
- ],
344
- timings: {},
345
- };
346
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
347
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(0);
348
- });
349
- (0, vitest_1.it)('handles diagnostics with undefined code', () => {
350
- const output = {
351
- success: false,
352
- version: '1.0.0',
353
- diagnostics: [
354
- { code: undefined, message: 'Error', level: errors_1.DiagnosticLevel.Error },
355
- ],
356
- timings: {},
357
- };
358
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
359
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(1);
360
- });
361
- (0, vitest_1.it)('handles diagnostics with undefined message', () => {
362
- const output = {
363
- success: false,
364
- version: '1.0.0',
365
- diagnostics: [
366
- { code: 1001, message: undefined, level: errors_1.DiagnosticLevel.Error },
367
- ],
368
- timings: {},
369
- };
370
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
371
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(1);
372
- });
373
- (0, vitest_1.it)('handles diagnostics with undefined filename', () => {
374
- const output = {
375
- success: false,
376
- version: '1.0.0',
377
- diagnostics: [
378
- { code: 1001, message: 'Error', level: errors_1.DiagnosticLevel.Error, filename: undefined },
379
- ],
380
- timings: {},
381
- };
382
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
383
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(1);
384
- });
385
- (0, vitest_1.it)('handles diagnostics with undefined location', () => {
386
- const output = {
387
- success: false,
388
- version: '1.0.0',
389
- diagnostics: [
390
- { code: 1001, message: 'Error', level: errors_1.DiagnosticLevel.Error, location: undefined },
391
- ],
392
- timings: {},
393
- };
394
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
395
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(1);
396
- });
397
- (0, vitest_1.it)('handles multiple bundles', () => {
398
- const output = {
399
- success: false,
400
- version: '1.0.0',
401
- diagnostics: [],
402
- results: [
403
- {
404
- code: 'bundle1',
405
- map: null,
406
- imports: [],
407
- outputConfig: {},
408
- diagnostics: [
409
- { code: 2001, message: 'Bundle 1 error', level: errors_1.DiagnosticLevel.Error },
410
- ],
411
- timings: {},
412
- },
413
- {
414
- code: 'bundle2',
415
- map: null,
416
- imports: [],
417
- outputConfig: {},
418
- diagnostics: [
419
- { code: 2002, message: 'Bundle 2 error', level: errors_1.DiagnosticLevel.Error },
420
- ],
421
- timings: {},
422
- },
423
- ],
424
- timings: {},
425
- };
426
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
427
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(2);
428
- });
429
- });
430
- (0, vitest_1.describe)('convertDiagnosticsToSarif', () => {
431
- (0, vitest_1.it)('creates valid SARIF structure', () => {
432
- const diagnostics = [{
433
- code: 1001,
434
- message: 'Test error',
435
- level: errors_1.DiagnosticLevel.Error,
436
- }];
437
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
438
- (0, vitest_1.expect)(sarif.version).toBe('2.1.0');
439
- (0, vitest_1.expect)(sarif.$schema).toBe('https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json');
440
- (0, vitest_1.expect)(sarif.runs).toHaveLength(1);
441
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.name).toBe('@lwc/sfdc-lwc-compiler');
442
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(1);
443
- });
444
- (0, vitest_1.it)('uses default tool name when options not provided', () => {
445
- const diagnostics = [{
446
- code: 1001,
447
- message: 'Test error',
448
- level: errors_1.DiagnosticLevel.Error,
449
- }];
450
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
451
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.name).toBe('@lwc/sfdc-lwc-compiler');
452
- });
453
- (0, vitest_1.it)('uses default tool name when options is empty object', () => {
454
- const diagnostics = [{
455
- code: 1001,
456
- message: 'Test error',
457
- level: errors_1.DiagnosticLevel.Error,
458
- }];
459
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics, {});
460
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.name).toBe('@lwc/sfdc-lwc-compiler');
461
- });
462
- (0, vitest_1.it)('uses custom tool name when provided', () => {
463
- const diagnostics = [{
464
- code: 1001,
465
- message: 'Test error',
466
- level: errors_1.DiagnosticLevel.Error,
467
- }];
468
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics, { toolName: 'custom-tool' });
469
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.name).toBe('custom-tool');
470
- });
471
- (0, vitest_1.it)('creates rule for diagnostic with code', () => {
472
- const diagnostics = [{
473
- code: 1001,
474
- message: 'Test error',
475
- level: errors_1.DiagnosticLevel.Error,
476
- }];
477
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
478
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.rules).toHaveLength(1);
479
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.rules[0].id).toBe('LWC1001');
480
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.rules[0].name).toBe('LWC1001');
481
- });
482
- (0, vitest_1.it)('does not create rule for diagnostic without code', () => {
483
- const diagnostics = [{
484
- code: undefined,
485
- message: 'Test error',
486
- level: errors_1.DiagnosticLevel.Error,
487
- }];
488
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
489
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.rules).toBeUndefined();
490
- });
491
- (0, vitest_1.it)('de-duplicates rules with same ruleId', () => {
492
- const diagnostics = [
493
- { code: 1001, message: 'Error 1', level: errors_1.DiagnosticLevel.Error },
494
- { code: 1001, message: 'Error 2', level: errors_1.DiagnosticLevel.Error },
495
- { code: 1001, message: 'Error 3', level: errors_1.DiagnosticLevel.Error },
496
- ];
497
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
498
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.rules).toHaveLength(1);
499
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(3);
500
- });
501
- (0, vitest_1.it)('creates multiple rules for different codes', () => {
502
- const diagnostics = [
503
- { code: 1001, message: 'Error 1', level: errors_1.DiagnosticLevel.Error },
504
- { code: 1002, message: 'Error 2', level: errors_1.DiagnosticLevel.Error },
505
- { code: 1003, message: 'Error 3', level: errors_1.DiagnosticLevel.Error },
506
- ];
507
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
508
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.rules).toHaveLength(3);
509
- });
510
- (0, vitest_1.it)('extracts short description from message with colon', () => {
511
- const diagnostics = [{
512
- code: 1001,
513
- message: 'ShortDesc: Full description here',
514
- level: errors_1.DiagnosticLevel.Error,
515
- }];
516
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
517
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.rules[0].shortDescription?.text).toBe('ShortDesc');
518
- });
519
- (0, vitest_1.it)('uses full message as short description when no colon', () => {
520
- const diagnostics = [{
521
- code: 1001,
522
- message: 'Full message without colon',
523
- level: errors_1.DiagnosticLevel.Error,
524
- }];
525
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
526
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.rules[0].shortDescription?.text).toBe('Full message without colon');
527
- });
528
- (0, vitest_1.it)('handles empty short description', () => {
529
- const diagnostics = [{
530
- code: 1001,
531
- message: '',
532
- level: errors_1.DiagnosticLevel.Error,
533
- }];
534
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
535
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.rules[0].shortDescription).toBeUndefined();
536
- });
537
- (0, vitest_1.it)('includes helpUri when url is provided', () => {
538
- const diagnostics = [{
539
- code: 1001,
540
- message: 'Test error',
541
- level: errors_1.DiagnosticLevel.Error,
542
- url: 'https://example.com/error/1001',
543
- }];
544
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
545
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.rules[0].helpUri).toBe('https://example.com/error/1001');
546
- });
547
- (0, vitest_1.it)('sets helpUri to undefined when url is not provided', () => {
548
- const diagnostics = [{
549
- code: 1001,
550
- message: 'Test error',
551
- level: errors_1.DiagnosticLevel.Error,
552
- }];
553
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
554
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.rules[0].helpUri).toBeUndefined();
555
- });
556
- (0, vitest_1.it)('sets rank to 100 for Fatal level', () => {
557
- const diagnostics = [{
558
- code: 1001,
559
- message: 'Fatal error',
560
- level: errors_1.DiagnosticLevel.Fatal,
561
- }];
562
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
563
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.rank).toBe(100);
564
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.properties?.isFatal).toBe(true);
565
- });
566
- (0, vitest_1.it)('sets rank to -1 for non-Fatal levels', () => {
567
- const diagnostics = [
568
- { code: 1001, message: 'Error', level: errors_1.DiagnosticLevel.Error },
569
- { code: 1002, message: 'Warning', level: errors_1.DiagnosticLevel.Warning },
570
- { code: 1003, message: 'Log', level: errors_1.DiagnosticLevel.Log },
571
- ];
572
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
573
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.rank).toBe(-1);
574
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[1]?.rank).toBe(-1);
575
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[2]?.rank).toBe(-1);
576
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.properties?.isFatal).toBe(false);
577
- });
578
- (0, vitest_1.it)('includes message text', () => {
579
- const diagnostics = [{
580
- code: 1001,
581
- message: 'Test error message',
582
- level: errors_1.DiagnosticLevel.Error,
583
- }];
584
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
585
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.message.text).toBe('Test error message');
586
- });
587
- (0, vitest_1.it)('uses empty string for undefined message', () => {
588
- const diagnostics = [{
589
- code: 1001,
590
- message: undefined,
591
- level: errors_1.DiagnosticLevel.Error,
592
- }];
593
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
594
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.message.text).toBe('');
595
- });
596
- (0, vitest_1.it)('includes both filename and location', () => {
597
- const diagnostics = [{
598
- code: 1001,
599
- message: 'Test error',
600
- level: errors_1.DiagnosticLevel.Error,
601
- filename: 'test.js',
602
- location: { line: 10, column: 5 },
603
- }];
604
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
605
- const result = sarif.runs[0]?.results?.[0];
606
- (0, vitest_1.expect)(result?.locations).toHaveLength(1);
607
- (0, vitest_1.expect)(result?.locations?.[0]?.physicalLocation?.artifactLocation?.uri).toBe('test.js');
608
- (0, vitest_1.expect)(result?.locations?.[0]?.physicalLocation?.region?.startLine).toBe(10);
609
- (0, vitest_1.expect)(result?.locations?.[0]?.physicalLocation?.region?.startColumn).toBe(5);
610
- });
611
- (0, vitest_1.it)('includes only filename when location is not provided', () => {
612
- const diagnostics = [{
613
- code: 1001,
614
- message: 'Test error',
615
- level: errors_1.DiagnosticLevel.Error,
616
- filename: 'test.js',
617
- }];
618
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
619
- const result = sarif.runs[0]?.results?.[0];
620
- (0, vitest_1.expect)(result?.locations).toHaveLength(1);
621
- (0, vitest_1.expect)(result?.locations?.[0]?.physicalLocation?.artifactLocation?.uri).toBe('test.js');
622
- (0, vitest_1.expect)(result?.locations?.[0]?.physicalLocation?.region).toBeUndefined();
623
- });
624
- (0, vitest_1.it)('includes only location when filename is not provided', () => {
625
- const diagnostics = [{
626
- code: 1001,
627
- message: 'Test error',
628
- level: errors_1.DiagnosticLevel.Error,
629
- location: { line: 10, column: 5 },
630
- }];
631
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
632
- const result = sarif.runs[0]?.results?.[0];
633
- (0, vitest_1.expect)(result?.locations).toHaveLength(1);
634
- (0, vitest_1.expect)(result?.locations?.[0]?.physicalLocation?.artifactLocation).toBeUndefined();
635
- (0, vitest_1.expect)(result?.locations?.[0]?.physicalLocation?.region?.startLine).toBe(10);
636
- (0, vitest_1.expect)(result?.locations?.[0]?.physicalLocation?.region?.startColumn).toBe(5);
637
- });
638
- (0, vitest_1.it)('sets locations to undefined when neither filename nor location provided', () => {
639
- const diagnostics = [{
640
- code: 1001,
641
- message: 'Test error',
642
- level: errors_1.DiagnosticLevel.Error,
643
- }];
644
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
645
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.locations).toBeUndefined();
646
- });
647
- (0, vitest_1.it)('includes code in properties', () => {
648
- const diagnostics = [{
649
- code: 1234,
650
- message: 'Test error',
651
- level: errors_1.DiagnosticLevel.Error,
652
- }];
653
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
654
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.properties?.code).toBe(1234);
655
- });
656
- (0, vitest_1.it)('handles empty diagnostics array', () => {
657
- const diagnostics = [];
658
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
659
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(0);
660
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.rules).toBeUndefined();
661
- });
662
- (0, vitest_1.it)('handles diagnostics with all fields populated', () => {
663
- const diagnostics = [{
664
- code: 1001,
665
- message: 'Complete error',
666
- level: errors_1.DiagnosticLevel.Fatal,
667
- filename: 'component.js',
668
- location: { line: 42, column: 13, start: 500, length: 10 },
669
- url: 'https://docs.example.com/errors/1001',
670
- }];
671
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
672
- const result = sarif.runs[0]?.results?.[0];
673
- (0, vitest_1.expect)(result?.ruleId).toBe('LWC1001');
674
- (0, vitest_1.expect)(result?.level).toBe('error');
675
- (0, vitest_1.expect)(result?.rank).toBe(100);
676
- (0, vitest_1.expect)(result?.message.text).toBe('Complete error');
677
- (0, vitest_1.expect)(result?.locations?.[0]?.physicalLocation?.artifactLocation?.uri).toBe('component.js');
678
- (0, vitest_1.expect)(result?.locations?.[0]?.physicalLocation?.region?.startLine).toBe(42);
679
- (0, vitest_1.expect)(result?.properties?.isFatal).toBe(true);
680
- });
681
- (0, vitest_1.it)('handles multiple diagnostics with mixed configurations', () => {
682
- const diagnostics = [
683
- { code: 1001, message: 'Fatal error', level: errors_1.DiagnosticLevel.Fatal, filename: 'a.js' },
684
- { code: 1002, message: 'Error', level: errors_1.DiagnosticLevel.Error },
685
- { code: 1003, message: 'Warning', level: errors_1.DiagnosticLevel.Warning, location: { line: 5, column: 10 } },
686
- { code: undefined, message: 'No code', level: errors_1.DiagnosticLevel.Log },
687
- ];
688
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
689
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(4);
690
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.rules).toHaveLength(3); // Only 3 have codes
691
- });
692
- });
693
- (0, vitest_1.describe)('convertCompilerOutputToSarif', () => {
694
- (0, vitest_1.it)('converts complete compiler output to SARIF', () => {
695
- const output = {
696
- success: false,
697
- version: '1.0.0',
698
- diagnostics: [
699
- { code: 1001, message: 'Top-level error', level: errors_1.DiagnosticLevel.Error },
700
- ],
701
- results: [
702
- {
703
- code: 'bundle code',
704
- map: null,
705
- imports: [],
706
- outputConfig: {},
707
- diagnostics: [
708
- { code: 2001, message: 'Bundle error', level: errors_1.DiagnosticLevel.Warning },
709
- ],
710
- timings: {},
711
- },
712
- ],
713
- timings: {},
714
- };
715
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
716
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(2);
717
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.name).toBe('@lwc/sfdc-lwc-compiler');
718
- });
719
- (0, vitest_1.it)('uses custom tool name when provided', () => {
720
- const output = {
721
- success: true,
722
- version: '1.0.0',
723
- diagnostics: [],
724
- timings: {},
725
- };
726
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output, { toolName: 'custom-compiler' });
727
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.name).toBe('custom-compiler');
728
- });
729
- (0, vitest_1.it)('handles successful compilation with no diagnostics', () => {
730
- const output = {
731
- success: true,
732
- version: '1.0.0',
733
- diagnostics: [],
734
- timings: {},
735
- };
736
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
737
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(0);
738
- });
739
- (0, vitest_1.it)('de-duplicates diagnostics across top-level and bundles', () => {
740
- const diagnostic = {
741
- code: 1001,
742
- message: 'Duplicate',
743
- level: errors_1.DiagnosticLevel.Error,
744
- filename: 'test.js',
745
- location: { line: 10, column: 5 },
746
- };
747
- const output = {
748
- success: false,
749
- version: '1.0.0',
750
- diagnostics: [diagnostic],
751
- results: [
752
- {
753
- code: 'bundle1',
754
- map: null,
755
- imports: [],
756
- outputConfig: {},
757
- diagnostics: [diagnostic],
758
- timings: {},
759
- },
760
- {
761
- code: 'bundle2',
762
- map: null,
763
- imports: [],
764
- outputConfig: {},
765
- diagnostics: [diagnostic],
766
- timings: {},
767
- },
768
- ],
769
- timings: {},
770
- };
771
- const sarif = (0, sarif_1.convertCompilerOutputToSarif)(output);
772
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(1);
773
- });
774
- });
775
- (0, vitest_1.describe)('edge cases and integration', () => {
776
- (0, vitest_1.it)('handles Unicode characters in messages', () => {
777
- const diagnostics = [{
778
- code: 1001,
779
- message: 'Error with émojis 🎉 and ünïcödé',
780
- level: errors_1.DiagnosticLevel.Error,
781
- }];
782
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
783
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.message.text).toBe('Error with émojis 🎉 and ünïcödé');
784
- });
785
- (0, vitest_1.it)('handles special characters in filenames', () => {
786
- const diagnostics = [{
787
- code: 1001,
788
- message: 'Error',
789
- level: errors_1.DiagnosticLevel.Error,
790
- filename: 'path/to/file with spaces.js',
791
- }];
792
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
793
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.locations?.[0]?.physicalLocation?.artifactLocation?.uri).toBe('path/to/file with spaces.js');
794
- });
795
- (0, vitest_1.it)('handles very large line numbers', () => {
796
- const diagnostics = [{
797
- code: 1001,
798
- message: 'Error',
799
- level: errors_1.DiagnosticLevel.Error,
800
- location: { line: 999999, column: 999999 },
801
- }];
802
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
803
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.locations?.[0]?.physicalLocation?.region?.startLine).toBe(999999);
804
- (0, vitest_1.expect)(sarif.runs[0]?.results?.[0]?.locations?.[0]?.physicalLocation?.region?.startColumn).toBe(999999);
805
- });
806
- (0, vitest_1.it)('handles large number of diagnostics', () => {
807
- const diagnostics = Array.from({ length: 100 }, (_, i) => ({
808
- code: 1000 + i,
809
- message: `Error ${i}`,
810
- level: errors_1.DiagnosticLevel.Error,
811
- }));
812
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
813
- (0, vitest_1.expect)(sarif.runs[0].results).toHaveLength(100);
814
- (0, vitest_1.expect)(sarif.runs[0].tool.driver.rules).toHaveLength(100);
815
- });
816
- (0, vitest_1.it)('produces SARIF that matches schema structure', () => {
817
- const diagnostics = [{
818
- code: 1001,
819
- message: 'Test: Full error message',
820
- level: errors_1.DiagnosticLevel.Error,
821
- filename: 'component.js',
822
- location: { line: 10, column: 5 },
823
- url: 'https://docs.example.com/1001',
824
- }];
825
- const sarif = (0, sarif_1.convertDiagnosticsToSarif)(diagnostics);
826
- // Validate SARIF structure
827
- (0, vitest_1.expect)(sarif).toHaveProperty('version');
828
- (0, vitest_1.expect)(sarif).toHaveProperty('$schema');
829
- (0, vitest_1.expect)(sarif).toHaveProperty('runs');
830
- (0, vitest_1.expect)(sarif.runs[0]).toHaveProperty('tool');
831
- (0, vitest_1.expect)(sarif.runs[0]).toHaveProperty('results');
832
- (0, vitest_1.expect)(sarif.runs[0].tool).toHaveProperty('driver');
833
- (0, vitest_1.expect)(sarif.runs[0].tool.driver).toHaveProperty('name');
834
- });
835
- });
836
- });
837
- //# sourceMappingURL=sarif.spec.js.map