test(bazel): re-enable ng_package golden testing on ci (#27829)

* Enables the ng_package golden testing on the CI
* Fixes the ng_package golden testing for Windows

PR Close #27829
This commit is contained in:
Paul Gschwendtner 2018-12-25 23:16:56 +01:00 committed by Kara Erickson
parent 8122970f63
commit ac5f5ed0a6
5 changed files with 47 additions and 22 deletions

View File

@ -33,6 +33,7 @@ ts_library(
srcs = ["common_package.spec.ts"],
deps = [
"//packages:types",
"//packages/private/testing",
"@ngdeps//@types/shelljs",
],
)
@ -63,9 +64,10 @@ jasmine_node_test(
"example_package.golden",
"//packages/bazel/test/ng_package/example:npm_package",
],
# TODO(alexeagle): re-enable this test
# see https://github.com/angular/angular/pull/22933
tags = ["manual"],
# We don't want to run the example_package golden test with Ivy yet. Currently the golden
# file is based on non-ivy output and therefore won't work for ngc and Ivy at the same time.
# TODO: We should be able to have another golden for ivy-aot as well.
tags = ["no-ivy-aot"],
deps = ["@ngdeps//diff"],
)
@ -73,10 +75,10 @@ nodejs_binary(
name = "example_package.accept",
testonly = True,
data = [
"example_package.golden",
":example_spec_lib",
"//packages/bazel/test/ng_package/example:npm_package",
"@ngdeps//diff",
":example_spec_lib",
"example_package.golden",
],
entry_point = "angular/packages/bazel/test/ng_package/example_package.spec.js",
templated_args = ["--accept"],

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {obsoleteInIvy} from '@angular/private/testing';
import * as fs from 'fs';
import * as path from 'path';
import * as shx from 'shelljs';
@ -92,6 +93,14 @@ describe('@angular/common ng_package', () => {
.toMatch('//# sourceMappingURL=testing.js.map');
});
describe('secondary entry-point', () => {
obsoleteInIvy(
`now that we don't need metadata files, we don't need these redirects to help resolve paths to them`)
.it('should contain a root type definition re-export', () => {
expect(shx.cat('./testing.d.ts')).toContain(`export * from './testing/testing';`);
});
});
describe('should have module resolution properties in the package.json file for', () => {
// https://github.com/angular/common-builds/blob/master/package.json

View File

@ -224,12 +224,13 @@ describe('@angular/core ng_package', () => {
describe('typings', () => {
const typingsFile = p `testing/index.d.ts`;
it('should have a typings file',
() => { expect(shx.cat(typingsFile)).toContain('export * from \'./public_api\';'); });
() => { expect(shx.cat(typingsFile)).toContain(`export * from './public_api';`); });
obsoleteInIvy(
'now that we don\'t need metadata files, we don\'t need these redirects to help resolve paths to them')
.it('should have an \'redirect\' d.ts file in the parent dir',
() => { expect(shx.cat('testing.d.ts')).toContain(`export *`); });
.it('should have an \'redirect\' d.ts file in the parent dir', () => {
expect(shx.cat('testing.d.ts')).toContain(`export * from './testing/testing';`);
});
});
obsoleteInIvy('metadata files are no longer needed or produced in Ivy')

View File

@ -1,3 +1,4 @@
README.md
arbitrary-npm-package-main.js
arbitrary_bin.txt
arbitrary_genfiles.txt
@ -44,7 +45,6 @@ fesm5
index.d.ts
mymodule.d.ts
package.json
README.md
secondary
secondary/index.d.ts
secondary/package.json
@ -54,6 +54,16 @@ secondary
secondary.d.ts
secondary.metadata.json
some-file.txt
--- README.md ---
Angular
=======
The sources for this package are in the main [Angular](https://github.com/angular/angular) repo. Please file issues and pull requests against that repo.
License: MIT
--- arbitrary-npm-package-main.js ---
/**
@ -683,16 +693,6 @@ export declare class MyModule {
"es2015": "./fesm2015/example.js"
}
--- README.md ---
Angular
=======
The sources for this package are in the main [Angular](https://github.com/angular/angular) repo. Please file issues and pull requests against that repo.
License: MIT
--- secondary/index.d.ts ---
/**

View File

@ -37,7 +37,9 @@ const packagesToTest: TestPackage[] = [
function getIndentedDirectoryStructure(directoryPath: string, depth = 0): string[] {
const result: string[] = [];
if (fs.statSync(directoryPath).isDirectory()) {
fs.readdirSync(directoryPath).forEach(f => {
// We need to sort the directories because on Windows "readdirsync" is not sorted. Since we
// compare these in a golden file, the order needs to be consistent across different platforms.
fs.readdirSync(directoryPath).sort().forEach(f => {
const filePath = path.posix.join(directoryPath, f);
result.push(
' '.repeat(depth) + filePath, ...getIndentedDirectoryStructure(filePath, depth + 1));
@ -56,14 +58,16 @@ function getIndentedDirectoryStructure(directoryPath: string, depth = 0): string
function getDescendantFilesContents(directoryPath: string): string[] {
const result: string[] = [];
if (fs.statSync(directoryPath).isDirectory()) {
fs.readdirSync(directoryPath).forEach(dir => {
// We need to sort the directories because on Windows "readdirsync" is not sorted. Since we
// compare these in a golden file, the order needs to be consistent across different platforms.
fs.readdirSync(directoryPath).sort().forEach(dir => {
result.push(...getDescendantFilesContents(path.posix.join(directoryPath, dir)));
});
}
// Note that we don't want to include ".map" files in the golden file since these are not
// consistent across different environments (e.g. path delimiters)
else if (path.extname(directoryPath) !== '.map') {
result.push(`--- ${directoryPath} ---`, '', fs.readFileSync(directoryPath, 'utf-8'), '');
result.push(`--- ${directoryPath} ---`, '', readFileContents(directoryPath), '');
}
return result;
}
@ -115,6 +119,15 @@ function runPackageGoldTest(testPackage: TestPackage) {
});
}
/**
* Reads the contents of the specified file. Additionally it strips all carriage return (CR)
* characters from the given content. We do this since the content that will be pulled into the
* golden file needs to be consistent across all platforms.
*/
function readFileContents(filePath: string): string {
return fs.readFileSync(filePath, 'utf8').replace(/\r/g, '');
}
if (require.main === module) {
const args = process.argv.slice(2);
const acceptingNewGold = (args[0] === '--accept');