| 
									
										
										
										
											2020-09-23 16:38:20 +02:00
										 |  |  | const extractJSComments = require('./extract-js-comments'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const someJS = `
 | 
					
						
							|  |  |  | // single line comment
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  | a multiline comment | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var x = 'y'; // single line comment
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var y = '// single line comment'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-27 16:32:37 +02:00
										 |  |  | const someInvalidJS = `const isChange;`; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-23 16:38:20 +02:00
										 |  |  | describe('extractJSComments', () => { | 
					
						
							|  |  |  |   it('should return an object with comment keys and count values', () => { | 
					
						
							|  |  |  |     const commentCounts = { | 
					
						
							|  |  |  |       'single line comment': 2, | 
					
						
							|  |  |  |       'a multiline comment': 1 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     expect(extractJSComments(someJS)).toEqual(commentCounts); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-10-27 16:32:37 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   it('should throw an informative error if the JS is invalid', () => { | 
					
						
							|  |  |  |     expect(() => extractJSComments(someInvalidJS)).toThrow( | 
					
						
							| 
									
										
										
										
											2021-10-27 17:20:18 +02:00
										 |  |  |       `extract-js-comments could not parse the code below, this challenge has invalid syntax:
 | 
					
						
							| 
									
										
										
										
											2021-10-27 16:32:37 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | ${someInvalidJS} | 
					
						
							|  |  |  | `
 | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-09-23 16:38:20 +02:00
										 |  |  | }); |