1
1
const fs = require ( 'fs' ) ;
2
2
3
- let plugins = fs . readFileSync ( './plugins.json' ) . toString ( ) ;
3
+ const plugins = fs . readFileSync ( './plugins.json' ) . toString ( ) ;
4
4
5
5
// helper function
6
6
const countPluginKey = ( plugins , key ) => plugins
@@ -12,15 +12,32 @@ describe('plugins', () => {
12
12
} ) ;
13
13
14
14
it ( 'should have all required keys' , ( ) => {
15
- plugins = JSON . parse ( plugins ) ;
16
- const pluginsCount = plugins . length ;
15
+ const parsed = JSON . parse ( plugins ) ;
16
+ const pluginsCount = parsed . length ;
17
17
18
- const nameCount = countPluginKey ( plugins , 'name' ) ;
19
- const descriptionCount = countPluginKey ( plugins , 'description' ) ;
20
- const githubUrlCount = countPluginKey ( plugins , 'githubUrl' ) ;
18
+ const nameCount = countPluginKey ( parsed , 'name' ) ;
19
+ const descriptionCount = countPluginKey ( parsed , 'description' ) ;
20
+ const githubUrlCount = countPluginKey ( parsed , 'githubUrl' ) ;
21
21
22
22
expect ( nameCount ) . toBe ( pluginsCount ) ;
23
23
expect ( descriptionCount ) . toBe ( pluginsCount ) ;
24
24
expect ( githubUrlCount ) . toBe ( pluginsCount ) ;
25
25
} ) ;
26
+
27
+ it ( 'should be unique' , ( ) => {
28
+ const parsed = JSON . parse ( plugins ) ;
29
+ const pluginsCount = parsed . length ;
30
+
31
+ // create an array only containing the plugin names
32
+ const pluginNames = parsed . map ( ( plugin ) => plugin . name ) ;
33
+
34
+ const uniquePlugins = [ ] ;
35
+ pluginNames . forEach ( ( plugin ) => {
36
+ if ( uniquePlugins . indexOf ( plugin ) === - 1 ) uniquePlugins . push ( plugin )
37
+ } ) ;
38
+
39
+ const uniquePluginsCount = uniquePlugins . length ;
40
+
41
+ expect ( pluginsCount ) . toBe ( uniquePluginsCount ) ;
42
+ } ) ;
26
43
} ) ;
0 commit comments