test(@angular-devkit/build-ng-packagr): build and test with Bazel

This commit is contained in:
Filipe Silva 2020-04-10 11:24:09 +01:00 committed by Douglas Parker
parent ef7a07050a
commit bae240e090
37 changed files with 150 additions and 554 deletions

View File

@ -169,6 +169,7 @@
"mini-css-extract-plugin": "0.9.0",
"minimatch": "3.0.4",
"minimist": "^1.2.0",
"ng-packagr": "~9.0.0",
"node-fetch": "^2.2.0",
"npm-registry-client": "8.6.0",
"open": "7.0.3",

View File

@ -0,0 +1,114 @@
# 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
licenses(["notice"]) # MIT
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("//tools:ts_json_schema.bzl", "ts_json_schema")
package(default_visibility = ["//visibility:public"])
ts_json_schema(
name = "schema",
src = "src/build/schema.json",
)
ts_library(
name = "build_ng_packagr",
srcs = glob(
include = ["src/**/*.ts"],
exclude = ["src/**/*_spec.ts"],
) + [
"//packages/angular_devkit/build_ng_packagr:src/build/schema.ts",
],
data = glob(
include = [
"package.json",
"builders.json",
"src/build/schema.json",
],
),
devmode_module = "commonjs",
devmode_target = "es2018",
module_name = "@angular-devkit/build-ng-packagr",
module_root = "src/index.d.ts",
deps = [
"//packages/angular_devkit/architect",
"@npm//@types/node",
"@npm//ng-packagr",
"@npm//rxjs",
],
)
pkg_npm(
name = "npm_package",
deps = [
":build_ng_packagr",
],
)
pkg_tar(
name = "npm_package_archive",
srcs = [":npm_package"],
extension = "tar.gz",
strip_prefix = "./npm_package",
tags = ["manual"],
)
ts_library(
name = "build_ng_packagr_test_lib",
testonly = True,
srcs = glob(
include = [
"src/test-utils.ts",
"src/**/*_spec.ts",
],
),
data = glob(["test/**/*"]),
devmode_module = "commonjs",
devmode_target = "es2018",
tsconfig = "//:tsconfig-test.json",
deps = [
":build_ng_packagr",
"//packages/angular_devkit/architect",
"//packages/angular_devkit/architect/node",
"//packages/angular_devkit/architect/testing",
"//packages/angular_devkit/core",
"@npm//@angular/common",
"@npm//@angular/compiler",
"@npm//@angular/compiler-cli",
"@npm//@angular/core",
"@npm//@angular/platform-browser",
"@npm//@angular/platform-browser-dynamic",
"@npm//@angular/router",
"@npm//@types/jasmine",
"@npm//@types/node",
"@npm//ng-packagr",
"@npm//rxjs",
"@npm//tslib",
"@npm//typescript",
"@npm//zone.js",
],
)
jasmine_node_test(
name = "build_ng_packagr_test",
srcs = ["build_ng_packagr_test_lib"],
tags = ["cpu:2"],
templated_args = ["--nobazel_patch_module_resolver"],
)
jasmine_node_test(
name = "build_ng_packagr_ve_test",
srcs = ["build_ng_packagr_test_lib"],
tags = ["cpu:2"],
templated_args = [
"--nobazel_patch_module_resolver",
"view_engine",
],
)

View File

@ -18,13 +18,12 @@ import {
} from '@angular-devkit/core'; // tslint:disable-line:no-implicit-dependencies
import { map, take, tap } from 'rxjs/operators';
const veEnabled = process.argv.includes('--ve');
// Default timeout for large specs is 2.5 minutes.
jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;
const devkitRoot = (global as unknown as { _DevKitRoot: string})._DevKitRoot;
const workspaceRoot = join(
normalize(devkitRoot),
`tests/angular_devkit/build_ng_packagr/ng-packaged${veEnabled ? '-ve' : ''}/`,
);
// This flag controls whether AOT compilation uses Ivy or View Engine (VE).
export let veEnabled = process.argv.some(arg => arg == 'view_engine');
export const workspaceRoot = join(normalize(__dirname), `../../test/ng-packaged/`);
describe('NgPackagr Builder', () => {
const host = new TestProjectHost(workspaceRoot);
@ -48,6 +47,11 @@ describe('NgPackagr Builder', () => {
);
architect = new Architect(architectHost, registry);
// Set AOT compilation to use VE if needed.
if (veEnabled) {
host.replaceInFile('tsconfig.json', `"enableIvy": true,`, `"enableIvy": false,`);
}
});
afterEach(() => host.restore().toPromise());

View File

@ -0,0 +1,24 @@
{
"$schema": "../../../../packages/angular_devkit/core/src/workspace/workspace-schema.json",
"version": 1,
"projects": {
"lib": {
"root": "projects/lib",
"projectType": "library",
"targets": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"project": "projects/lib/ng-package.json",
"tsConfig": "projects/lib/tsconfig.lib.json"
},
"configurations": {
"production": {
"tsConfig": "projects/lib/tsconfig.lib.prod.json"
}
}
}
}
}
}
}

View File

@ -18,6 +18,7 @@
]
},
"angularCompilerOptions": {
"enableIvy": true,
"disableTypeScriptVersionCheck": true
}
}

View File

@ -1,42 +0,0 @@
{
"$schema": "../../../../packages/angular_devkit/core/src/workspace/workspace-schema.json",
"version": 1,
"projects": {
"lib": {
"root": "projects/lib",
"projectType": "library",
"targets": {
"build": {
"builder": "../../../../packages/angular_devkit/build_ng_packagr:build",
"options": {
"project": "projects/lib/ng-package.json",
"tsConfig": "projects/lib/tsconfig.lib.json"
}
},
"test": {
"builder": "../../../../packages/angular_devkit/build_angular:karma",
"options": {
"main": "projects/lib/src/test.ts",
"tsConfig": "projects/lib/tsconfig.spec.json",
"karmaConfig": "projects/lib/karma.conf.js",
"browsers": "ChromeHeadlessCI",
"progress": false,
"watch": false
}
},
"lint": {
"builder": "../../../../packages/angular_devkit/build_angular:tslint",
"options": {
"tsConfig": [
"projects/lib/tsconfig.lib.json",
"projects/lib/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
}
}

View File

@ -1,24 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "es2015",
"declaration": true,
"inlineSources": true,
"types": [],
"lib": [
"dom",
"es2018"
]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}

View File

@ -1,24 +0,0 @@
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"experimentalDecorators": true,
"target": "es2015",
"module": "esnext",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
},
"angularCompilerOptions": {
"enableIvy": false,
"disableTypeScriptVersionCheck": true
}
}

View File

@ -1,42 +0,0 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
/out-tsc
# dependencies
/node_modules
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
testem.log
/typings
# e2e
/e2e/*.js
/e2e/*.map
# System Files
.DS_Store
Thumbs.db

View File

@ -1,47 +0,0 @@
{
"$schema": "../../../../packages/angular_devkit/core/src/workspace/workspace-schema.json",
"version": 1,
"projects": {
"lib": {
"root": "projects/lib",
"projectType": "library",
"targets": {
"build": {
"builder": "../../../../packages/angular_devkit/build_ng_packagr:build",
"options": {
"project": "projects/lib/ng-package.json",
"tsConfig": "projects/lib/tsconfig.lib.json"
},
"configurations": {
"production": {
"tsConfig": "projects/lib/tsconfig.lib.prod.json"
}
}
},
"test": {
"builder": "../../../../packages/angular_devkit/build_angular:karma",
"options": {
"main": "projects/lib/src/test.ts",
"tsConfig": "projects/lib/tsconfig.spec.json",
"karmaConfig": "projects/lib/karma.conf.js",
"browsers": "ChromeHeadlessCI",
"progress": false,
"watch": false
}
},
"lint": {
"builder": "../../../../packages/angular_devkit/build_angular:tslint",
"options": {
"tsConfig": [
"projects/lib/tsconfig.lib.json",
"projects/lib/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
}
}

View File

@ -1,44 +0,0 @@
/**
* @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
*/
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
customLaunchers: {
ChromeHeadlessCI: {
base: 'ChromeHeadless',
flags: ['--disable-gpu']
}
},
singleRun: false
});
};

View File

@ -1,7 +0,0 @@
{
"$schema": "../../../../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/lib",
"lib": {
"entryFile": "src/public-api.ts"
}
}

View File

@ -1,8 +0,0 @@
{
"name": "lib",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^6.0.0-rc.0 || ^6.0.0",
"@angular/core": "^6.0.0-rc.0 || ^6.0.0"
}
}

View File

@ -1,32 +0,0 @@
/**
* @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 { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LibComponent } from './lib.component';
describe('LibComponent', () => {
let component: LibComponent;
let fixture: ComponentFixture<LibComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LibComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LibComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,26 +0,0 @@
/**
* @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 { Component, OnInit } from '@angular/core';
@Component({
selector: 'lib',
template: `
<p>
lib works!
</p>
`,
styles: []
})
export class LibComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}

View File

@ -1,18 +0,0 @@
/**
* @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 { NgModule } from '@angular/core';
import { LibComponent } from './lib.component';
import { LibService } from './lib.service';
@NgModule({
imports: [
],
declarations: [LibComponent],
providers: [LibService]
})
export class LibModule { }

View File

@ -1,22 +0,0 @@
/**
* @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 { TestBed, inject } from '@angular/core/testing';
import { LibService } from './lib.service';
describe('LibService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [LibService]
});
});
it('should be created', inject([LibService], (service: LibService) => {
expect(service).toBeTruthy();
}));
});

View File

@ -1,19 +0,0 @@
/**
* @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 { Injectable } from '@angular/core';
@Injectable()
export class LibService {
constructor() { }
testEs2016() {
return ['foo', 'bar'].includes('foo');
}
}

View File

@ -1,14 +0,0 @@
/**
* @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
*/
/*
* Public API Surface of lib
*/
export * from './lib/lib.service';
export * from './lib/lib.component';
export * from './lib/lib.module';

View File

@ -1,33 +0,0 @@
/**
* @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
*/
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(path: string, deep?: boolean, filter?: RegExp): {
keys(): string[];
<T>(id: string): T;
};
};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

View File

@ -1,17 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}

View File

@ -1,129 +0,0 @@
{
"extends": "tslint:recommended",
"rulesDirectory": [
"codelyzer"
],
"rules": {
"align": {
"options": [
"parameters",
"statements"
]
},
"array-type": false,
"arrow-return-shorthand": true,
"curly": true,
"deprecation": {
"severity": "warning"
},
"eofline": true,
"import-blacklist": [
true,
"rxjs/Rx"
],
"import-spacing": true,
"indent": {
"options": [
"spaces"
]
},
"max-classes-per-file": false,
"max-line-length": [
true,
140
],
"member-ordering": [
true,
{
"order": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-empty": false,
"no-inferrable-types": [
true,
"ignore-params"
],
"no-non-null-assertion": true,
"no-redundant-jsdoc": true,
"no-switch-case-fall-through": true,
"no-var-requires": false,
"object-literal-key-quotes": [
true,
"as-needed"
],
"quotemark": [
true,
"single"
],
"semicolon": {
"options": [
"always"
]
},
"space-before-function-paren": {
"options": {
"anonymous": "never",
"asyncArrow": "always",
"constructor": "never",
"method": "never",
"named": "never"
}
},
"typedef-whitespace": {
"options": [
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
},
{
"call-signature": "onespace",
"index-signature": "onespace",
"parameter": "onespace",
"property-declaration": "onespace",
"variable-declaration": "onespace"
}
]
},
"whitespace": {
"options": [
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type",
"check-typecast"
]
},
"component-class-suffix": true,
"contextual-lifecycle": true,
"directive-class-suffix": true,
"no-conflicting-lifecycle": true,
"no-host-metadata-property": true,
"no-input-rename": true,
"no-inputs-metadata-property": true,
"no-output-native": true,
"no-output-on-prefix": true,
"no-output-rename": true,
"no-outputs-metadata-property": true,
"template-banana-in-box": true,
"template-no-negated-async": true,
"use-lifecycle-interface": true,
"use-pipe-transform-interface": true
}
}