|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google Inc. All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | + |
| 9 | +import * as fs from 'fs'; |
| 10 | +import * as path from 'path'; |
| 11 | + |
| 12 | +import {mainNgcc} from '../../src/ngcc/src/main'; |
| 13 | + |
| 14 | +import {TestSupport, isInBazel, setup} from '../test_support'; |
| 15 | + |
| 16 | +function setupNodeModules(support: TestSupport): void { |
| 17 | + const corePath = path.join(process.env.TEST_SRCDIR, 'angular/packages/core/npm_package'); |
| 18 | + const commonPath = path.join(process.env.TEST_SRCDIR, 'angular/packages/common/npm_package'); |
| 19 | + |
| 20 | + const nodeModulesPath = path.join(support.basePath, 'node_modules'); |
| 21 | + const angularCoreDirectory = path.join(nodeModulesPath, '@angular/core'); |
| 22 | + const angularCommonDirectory = path.join(nodeModulesPath, '@angular/common'); |
| 23 | + |
| 24 | + // fs.symlinkSync(corePath, angularCoreDirectory); |
| 25 | + // fs.symlinkSync(commonPath, angularCommonDirectory); |
| 26 | +} |
| 27 | + |
| 28 | +describe('ngcc behavioral tests', () => { |
| 29 | + if (!isInBazel()) { |
| 30 | + // These tests should be excluded from the non-Bazel build. |
| 31 | + return; |
| 32 | + } |
| 33 | + |
| 34 | + let basePath: string; |
| 35 | + let outDir: string; |
| 36 | + let write: (fileName: string, content: string) => void; |
| 37 | + let errorSpy: jasmine.Spy&((s: string) => void); |
| 38 | + |
| 39 | + function shouldExist(fileName: string) { |
| 40 | + if (!fs.existsSync(path.resolve(outDir, fileName))) { |
| 41 | + throw new Error(`Expected ${fileName} to be emitted (outDir: ${outDir})`); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + function shouldNotExist(fileName: string) { |
| 46 | + if (fs.existsSync(path.resolve(outDir, fileName))) { |
| 47 | + throw new Error(`Did not expect ${fileName} to be emitted (outDir: ${outDir})`); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + function getContents(fileName: string): string { |
| 52 | + shouldExist(fileName); |
| 53 | + const modulePath = path.resolve(outDir, fileName); |
| 54 | + return fs.readFileSync(modulePath, 'utf8'); |
| 55 | + } |
| 56 | + |
| 57 | + function writeConfig( |
| 58 | + tsconfig: string = |
| 59 | + '{"extends": "./tsconfig-base.json", "angularCompilerOptions": {"enableIvy": "ngtsc"}}') { |
| 60 | + write('tsconfig.json', tsconfig); |
| 61 | + } |
| 62 | + |
| 63 | + beforeEach(() => { |
| 64 | + errorSpy = jasmine.createSpy('consoleError').and.callFake(console.error); |
| 65 | + const support = setup(); |
| 66 | + basePath = support.basePath; |
| 67 | + outDir = path.join(basePath, 'built'); |
| 68 | + process.chdir(basePath); |
| 69 | + write = (fileName: string, content: string) => { support.write(fileName, content); }; |
| 70 | + |
| 71 | + setupNodeModules(support); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should run ngcc without errors', () => { |
| 75 | + const nodeModulesPath = path.join(basePath, 'node_modules'); |
| 76 | + console.error(nodeModulesPath); |
| 77 | + const commonPath = path.join(nodeModulesPath, '@angular/common'); |
| 78 | + const exitCode = mainNgcc([commonPath]); |
| 79 | + |
| 80 | + expect(exitCode).toBe(0); |
| 81 | + }); |
| 82 | +}); |
0 commit comments