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:
parent
8122970f63
commit
ac5f5ed0a6
|
@ -33,6 +33,7 @@ ts_library(
|
||||||
srcs = ["common_package.spec.ts"],
|
srcs = ["common_package.spec.ts"],
|
||||||
deps = [
|
deps = [
|
||||||
"//packages:types",
|
"//packages:types",
|
||||||
|
"//packages/private/testing",
|
||||||
"@ngdeps//@types/shelljs",
|
"@ngdeps//@types/shelljs",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -63,9 +64,10 @@ jasmine_node_test(
|
||||||
"example_package.golden",
|
"example_package.golden",
|
||||||
"//packages/bazel/test/ng_package/example:npm_package",
|
"//packages/bazel/test/ng_package/example:npm_package",
|
||||||
],
|
],
|
||||||
# TODO(alexeagle): re-enable this test
|
# We don't want to run the example_package golden test with Ivy yet. Currently the golden
|
||||||
# see https://github.com/angular/angular/pull/22933
|
# file is based on non-ivy output and therefore won't work for ngc and Ivy at the same time.
|
||||||
tags = ["manual"],
|
# TODO: We should be able to have another golden for ivy-aot as well.
|
||||||
|
tags = ["no-ivy-aot"],
|
||||||
deps = ["@ngdeps//diff"],
|
deps = ["@ngdeps//diff"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -73,10 +75,10 @@ nodejs_binary(
|
||||||
name = "example_package.accept",
|
name = "example_package.accept",
|
||||||
testonly = True,
|
testonly = True,
|
||||||
data = [
|
data = [
|
||||||
|
"example_package.golden",
|
||||||
|
":example_spec_lib",
|
||||||
"//packages/bazel/test/ng_package/example:npm_package",
|
"//packages/bazel/test/ng_package/example:npm_package",
|
||||||
"@ngdeps//diff",
|
"@ngdeps//diff",
|
||||||
":example_spec_lib",
|
|
||||||
"example_package.golden",
|
|
||||||
],
|
],
|
||||||
entry_point = "angular/packages/bazel/test/ng_package/example_package.spec.js",
|
entry_point = "angular/packages/bazel/test/ng_package/example_package.spec.js",
|
||||||
templated_args = ["--accept"],
|
templated_args = ["--accept"],
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {obsoleteInIvy} from '@angular/private/testing';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as shx from 'shelljs';
|
import * as shx from 'shelljs';
|
||||||
|
@ -92,6 +93,14 @@ describe('@angular/common ng_package', () => {
|
||||||
.toMatch('//# sourceMappingURL=testing.js.map');
|
.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', () => {
|
describe('should have module resolution properties in the package.json file for', () => {
|
||||||
// https://github.com/angular/common-builds/blob/master/package.json
|
// https://github.com/angular/common-builds/blob/master/package.json
|
||||||
|
|
|
@ -224,12 +224,13 @@ describe('@angular/core ng_package', () => {
|
||||||
describe('typings', () => {
|
describe('typings', () => {
|
||||||
const typingsFile = p `testing/index.d.ts`;
|
const typingsFile = p `testing/index.d.ts`;
|
||||||
it('should have a typings file',
|
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(
|
obsoleteInIvy(
|
||||||
'now that we don\'t need metadata files, we don\'t need these redirects to help resolve paths to them')
|
'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',
|
.it('should have an \'redirect\' d.ts file in the parent dir', () => {
|
||||||
() => { expect(shx.cat('testing.d.ts')).toContain(`export *`); });
|
expect(shx.cat('testing.d.ts')).toContain(`export * from './testing/testing';`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
obsoleteInIvy('metadata files are no longer needed or produced in Ivy')
|
obsoleteInIvy('metadata files are no longer needed or produced in Ivy')
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
README.md
|
||||||
arbitrary-npm-package-main.js
|
arbitrary-npm-package-main.js
|
||||||
arbitrary_bin.txt
|
arbitrary_bin.txt
|
||||||
arbitrary_genfiles.txt
|
arbitrary_genfiles.txt
|
||||||
|
@ -44,7 +45,6 @@ fesm5
|
||||||
index.d.ts
|
index.d.ts
|
||||||
mymodule.d.ts
|
mymodule.d.ts
|
||||||
package.json
|
package.json
|
||||||
README.md
|
|
||||||
secondary
|
secondary
|
||||||
secondary/index.d.ts
|
secondary/index.d.ts
|
||||||
secondary/package.json
|
secondary/package.json
|
||||||
|
@ -54,6 +54,16 @@ secondary
|
||||||
secondary.d.ts
|
secondary.d.ts
|
||||||
secondary.metadata.json
|
secondary.metadata.json
|
||||||
some-file.txt
|
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 ---
|
--- arbitrary-npm-package-main.js ---
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -683,16 +693,6 @@ export declare class MyModule {
|
||||||
"es2015": "./fesm2015/example.js"
|
"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 ---
|
--- secondary/index.d.ts ---
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,7 +37,9 @@ const packagesToTest: TestPackage[] = [
|
||||||
function getIndentedDirectoryStructure(directoryPath: string, depth = 0): string[] {
|
function getIndentedDirectoryStructure(directoryPath: string, depth = 0): string[] {
|
||||||
const result: string[] = [];
|
const result: string[] = [];
|
||||||
if (fs.statSync(directoryPath).isDirectory()) {
|
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);
|
const filePath = path.posix.join(directoryPath, f);
|
||||||
result.push(
|
result.push(
|
||||||
' '.repeat(depth) + filePath, ...getIndentedDirectoryStructure(filePath, depth + 1));
|
' '.repeat(depth) + filePath, ...getIndentedDirectoryStructure(filePath, depth + 1));
|
||||||
|
@ -56,14 +58,16 @@ function getIndentedDirectoryStructure(directoryPath: string, depth = 0): string
|
||||||
function getDescendantFilesContents(directoryPath: string): string[] {
|
function getDescendantFilesContents(directoryPath: string): string[] {
|
||||||
const result: string[] = [];
|
const result: string[] = [];
|
||||||
if (fs.statSync(directoryPath).isDirectory()) {
|
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)));
|
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
|
// 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)
|
// consistent across different environments (e.g. path delimiters)
|
||||||
else if (path.extname(directoryPath) !== '.map') {
|
else if (path.extname(directoryPath) !== '.map') {
|
||||||
result.push(`--- ${directoryPath} ---`, '', fs.readFileSync(directoryPath, 'utf-8'), '');
|
result.push(`--- ${directoryPath} ---`, '', readFileContents(directoryPath), '');
|
||||||
}
|
}
|
||||||
return result;
|
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) {
|
if (require.main === module) {
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
const acceptingNewGold = (args[0] === '--accept');
|
const acceptingNewGold = (args[0] === '--accept');
|
||||||
|
|
Loading…
Reference in New Issue