@grafana/create-plugin 6.5.0-canary.2320.20268376971.0 → 6.5.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.
@@ -1,674 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import * as v from 'valibot';
3
-
4
- import { Context } from '../../../context.js';
5
- import i18nAddition, { schema } from './index.js';
6
-
7
- describe('i18n addition', () => {
8
- describe('schema validation', () => {
9
- it('should require locales to be provided', () => {
10
- const result = v.safeParse(schema, {});
11
- expect(result.success).toBe(false);
12
- if (!result.success) {
13
- const errorMessage = result.issues[0].message;
14
- expect(errorMessage).toContain('comma-separated list');
15
- expect(errorMessage).toContain('en-US,es-ES,sv-SE');
16
- }
17
- });
18
-
19
- it('should validate locale format', () => {
20
- const result = v.safeParse(schema, { locales: ['invalid'] });
21
- expect(result.success).toBe(false);
22
- if (!result.success) {
23
- const errorMessage = result.issues[0].message;
24
- expect(errorMessage).toContain('xx-XX');
25
- expect(errorMessage).toContain('en-US');
26
- expect(errorMessage).toContain('sv-SE');
27
- }
28
- });
29
-
30
- it('should accept valid locales as array', () => {
31
- const result = v.safeParse(schema, { locales: ['en-US', 'es-ES', 'sv-SE'] });
32
- expect(result.success).toBe(true);
33
- if (result.success) {
34
- expect(result.output.locales).toEqual(['en-US', 'es-ES', 'sv-SE']);
35
- }
36
- });
37
-
38
- it('should parse comma-separated string into array (CLI format)', () => {
39
- const result = v.safeParse(schema, { locales: 'en-US,es-ES,sv-SE' });
40
- expect(result.success).toBe(true);
41
- if (result.success) {
42
- expect(result.output.locales).toEqual(['en-US', 'es-ES', 'sv-SE']);
43
- }
44
- });
45
-
46
- it('should trim whitespace from comma-separated values', () => {
47
- const result = v.safeParse(schema, { locales: 'en-US, es-ES , sv-SE' });
48
- expect(result.success).toBe(true);
49
- if (result.success) {
50
- expect(result.output.locales).toEqual(['en-US', 'es-ES', 'sv-SE']);
51
- }
52
- });
53
- });
54
-
55
- it('should add i18n support with en-US locale', () => {
56
- const context = new Context('/virtual');
57
-
58
- // Set up a minimal plugin structure with Grafana 11.0.0 (needs backward compatibility)
59
- context.addFile(
60
- 'src/plugin.json',
61
- JSON.stringify({
62
- id: 'test-plugin',
63
- type: 'panel',
64
- name: 'Test Plugin',
65
- dependencies: {
66
- grafanaDependency: '>=11.0.0',
67
- },
68
- })
69
- );
70
- context.addFile(
71
- 'docker-compose.yaml',
72
- `services:
73
- grafana:
74
- environment:
75
- FOO: bar`
76
- );
77
- context.addFile('package.json', JSON.stringify({ dependencies: {}, devDependencies: {}, scripts: {} }));
78
- context.addFile(
79
- 'eslint.config.mjs',
80
- 'import { defineConfig } from "eslint/config";\nexport default defineConfig([]);'
81
- );
82
- context.addFile(
83
- 'src/module.ts',
84
- 'import { PanelPlugin } from "@grafana/data";\nexport const plugin = new PanelPlugin();'
85
- );
86
-
87
- const result = i18nAddition(context, { locales: ['en-US'] });
88
-
89
- // Check plugin.json was updated
90
- const pluginJson = JSON.parse(result.getFile('src/plugin.json') || '{}');
91
- expect(pluginJson.languages).toEqual(['en-US']);
92
- // Should stay at 11.0.0 for backward compatibility
93
- expect(pluginJson.dependencies.grafanaDependency).toBe('>=11.0.0');
94
-
95
- // Check locale file was created
96
- expect(result.doesFileExist('src/locales/en-US/test-plugin.json')).toBe(true);
97
- const localeContent = result.getFile('src/locales/en-US/test-plugin.json');
98
- const localeData = JSON.parse(localeContent || '{}');
99
- expect(localeData).toEqual({}); // Should be an empty object
100
-
101
- // Check package.json was updated with dependencies
102
- const packageJson = JSON.parse(result.getFile('package.json') || '{}');
103
- expect(packageJson.dependencies['@grafana/i18n']).toBe('^12.2.2');
104
- expect(packageJson.dependencies['semver']).toBe('^7.6.0');
105
- expect(packageJson.devDependencies['@types/semver']).toBe('^7.5.0');
106
- expect(packageJson.devDependencies['i18next-cli']).toBeDefined();
107
- expect(packageJson.scripts['i18n-extract']).toBe('i18next-cli extract --sync-primary');
108
-
109
- // Check docker-compose.yaml was updated with feature toggle
110
- const dockerCompose = result.getFile('docker-compose.yaml');
111
- expect(dockerCompose).toContain('localizationForPlugins');
112
-
113
- // Check module.ts was updated with backward compatibility code
114
- const moduleTs = result.getFile('src/module.ts');
115
- expect(moduleTs).toContain('initPluginTranslations');
116
- expect(moduleTs).toContain('semver');
117
- expect(moduleTs).toContain('loadResources');
118
-
119
- // Check loadResources.ts was created for backward compatibility
120
- expect(result.doesFileExist('src/loadResources.ts')).toBe(true);
121
- const loadResources = result.getFile('src/loadResources.ts');
122
- expect(loadResources).toContain('ResourceLoader');
123
-
124
- // Check i18next.config.ts was created
125
- expect(result.doesFileExist('i18next.config.ts')).toBe(true);
126
- const i18nextConfig = result.getFile('i18next.config.ts');
127
- expect(i18nextConfig).toContain('defineConfig');
128
- expect(i18nextConfig).toContain('pluginJson.id');
129
- });
130
-
131
- it('should add i18n support with multiple locales', () => {
132
- const context = new Context('/virtual');
133
-
134
- context.addFile(
135
- 'src/plugin.json',
136
- JSON.stringify({
137
- id: 'test-plugin',
138
- type: 'panel',
139
- name: 'Test Plugin',
140
- dependencies: {
141
- grafanaDependency: '>=11.0.0',
142
- },
143
- })
144
- );
145
- context.addFile(
146
- 'docker-compose.yaml',
147
- `services:
148
- grafana:
149
- environment:
150
- FOO: bar`
151
- );
152
- context.addFile('package.json', JSON.stringify({ dependencies: {}, devDependencies: {}, scripts: {} }));
153
- context.addFile(
154
- 'eslint.config.mjs',
155
- 'import { defineConfig } from "eslint/config";\nexport default defineConfig([]);'
156
- );
157
- context.addFile(
158
- 'src/module.ts',
159
- 'import { PanelPlugin } from "@grafana/data";\nexport const plugin = new PanelPlugin();'
160
- );
161
-
162
- const result = i18nAddition(context, { locales: ['en-US', 'es-ES', 'sv-SE'] });
163
-
164
- // Check plugin.json has all locales
165
- const pluginJson = JSON.parse(result.getFile('src/plugin.json') || '{}');
166
- expect(pluginJson.languages).toEqual(['en-US', 'es-ES', 'sv-SE']);
167
-
168
- // Check all locale files were created
169
- expect(result.doesFileExist('src/locales/en-US/test-plugin.json')).toBe(true);
170
- expect(result.doesFileExist('src/locales/es-ES/test-plugin.json')).toBe(true);
171
- expect(result.doesFileExist('src/locales/sv-SE/test-plugin.json')).toBe(true);
172
- });
173
-
174
- it('should handle adding additional locales when i18n is already configured', () => {
175
- const context = new Context('/virtual');
176
-
177
- // Set up a plugin with i18n already configured
178
- context.addFile(
179
- 'src/plugin.json',
180
- JSON.stringify({
181
- id: 'test-plugin',
182
- type: 'panel',
183
- name: 'Test Plugin',
184
- languages: ['en-US'], // Already configured
185
- dependencies: {
186
- grafanaDependency: '>=12.1.0',
187
- },
188
- })
189
- );
190
- context.addFile(
191
- 'docker-compose.yaml',
192
- `services:
193
- grafana:
194
- environment:
195
- GF_FEATURE_TOGGLES_ENABLE: localizationForPlugins`
196
- );
197
- context.addFile('package.json', JSON.stringify({ dependencies: {}, devDependencies: {}, scripts: {} }));
198
- context.addFile(
199
- 'eslint.config.mjs',
200
- 'import { defineConfig } from "eslint/config";\nexport default defineConfig([]);'
201
- );
202
- context.addFile(
203
- 'src/module.ts',
204
- 'import { PanelPlugin } from "@grafana/data";\nimport { initPluginTranslations } from "@grafana/i18n";\nimport pluginJson from "plugin.json";\nawait initPluginTranslations(pluginJson.id);\nexport const plugin = new PanelPlugin();'
205
- );
206
- context.addFile('src/locales/en-US/test-plugin.json', JSON.stringify({ existing: 'translation' }));
207
-
208
- const result = i18nAddition(context, { locales: ['en-US', 'es-ES'] });
209
-
210
- // Should keep existing en-US locale file unchanged
211
- const enUSContent = result.getFile('src/locales/en-US/test-plugin.json');
212
- expect(JSON.parse(enUSContent || '{}')).toEqual({ existing: 'translation' });
213
-
214
- // Should create the new es-ES locale file
215
- expect(result.doesFileExist('src/locales/es-ES/test-plugin.json')).toBe(true);
216
-
217
- // Should update plugin.json with both locales (defensive update)
218
- const pluginJson = JSON.parse(result.getFile('src/plugin.json') || '{}');
219
- expect(pluginJson.languages).toEqual(['en-US', 'es-ES']);
220
-
221
- // Should not duplicate existing configurations
222
- const moduleTs = result.getFile('src/module.ts');
223
- const initCallCount = (moduleTs?.match(/initPluginTranslations/g) || []).length;
224
- expect(initCallCount).toBe(2); // 1 import + 1 call, not duplicated
225
- });
226
-
227
- it('should handle existing feature toggles in docker-compose.yaml (Grafana >= 12.1.0)', () => {
228
- const context = new Context('/virtual');
229
-
230
- context.addFile(
231
- 'src/plugin.json',
232
- JSON.stringify({
233
- id: 'test-plugin',
234
- type: 'panel',
235
- name: 'Test Plugin',
236
- dependencies: {
237
- grafanaDependency: '>=12.1.0',
238
- },
239
- })
240
- );
241
- context.addFile(
242
- 'docker-compose.yaml',
243
- `services:
244
- grafana:
245
- environment:
246
- GF_FEATURE_TOGGLES_ENABLE: someOtherFeature`
247
- );
248
- context.addFile('package.json', JSON.stringify({ dependencies: {}, devDependencies: {}, scripts: {} }));
249
- context.addFile(
250
- 'eslint.config.mjs',
251
- 'import { defineConfig } from "eslint/config";\nexport default defineConfig([]);'
252
- );
253
- context.addFile(
254
- 'src/module.ts',
255
- 'import { PanelPlugin } from "@grafana/data";\nexport const plugin = new PanelPlugin();'
256
- );
257
-
258
- const result = i18nAddition(context, { locales: ['en-US'] });
259
-
260
- const dockerCompose = result.getFile('docker-compose.yaml');
261
- expect(dockerCompose).toContain('someOtherFeature,localizationForPlugins');
262
- });
263
-
264
- it('should work with module.tsx instead of module.ts', () => {
265
- const context = new Context('/virtual');
266
-
267
- context.addFile(
268
- 'src/plugin.json',
269
- JSON.stringify({
270
- id: 'test-plugin',
271
- type: 'panel',
272
- name: 'Test Plugin',
273
- dependencies: {
274
- grafanaDependency: '>=11.0.0',
275
- },
276
- })
277
- );
278
- context.addFile(
279
- 'docker-compose.yaml',
280
- `services:
281
- grafana:
282
- environment:
283
- FOO: bar`
284
- );
285
- context.addFile('package.json', JSON.stringify({ dependencies: {}, devDependencies: {}, scripts: {} }));
286
- context.addFile(
287
- 'eslint.config.mjs',
288
- 'import { defineConfig } from "eslint/config";\nexport default defineConfig([]);'
289
- );
290
- context.addFile(
291
- 'src/module.tsx',
292
- 'import { PanelPlugin } from "@grafana/data";\nexport const plugin = new PanelPlugin();'
293
- );
294
-
295
- const result = i18nAddition(context, { locales: ['en-US'] });
296
-
297
- const moduleTsx = result.getFile('src/module.tsx');
298
- expect(moduleTsx).toContain('@grafana/i18n');
299
- });
300
-
301
- it('should not update grafanaDependency if it is already >= 12.1.0', () => {
302
- const context = new Context('/virtual');
303
-
304
- context.addFile(
305
- 'src/plugin.json',
306
- JSON.stringify({
307
- id: 'test-plugin',
308
- type: 'panel',
309
- name: 'Test Plugin',
310
- dependencies: {
311
- grafanaDependency: '>=13.0.0',
312
- },
313
- })
314
- );
315
- context.addFile(
316
- 'docker-compose.yaml',
317
- `services:
318
- grafana:
319
- environment:
320
- FOO: bar`
321
- );
322
- context.addFile('package.json', JSON.stringify({ dependencies: {}, devDependencies: {}, scripts: {} }));
323
- context.addFile(
324
- 'eslint.config.mjs',
325
- 'import { defineConfig } from "eslint/config";\nexport default defineConfig([]);'
326
- );
327
- context.addFile(
328
- 'src/module.ts',
329
- 'import { PanelPlugin } from "@grafana/data";\nexport const plugin = new PanelPlugin();'
330
- );
331
-
332
- const result = i18nAddition(context, { locales: ['en-US'] });
333
-
334
- const pluginJson = JSON.parse(result.getFile('src/plugin.json') || '{}');
335
- expect(pluginJson.dependencies.grafanaDependency).toBe('>=13.0.0');
336
- });
337
-
338
- it('should handle plugins without existing scripts in package.json', () => {
339
- const context = new Context('/virtual');
340
-
341
- context.addFile(
342
- 'src/plugin.json',
343
- JSON.stringify({
344
- id: 'test-plugin',
345
- type: 'panel',
346
- name: 'Test Plugin',
347
- dependencies: {
348
- grafanaDependency: '>=11.0.0',
349
- },
350
- })
351
- );
352
- context.addFile(
353
- 'docker-compose.yaml',
354
- `services:
355
- grafana:
356
- environment:
357
- FOO: bar`
358
- );
359
- context.addFile('package.json', JSON.stringify({ dependencies: {}, devDependencies: {} })); // No scripts field
360
- context.addFile(
361
- 'eslint.config.mjs',
362
- 'import { defineConfig } from "eslint/config";\nexport default defineConfig([]);'
363
- );
364
- context.addFile(
365
- 'src/module.ts',
366
- 'import { PanelPlugin } from "@grafana/data";\nexport const plugin = new PanelPlugin();'
367
- );
368
-
369
- const result = i18nAddition(context, { locales: ['en-US'] });
370
-
371
- const packageJson = JSON.parse(result.getFile('package.json') || '{}');
372
- expect(packageJson.scripts['i18n-extract']).toBe('i18next-cli extract --sync-primary');
373
- });
374
-
375
- it('should not create locale files if they already exist', () => {
376
- const context = new Context('/virtual');
377
-
378
- context.addFile(
379
- 'src/plugin.json',
380
- JSON.stringify({
381
- id: 'test-plugin',
382
- type: 'panel',
383
- name: 'Test Plugin',
384
- dependencies: {
385
- grafanaDependency: '>=12.1.0',
386
- },
387
- })
388
- );
389
- context.addFile(
390
- 'docker-compose.yaml',
391
- `services:
392
- grafana:
393
- environment:
394
- FOO: bar`
395
- );
396
- context.addFile('package.json', JSON.stringify({ dependencies: {}, devDependencies: {}, scripts: {} }));
397
- context.addFile(
398
- 'eslint.config.mjs',
399
- 'import { defineConfig } from "eslint/config";\nexport default defineConfig([]);'
400
- );
401
- context.addFile(
402
- 'src/module.ts',
403
- 'import { PanelPlugin } from "@grafana/data";\nexport const plugin = new PanelPlugin();'
404
- );
405
- // Pre-existing locale file with custom content
406
- const customTranslations = JSON.stringify({ custom: { key: 'value' } }, null, 2);
407
- context.addFile('src/locales/en-US/test-plugin.json', customTranslations);
408
-
409
- const result = i18nAddition(context, { locales: ['en-US'] });
410
-
411
- // The existing locale file should remain unchanged
412
- const localeContent = result.getFile('src/locales/en-US/test-plugin.json');
413
- expect(localeContent).toBe(customTranslations);
414
- });
415
-
416
- it('should not add i18n initialization if already present', () => {
417
- const context = new Context('/virtual');
418
-
419
- context.addFile(
420
- 'src/plugin.json',
421
- JSON.stringify({
422
- id: 'test-plugin',
423
- type: 'panel',
424
- name: 'Test Plugin',
425
- dependencies: {
426
- grafanaDependency: '>=12.1.0',
427
- },
428
- })
429
- );
430
- context.addFile(
431
- 'docker-compose.yaml',
432
- `services:
433
- grafana:
434
- environment:
435
- FOO: bar`
436
- );
437
- context.addFile('package.json', JSON.stringify({ dependencies: {}, devDependencies: {}, scripts: {} }));
438
- context.addFile(
439
- 'eslint.config.mjs',
440
- 'import { defineConfig } from "eslint/config";\nexport default defineConfig([]);'
441
- );
442
- const moduleWithI18n = `import { PanelPlugin } from "@grafana/data";
443
- import { initPluginTranslations } from "@grafana/i18n";
444
- import pluginJson from "plugin.json";
445
-
446
- await initPluginTranslations(pluginJson.id);
447
-
448
- export const plugin = new PanelPlugin();`;
449
- context.addFile('src/module.ts', moduleWithI18n);
450
-
451
- const result = i18nAddition(context, { locales: ['en-US'] });
452
-
453
- // The module file should remain unchanged (no duplicate imports/calls)
454
- const moduleTs = result.getFile('src/module.ts');
455
- const initCallCount = (moduleTs?.match(/initPluginTranslations/g) || []).length;
456
- expect(initCallCount).toBe(2); // 1 import + 1 call
457
- });
458
-
459
- it('should not create i18next.config.ts if it already exists', () => {
460
- const context = new Context('/virtual');
461
-
462
- context.addFile(
463
- 'src/plugin.json',
464
- JSON.stringify({
465
- id: 'test-plugin',
466
- type: 'panel',
467
- name: 'Test Plugin',
468
- dependencies: {
469
- grafanaDependency: '>=12.1.0',
470
- },
471
- })
472
- );
473
- context.addFile(
474
- 'docker-compose.yaml',
475
- `services:
476
- grafana:
477
- environment:
478
- FOO: bar`
479
- );
480
- context.addFile('package.json', JSON.stringify({ dependencies: {}, devDependencies: {}, scripts: {} }));
481
- context.addFile(
482
- 'eslint.config.mjs',
483
- 'import { defineConfig } from "eslint/config";\nexport default defineConfig([]);'
484
- );
485
- context.addFile(
486
- 'src/module.ts',
487
- 'import { PanelPlugin } from "@grafana/data";\nexport const plugin = new PanelPlugin();'
488
- );
489
- const customI18nextConfig = 'export default { custom: true };';
490
- context.addFile('i18next.config.ts', customI18nextConfig);
491
-
492
- const result = i18nAddition(context, { locales: ['en-US'] });
493
-
494
- // The existing i18next.config.ts should remain unchanged
495
- const i18nextConfig = result.getFile('i18next.config.ts');
496
- expect(i18nextConfig).toBe(customI18nextConfig);
497
- });
498
-
499
- it('should not create loadResources.ts if it already exists', () => {
500
- const context = new Context('/virtual');
501
-
502
- context.addFile(
503
- 'src/plugin.json',
504
- JSON.stringify({
505
- id: 'test-plugin',
506
- type: 'panel',
507
- name: 'Test Plugin',
508
- dependencies: {
509
- grafanaDependency: '>=11.0.0',
510
- },
511
- })
512
- );
513
- context.addFile(
514
- 'docker-compose.yaml',
515
- `services:
516
- grafana:
517
- environment:
518
- FOO: bar`
519
- );
520
- context.addFile('package.json', JSON.stringify({ dependencies: {}, devDependencies: {}, scripts: {} }));
521
- context.addFile(
522
- 'eslint.config.mjs',
523
- 'import { defineConfig } from "eslint/config";\nexport default defineConfig([]);'
524
- );
525
- context.addFile(
526
- 'src/module.ts',
527
- 'import { PanelPlugin } from "@grafana/data";\nexport const plugin = new PanelPlugin();'
528
- );
529
- const customLoadResources = 'export const loadResources = () => {};';
530
- context.addFile('src/loadResources.ts', customLoadResources);
531
-
532
- const result = i18nAddition(context, { locales: ['en-US'] });
533
-
534
- // The existing loadResources.ts should remain unchanged
535
- const loadResources = result.getFile('src/loadResources.ts');
536
- expect(loadResources).toBe(customLoadResources);
537
- });
538
-
539
- it('should not add i18n-extract script if it already exists', () => {
540
- const context = new Context('/virtual');
541
-
542
- context.addFile(
543
- 'src/plugin.json',
544
- JSON.stringify({
545
- id: 'test-plugin',
546
- type: 'panel',
547
- name: 'Test Plugin',
548
- dependencies: {
549
- grafanaDependency: '>=12.1.0',
550
- },
551
- })
552
- );
553
- context.addFile(
554
- 'docker-compose.yaml',
555
- `services:
556
- grafana:
557
- environment:
558
- FOO: bar`
559
- );
560
- context.addFile(
561
- 'package.json',
562
- JSON.stringify({
563
- dependencies: {},
564
- devDependencies: {},
565
- scripts: {
566
- 'i18n-extract': 'custom extract command',
567
- },
568
- })
569
- );
570
- context.addFile(
571
- 'eslint.config.mjs',
572
- 'import { defineConfig } from "eslint/config";\nexport default defineConfig([]);'
573
- );
574
- context.addFile(
575
- 'src/module.ts',
576
- 'import { PanelPlugin } from "@grafana/data";\nexport const plugin = new PanelPlugin();'
577
- );
578
-
579
- const result = i18nAddition(context, { locales: ['en-US'] });
580
-
581
- // The existing i18n-extract script should remain unchanged
582
- const packageJson = JSON.parse(result.getFile('package.json') || '{}');
583
- expect(packageJson.scripts['i18n-extract']).toBe('custom extract command');
584
- });
585
-
586
- it('should add feature toggle to docker-compose for Grafana >= 12.1.0', () => {
587
- const context = new Context('/virtual');
588
-
589
- context.addFile(
590
- 'src/plugin.json',
591
- JSON.stringify({
592
- id: 'test-plugin',
593
- type: 'panel',
594
- name: 'Test Plugin',
595
- dependencies: {
596
- grafanaDependency: '>=12.1.0',
597
- },
598
- })
599
- );
600
- context.addFile(
601
- 'docker-compose.yaml',
602
- `services:
603
- grafana:
604
- environment:
605
- FOO: bar`
606
- );
607
- context.addFile('package.json', JSON.stringify({ dependencies: {}, devDependencies: {}, scripts: {} }));
608
- context.addFile(
609
- 'eslint.config.mjs',
610
- 'import { defineConfig } from "eslint/config";\nexport default defineConfig([]);'
611
- );
612
- context.addFile(
613
- 'src/module.ts',
614
- 'import { PanelPlugin } from "@grafana/data";\nexport const plugin = new PanelPlugin();'
615
- );
616
-
617
- const result = i18nAddition(context, { locales: ['en-US'] });
618
-
619
- const dockerCompose = result.getFile('docker-compose.yaml');
620
- expect(dockerCompose).toContain('GF_FEATURE_TOGGLES_ENABLE: localizationForPlugins');
621
-
622
- // Should not add backward compatibility dependencies
623
- const packageJson = JSON.parse(result.getFile('package.json') || '{}');
624
- expect(packageJson.dependencies['semver']).toBeUndefined();
625
- expect(packageJson.devDependencies['@types/semver']).toBeUndefined();
626
-
627
- // Should not create loadResources.ts
628
- expect(result.doesFileExist('src/loadResources.ts')).toBe(false);
629
-
630
- // Module should not have semver imports
631
- const moduleTs = result.getFile('src/module.ts');
632
- expect(moduleTs).not.toContain('semver');
633
- expect(moduleTs).not.toContain('loadResources');
634
- });
635
-
636
- it('should not duplicate feature toggle if already present', () => {
637
- const context = new Context('/virtual');
638
-
639
- context.addFile(
640
- 'src/plugin.json',
641
- JSON.stringify({
642
- id: 'test-plugin',
643
- type: 'panel',
644
- name: 'Test Plugin',
645
- dependencies: {
646
- grafanaDependency: '>=12.1.0',
647
- },
648
- })
649
- );
650
- context.addFile(
651
- 'docker-compose.yaml',
652
- `services:
653
- grafana:
654
- environment:
655
- GF_FEATURE_TOGGLES_ENABLE: localizationForPlugins`
656
- );
657
- context.addFile('package.json', JSON.stringify({ dependencies: {}, devDependencies: {}, scripts: {} }));
658
- context.addFile(
659
- 'eslint.config.mjs',
660
- 'import { defineConfig } from "eslint/config";\nexport default defineConfig([]);'
661
- );
662
- context.addFile(
663
- 'src/module.ts',
664
- 'import { PanelPlugin } from "@grafana/data";\nexport const plugin = new PanelPlugin();'
665
- );
666
-
667
- const result = i18nAddition(context, { locales: ['en-US'] });
668
-
669
- const dockerCompose = result.getFile('docker-compose.yaml');
670
- // Should only have one instance of localizationForPlugins
671
- const toggleCount = (dockerCompose?.match(/localizationForPlugins/g) || []).length;
672
- expect(toggleCount).toBe(1);
673
- });
674
- });