| 
									
										
										
										
											2020-11-11 15:29:43 +00:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | import {FileSystem} from '../../../src/ngtsc/file_system'; | 
					
						
							|  |  |  | import {checkExpectations} from '../test_helpers/check_expectations'; | 
					
						
							| 
									
										
										
										
											2020-11-12 19:43:35 +00:00
										 |  |  | import {CompileResult, initMockTestFileSystem} from '../test_helpers/compile_test'; | 
					
						
							| 
									
										
										
										
											2020-12-02 14:12:03 +00:00
										 |  |  | import {CompilationMode, ComplianceTest, getAllComplianceTests} from '../test_helpers/get_compliance_tests'; | 
					
						
							| 
									
										
										
										
											2020-11-26 22:09:48 +01:00
										 |  |  | import {checkErrors, checkNoUnexpectedErrors} from './check_errors'; | 
					
						
							| 
									
										
										
										
											2020-11-11 15:29:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Set up jasmine specs for each of the compliance tests. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param type A description of the type of tests being run. | 
					
						
							|  |  |  |  * @param compileFn The function that will do the compilation of the source files | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-11-12 19:43:35 +00:00
										 |  |  | export function runTests( | 
					
						
							| 
									
										
										
										
											2020-12-02 14:12:03 +00:00
										 |  |  |     type: CompilationMode, compileFn: (fs: FileSystem, test: ComplianceTest) => CompileResult) { | 
					
						
							| 
									
										
										
										
											2020-11-11 15:29:43 +00:00
										 |  |  |   describe(`compliance tests (${type})`, () => { | 
					
						
							|  |  |  |     for (const test of getAllComplianceTests()) { | 
					
						
							| 
									
										
										
										
											2020-12-02 14:12:03 +00:00
										 |  |  |       if (!test.compilationModeFilter.includes(type)) { | 
					
						
							| 
									
										
										
										
											2020-11-12 19:43:35 +00:00
										 |  |  |         continue; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-11 15:29:43 +00:00
										 |  |  |       describe(`[${test.relativePath}]`, () => { | 
					
						
							|  |  |  |         const itFn = test.focusTest ? fit : test.excludeTest ? xit : it; | 
					
						
							|  |  |  |         itFn(test.description, () => { | 
					
						
							| 
									
										
										
										
											2020-12-02 14:12:03 +00:00
										 |  |  |           if (type === 'linked compile' && test.compilerOptions?.target === 'ES5') { | 
					
						
							| 
									
										
										
										
											2020-11-12 19:43:35 +00:00
										 |  |  |             throw new Error( | 
					
						
							|  |  |  |                 `The "${type}" scenario does not support ES5 output.\n` + | 
					
						
							| 
									
										
										
										
											2020-12-02 14:12:03 +00:00
										 |  |  |                 `Did you mean to set \`"compilationModeFilter": ["full compile"]\` in "${ | 
					
						
							| 
									
										
										
										
											2020-11-12 19:43:35 +00:00
										 |  |  |                     test.relativePath}"?`);
 | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-11 15:29:43 +00:00
										 |  |  |           const fs = initMockTestFileSystem(test.realTestPath); | 
					
						
							| 
									
										
										
										
											2020-11-12 19:43:35 +00:00
										 |  |  |           const {errors} = compileFn(fs, test); | 
					
						
							| 
									
										
										
										
											2020-11-11 15:29:43 +00:00
										 |  |  |           for (const expectation of test.expectations) { | 
					
						
							| 
									
										
										
										
											2020-11-12 19:43:35 +00:00
										 |  |  |             if (expectation.expectedErrors.length > 0) { | 
					
						
							|  |  |  |               checkErrors( | 
					
						
							|  |  |  |                   test.relativePath, expectation.failureMessage, expectation.expectedErrors, | 
					
						
							|  |  |  |                   errors); | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2020-11-26 22:09:48 +01:00
										 |  |  |               checkNoUnexpectedErrors(test.relativePath, errors); | 
					
						
							| 
									
										
										
										
											2020-11-12 19:43:35 +00:00
										 |  |  |               checkExpectations( | 
					
						
							|  |  |  |                   fs, test.relativePath, expectation.failureMessage, expectation.files, | 
					
						
							|  |  |  |                   expectation.extraChecks); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-11-11 15:29:43 +00:00
										 |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } |