33// Copyright 2019-Present Datadog, Inc.
44
55import { validateOptions } from '@dd/apps-plugin/validate' ;
6- import { resetEnableWarnings } from '@dd/core/helpers/options' ;
7- import type { Logger } from '@dd/core/types' ;
8-
9- const mockLogger : Logger = {
10- getLogger : jest . fn ( ( ) => mockLogger ) ,
11- time : jest . fn ( ) as unknown as Logger [ 'time' ] ,
12- error : jest . fn ( ) ,
13- warn : jest . fn ( ) ,
14- info : jest . fn ( ) ,
15- debug : jest . fn ( ) ,
16- } ;
17-
18- beforeEach ( ( ) => {
19- jest . clearAllMocks ( ) ;
20- resetEnableWarnings ( ) ;
21- } ) ;
226
237describe ( 'Apps Plugin - validateOptions' , ( ) => {
24- describe ( 'enable flag' , ( ) => {
25- const cases = [
26- {
27- description : 'return false when no apps config is provided' ,
28- input : { } ,
29- expected : false ,
30- } ,
31- {
32- description : 'return true when apps config is an empty object' ,
33- input : { apps : { } } ,
34- expected : true ,
35- } ,
36- {
37- description : 'respect explicit enable true' ,
38- input : { apps : { enable : true } } ,
39- expected : true ,
40- } ,
41- {
42- description : 'respect explicit enable false' ,
43- input : { apps : { enable : false } } ,
44- expected : false ,
45- } ,
46- ] ;
47-
48- test . each ( cases ) ( 'Should $description' , ( { input, expected } ) => {
49- const result = validateOptions ( input , mockLogger ) ;
50- expect ( result . enable ) . toBe ( expected ) ;
51- } ) ;
52- } ) ;
53-
54- describe ( 'enable deprecation warning for non-boolean values' , ( ) => {
55- const cases = [
56- {
57- description : 'coerce enable: 1 to true and warn' ,
58- input : { apps : { enable : 1 } } ,
59- expected : true ,
60- } ,
61- {
62- description : 'coerce enable: 0 to false and warn' ,
63- input : { apps : { enable : 0 } } ,
64- expected : false ,
65- } ,
66- {
67- description : 'coerce enable: "true" to true and warn' ,
68- input : { apps : { enable : 'true' } } ,
69- expected : true ,
70- } ,
71- ] ;
72-
73- test . each ( cases ) ( 'Should $description' , ( { input, expected } ) => {
74- const result = validateOptions (
75- input as unknown as Parameters < typeof validateOptions > [ 0 ] ,
76- mockLogger ,
77- ) ;
78- expect ( result . enable ) . toBe ( expected ) ;
79- expect ( mockLogger . warn ) . toHaveBeenCalledTimes ( 1 ) ;
80- expect ( mockLogger . warn ) . toHaveBeenCalledWith ( expect . stringContaining ( 'apps.enable' ) ) ;
81- } ) ;
82- } ) ;
83-
848 describe ( 'defaults' , ( ) => {
859 test ( 'Should set defaults when nothing is provided' , ( ) => {
86- const result = validateOptions ( { } , mockLogger ) ;
10+ const result = validateOptions ( { } ) ;
8711 expect ( result ) . toEqual ( {
8812 dryRun : true ,
89- enable : false ,
9013 include : [ ] ,
9114 identifier : undefined ,
9215 name : undefined ,
@@ -96,7 +19,7 @@ describe('Apps Plugin - validateOptions', () => {
9619 test ( 'Should set dryRun to false when DATADOG_APPS_UPLOAD_ASSETS is set' , ( ) => {
9720 process . env . DATADOG_APPS_UPLOAD_ASSETS = '1' ;
9821 try {
99- const result = validateOptions ( { apps : { } } , mockLogger ) ;
22+ const result = validateOptions ( { apps : { } } ) ;
10023 expect ( result . dryRun ) . toBe ( false ) ;
10124 } finally {
10225 delete process . env . DATADOG_APPS_UPLOAD_ASSETS ;
@@ -106,7 +29,7 @@ describe('Apps Plugin - validateOptions', () => {
10629 test ( 'Should set dryRun to false when DD_APPS_UPLOAD_ASSETS is set' , ( ) => {
10730 process . env . DD_APPS_UPLOAD_ASSETS = '1' ;
10831 try {
109- const result = validateOptions ( { apps : { } } , mockLogger ) ;
32+ const result = validateOptions ( { apps : { } } ) ;
11033 expect ( result . dryRun ) . toBe ( false ) ;
11134 } finally {
11235 delete process . env . DD_APPS_UPLOAD_ASSETS ;
@@ -116,7 +39,7 @@ describe('Apps Plugin - validateOptions', () => {
11639 test ( 'Should respect explicit dryRun over env var' , ( ) => {
11740 process . env . DATADOG_APPS_UPLOAD_ASSETS = '1' ;
11841 try {
119- const result = validateOptions ( { apps : { dryRun : true } } , mockLogger ) ;
42+ const result = validateOptions ( { apps : { dryRun : true } } ) ;
12043 expect ( result . dryRun ) . toBe ( true ) ;
12144 } finally {
12245 delete process . env . DATADOG_APPS_UPLOAD_ASSETS ;
@@ -126,21 +49,17 @@ describe('Apps Plugin - validateOptions', () => {
12649
12750 describe ( 'overrides' , ( ) => {
12851 test ( 'Should keep provided options and trim identifier' , ( ) => {
129- const result = validateOptions (
130- {
131- apps : {
132- dryRun : true ,
133- enable : true ,
134- include : [ 'public/**/*' , 'dist/**/*' ] ,
135- identifier : ' my-app ' ,
136- } ,
52+ const result = validateOptions ( {
53+ apps : {
54+ dryRun : true ,
55+ enable : true ,
56+ include : [ 'public/**/*' , 'dist/**/*' ] ,
57+ identifier : ' my-app ' ,
13758 } ,
138- mockLogger ,
139- ) ;
59+ } ) ;
14060
14161 expect ( result ) . toEqual ( {
14262 dryRun : true ,
143- enable : true ,
14463 include : [ 'public/**/*' , 'dist/**/*' ] ,
14564 identifier : 'my-app' ,
14665 name : undefined ,
0 commit comments