feat(ivy): ngcc project skeleton (#24897)

PR Close #24897
This commit is contained in:
Pete Bacon Darwin
2018-07-16 08:49:56 +01:00
committed by Igor Minar
parent a673494412
commit d7aa20d912
10 changed files with 241 additions and 2 deletions

View File

@ -0,0 +1,28 @@
load("//tools:defaults.bzl", "ts_library")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
# Integration tests
ts_library(
name = "ngcc_lib",
testonly = 1,
srcs = glob([
"**/*_spec.ts",
]),
deps = [
"//packages/compiler-cli/src/ngcc",
"//packages/compiler-cli/test:test_utils",
],
)
jasmine_node_test(
name = "ngcc",
bootstrap = ["angular/tools/testing/init_node_no_angular_spec.js"],
data = [
"//packages/common:npm_package",
"//packages/core:npm_package",
],
deps = [
":ngcc_lib",
"//tools/testing:node_no_angular",
],
)

View File

@ -0,0 +1,88 @@
/**
* @license
* Copyright Google Inc. 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 * as fs from 'fs';
import * as path from 'path';
import {cat, find} from 'shelljs';
import {mainNgcc} from '../../src/ngcc/src/main';
import {TestSupport, isInBazel, setup} from '../test_support';
function setupNodeModules(support: TestSupport): void {
const corePath = path.join(process.env.TEST_SRCDIR, 'angular/packages/core/npm_package');
const commonPath = path.join(process.env.TEST_SRCDIR, 'angular/packages/common/npm_package');
const nodeModulesPath = path.join(support.basePath, 'node_modules');
const angularCoreDirectory = path.join(nodeModulesPath, '@angular/core');
const angularCommonDirectory = path.join(nodeModulesPath, '@angular/common');
// fs.symlinkSync(corePath, angularCoreDirectory);
// fs.symlinkSync(commonPath, angularCommonDirectory);
}
describe('ngcc behavioral tests', () => {
if (!isInBazel()) {
// These tests should be excluded from the non-Bazel build.
return;
}
let basePath: string;
let outDir: string;
let write: (fileName: string, content: string) => void;
let errorSpy: jasmine.Spy&((s: string) => void);
function shouldExist(fileName: string) {
if (!fs.existsSync(path.resolve(outDir, fileName))) {
throw new Error(`Expected ${fileName} to be emitted (outDir: ${outDir})`);
}
}
function shouldNotExist(fileName: string) {
if (fs.existsSync(path.resolve(outDir, fileName))) {
throw new Error(`Did not expect ${fileName} to be emitted (outDir: ${outDir})`);
}
}
function getContents(fileName: string): string {
shouldExist(fileName);
const modulePath = path.resolve(outDir, fileName);
return fs.readFileSync(modulePath, 'utf8');
}
function writeConfig(
tsconfig: string =
'{"extends": "./tsconfig-base.json", "angularCompilerOptions": {"enableIvy": "ngtsc"}}') {
write('tsconfig.json', tsconfig);
}
beforeEach(() => {
errorSpy = jasmine.createSpy('consoleError').and.callFake(console.error);
const support = setup();
basePath = support.basePath;
outDir = path.join(basePath, 'built');
process.chdir(basePath);
write = (fileName: string, content: string) => { support.write(fileName, content); };
setupNodeModules(support);
});
it('should run ngcc without errors', () => {
const nodeModulesPath = path.join(basePath, 'node_modules');
console.error(nodeModulesPath);
const commonPath = path.join(nodeModulesPath, '@angular/common');
const exitCode = mainNgcc([commonPath]);
console.warn(find('node_modules_ngtsc').filter(p => p.endsWith('.js') || p.endsWith('map')));
console.warn(cat('node_modules_ngtsc/@angular/common/fesm2015/common.js').stdout);
console.warn(cat('node_modules_ngtsc/@angular/common/fesm2015/common.js.map').stdout);
expect(exitCode).toBe(0);
});
});