| 
									
										
										
										
											2017-09-28 16:18:12 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2017-09-28 16:18:12 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-02 15:59:57 -07:00
										 |  |  | import {sha1} from '../../cli/sha1'; | 
					
						
							| 
									
										
										
										
											2017-09-28 16:18:12 -07:00
										 |  |  | import {Filesystem} from '../src/filesystem'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class MockFilesystem implements Filesystem { | 
					
						
							|  |  |  |   private files = new Map<string, string>(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |   constructor(files: {[name: string]: string|undefined}) { | 
					
						
							|  |  |  |     Object.keys(files).forEach(path => this.files.set(path, files[path]!)); | 
					
						
							| 
									
										
										
										
											2017-09-28 16:18:12 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   async list(dir: string): Promise<string[]> { | 
					
						
							|  |  |  |     return Array.from(this.files.keys()).filter(path => path.startsWith(dir)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |   async read(path: string): Promise<string> { | 
					
						
							|  |  |  |     return this.files.get(path)!; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-09-28 16:18:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |   async hash(path: string): Promise<string> { | 
					
						
							|  |  |  |     return sha1(this.files.get(path)!); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-10-02 15:59:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |   async write(path: string, contents: string): Promise<void> { | 
					
						
							|  |  |  |     this.files.set(path, contents); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  | } |