File tree 3 files changed +25
-3
lines changed
tests/legacy-cli/e2e/tests/commands/config
3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ const validCliPaths = new Map<
24
24
25
25
[ 'cli.analytics' , undefined ] ,
26
26
[ 'cli.analyticsSharing.tracking' , undefined ] ,
27
- [ 'cli.analyticsSharing.uuid' , ( v ) => ( v ? `${ v } ` : uuidV4 ( ) ) ] ,
27
+ [ 'cli.analyticsSharing.uuid' , ( v ) => ( v === '' ? uuidV4 ( ) : `${ v } ` ) ] ,
28
28
] ) ;
29
29
30
30
/**
@@ -80,7 +80,15 @@ function normalizeValue(value: string | undefined | boolean | number): JsonValue
80
80
return + valueString ;
81
81
}
82
82
83
- return parseJson ( valueString ) ?? value ?? undefined ;
83
+ try {
84
+ // We use `JSON.parse` instead of `parseJson` because the latter will parse UUIDs
85
+ // and convert them into a numberic entities.
86
+ // Example: 73b61974-182c-48e4-b4c6-30ddf08c5c98 -> 73.
87
+ // These values should never contain comments, therefore using `JSON.parse` is safe.
88
+ return JSON . parse ( valueString ) ;
89
+ } catch {
90
+ return value ;
91
+ }
84
92
}
85
93
86
94
export class ConfigCommand extends Command < ConfigCommandSchema > {
Original file line number Diff line number Diff line change 73
73
},
74
74
"uuid" : {
75
75
"description" : " Analytics sharing info universally unique identifier." ,
76
- "type" : " string"
76
+ "type" : " string" ,
77
+ "format" : " uuid"
77
78
}
78
79
}
79
80
}
Original file line number Diff line number Diff line change @@ -24,4 +24,17 @@ export default async function () {
24
24
await ng ( 'config' , 'schematics' ) ;
25
25
await ng ( 'config' , 'schematics' , 'undefined' ) ;
26
26
await expectToFail ( ( ) => ng ( 'config' , 'schematics' ) ) ;
27
+
28
+ /**
29
+ * `ng config cli.analyticsSharing.uuid ""` should generate new random user ID.
30
+ * @see : https://angular.io/cli/usage-analytics-gathering#per-user-tracking
31
+ */
32
+ await ng ( 'config' , 'cli.analyticsSharing.uuid' , '' ) ;
33
+ const { stdout : stdout4 } = await ng ( 'config' , 'cli.analyticsSharing.uuid' ) ;
34
+ console . log ( stdout4 ) ;
35
+ if ( ! / (?: u r n : u u i d : ) ? [ 0 - 9 a - f ] { 8 } - (?: [ 0 - 9 a - f ] { 4 } - ) { 3 } [ 0 - 9 a - f ] { 12 } / i. test ( stdout4 ) ) {
36
+ throw new Error (
37
+ `Expected "cli.analyticsSharing.uuid" to be a UUID, received "${ JSON . stringify ( stdout4 ) } ".` ,
38
+ ) ;
39
+ }
27
40
}
You can’t perform that action at this time.
0 commit comments