Skip to content

Commit

Permalink
fixup! feat(bazel): speed up dev-turnaround by bundling types only wh…
Browse files Browse the repository at this point in the history
…en packaging

Update tests.
  • Loading branch information
devversion committed Mar 21, 2022
1 parent dd4688b commit 723128a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 197 deletions.
52 changes: 15 additions & 37 deletions packages/bazel/test/ng_package/common_package.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {runfiles} from '@bazel/runfiles';
import * as fs from 'fs';
import * as path from 'path';
import * as shx from 'shelljs';

import {matchesObjectWithOrder} from './test_utils';

// Resolve the "npm_package" directory by using the runfile resolution. Note that we need to
Expand Down Expand Up @@ -82,45 +83,45 @@ describe('@angular/common ng_package', () => {
esm2020: `./esm2020/common.mjs`,
fesm2020: `./fesm2020/common.mjs`,
fesm2015: `./fesm2015/common.mjs`,
typings: `./common.d.ts`,
typings: `./index.d.ts`,
exports: matchesObjectWithOrder({
'./locales/global/*': {default: './locales/global/*.js'},
'./locales/*': {default: './locales/*.mjs'},
'./package.json': {default: './package.json'},
'.': {
types: './common.d.ts',
types: './index.d.ts',
esm2020: './esm2020/common.mjs',
es2020: './fesm2020/common.mjs',
es2015: './fesm2015/common.mjs',
node: './fesm2015/common.mjs',
default: './fesm2020/common.mjs'
},
'./http': {
types: './http/http.d.ts',
types: './http/index.d.ts',
esm2020: './esm2020/http/http.mjs',
es2020: './fesm2020/http.mjs',
es2015: './fesm2015/http.mjs',
node: './fesm2015/http.mjs',
default: './fesm2020/http.mjs'
},
'./http/testing': {
types: './http/testing/testing.d.ts',
types: './http/testing/index.d.ts',
esm2020: './esm2020/http/testing/testing.mjs',
es2020: './fesm2020/http/testing.mjs',
es2015: './fesm2015/http/testing.mjs',
node: './fesm2015/http/testing.mjs',
default: './fesm2020/http/testing.mjs'
},
'./testing': {
types: './testing/testing.d.ts',
types: './testing/index.d.ts',
esm2020: './esm2020/testing/testing.mjs',
es2020: './fesm2020/testing.mjs',
es2015: './fesm2015/testing.mjs',
node: './fesm2015/testing.mjs',
default: './fesm2020/testing.mjs'
},
'./upgrade': {
types: './upgrade/upgrade.d.ts',
types: './upgrade/index.d.ts',
esm2020: './esm2020/upgrade/upgrade.mjs',
es2020: './fesm2020/upgrade.mjs',
es2015: './fesm2015/upgrade.mjs',
Expand All @@ -130,44 +131,21 @@ describe('@angular/common ng_package', () => {
}),
}));
});
// https://github.com/angular/common-builds/blob/master/http/package.json
// https://github.com/angular/common-builds/blob/master/http
it('/http', () => {
const actual =
JSON.parse(fs.readFileSync('http/package.json', {encoding: 'utf-8'})) as PackageJson;
expect(actual['fesm2015']).toEqual('../fesm2015/http.mjs');
expect(actual['es2020']).toEqual('../fesm2020/http.mjs');
expect(actual['module']).toEqual('../fesm2015/http.mjs');
expect(actual['typings']).toEqual('./http.d.ts');
expect(actual['exports']).toBeUndefined();
expect(fs.existsSync('http/index.d.ts')).toBe(true);
});
// https://github.com/angular/common-builds/blob/master/testing/package.json
// https://github.com/angular/common-builds/blob/master/testing
it('/testing', () => {
const actual =
JSON.parse(fs.readFileSync('testing/package.json', {encoding: 'utf-8'})) as PackageJson;
expect(actual['fesm2015']).toEqual('../fesm2015/testing.mjs');
expect(actual['es2020']).toEqual('../fesm2020/testing.mjs');
expect(actual['exports']).toBeUndefined();
expect(fs.existsSync('testing/index.d.ts')).toBe(true);
});
// https://github.com/angular/common-builds/blob/master/http/testing/package.json
// https://github.com/angular/common-builds/blob/master/http/testing
it('/http/testing', () => {
const actual =
JSON.parse(fs.readFileSync('http/testing/package.json', {encoding: 'utf-8'})) as
PackageJson;
expect(actual['fesm2015']).toEqual('../../fesm2015/http/testing.mjs');
expect(actual['es2020']).toEqual('../../fesm2020/http/testing.mjs');
expect(actual['module']).toEqual('../../fesm2015/http/testing.mjs');
expect(actual['typings']).toEqual('./testing.d.ts');
expect(actual['exports']).toBeUndefined();
expect(fs.existsSync('http/testing/index.d.ts')).toBe(true);
});
// https://github.com/angular/common-builds/blob/master/upgrade/package.json
// https://github.com/angular/common-builds/blob/master/upgrade
it('/upgrade', () => {
const actual =
JSON.parse(fs.readFileSync('upgrade/package.json', {encoding: 'utf-8'})) as PackageJson;
expect(actual['fesm2015']).toEqual('../fesm2015/upgrade.mjs');
expect(actual['es2020']).toEqual('../fesm2020/upgrade.mjs');
expect(actual['module']).toEqual('../fesm2015/upgrade.mjs');
expect(actual['typings']).toEqual('./upgrade.d.ts');
expect(actual['exports']).toBeUndefined();
expect(fs.existsSync('upgrade/index.d.ts')).toBe(true);
});
});
});
36 changes: 7 additions & 29 deletions packages/bazel/test/ng_package/core_package.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {runfiles} from '@bazel/runfiles';
import * as path from 'path';
import * as shx from 'shelljs';

import {matchesObjectWithOrder} from './test_utils';

// Resolve the "npm_package" directory by using the runfile resolution. Note that we need to
Expand Down Expand Up @@ -58,20 +59,20 @@ describe('@angular/core ng_package', () => {
esm2020: `./esm2020/core.mjs`,
fesm2020: `./fesm2020/core.mjs`,
fesm2015: `./fesm2015/core.mjs`,
typings: `./core.d.ts`,
typings: `./index.d.ts`,
exports: matchesObjectWithOrder({
'./schematics/*': {default: './schematics/*.js'},
'./package.json': {default: './package.json'},
'.': {
types: './core.d.ts',
types: './index.d.ts',
esm2020: './esm2020/core.mjs',
es2020: './fesm2020/core.mjs',
es2015: './fesm2015/core.mjs',
node: './fesm2015/core.mjs',
default: './fesm2020/core.mjs'
},
'./testing': {
types: './testing/testing.d.ts',
types: './testing/index.d.ts',
esm2020: './esm2020/testing/testing.mjs',
es2020: './fesm2020/testing.mjs',
es2015: './fesm2015/testing.mjs',
Expand All @@ -95,10 +96,10 @@ describe('@angular/core ng_package', () => {

describe('typescript support', () => {
it('should not have amd module names', () => {
expect(shx.cat('core.d.ts')).not.toContain('<amd-module name');
expect(shx.cat('index.d.ts')).not.toContain('<amd-module name');
});
it('should have an index d.ts file', () => {
expect(shx.cat('core.d.ts')).toContain('export declare');
expect(shx.cat('index.d.ts')).toContain('export declare');
});

// The `r3_symbols` file was needed for View Engine ngcc processing.
Expand Down Expand Up @@ -152,31 +153,8 @@ describe('@angular/core ng_package', () => {
});

describe('secondary entry-point', () => {
describe('package.json', () => {
const packageJson = p`testing/package.json`;

it('should have a package.json file', () => {
expect(shx.grep('"name":', packageJson)).toContain(`@angular/core/testing`);
});

it('should have its module resolution mappings defined in the nested package.json', () => {
const packageJson = p`testing/package.json`;
const data = JSON.parse(shx.cat(packageJson)) as any;

expect(data).toEqual(jasmine.objectContaining({
module: `../fesm2015/testing.mjs`,
es2020: `../fesm2020/testing.mjs`,
esm2020: `../esm2020/testing/testing.mjs`,
fesm2020: `../fesm2020/testing.mjs`,
fesm2015: `../fesm2015/testing.mjs`,
typings: `./testing.d.ts`,
}));
expect(data.exports).toBeUndefined();
});
});

describe('typings', () => {
const typingsFile = p`testing/testing.d.ts`;
const typingsFile = p`testing/index.d.ts`;
it('should have a typings file', () => {
expect(shx.cat(typingsFile)).toContain('export declare');
});
Expand Down

0 comments on commit 723128a

Please sign in to comment.