angular/packages/bazel/test/ng_package/test_utils.ts
Paul Gschwendtner cd1b52483e feat(bazel): expose esm2020 and es2020 conditions in APF package exports (#43740)
In addition to the existing `exports` conditional exports we ship
as part of APF v13, we want to expose the non-bundled ESM2020 output
through the `esm2020` conditional name. Additionally we will expose
the flat ES2020 files through the `es2020` conditional field, allowing
consumers (like the CLI) to prioritize certain formats.

e.g. consider the case with RXJS where it currently defaults to
the ESM5 output. The CLI could now set `es2015` as the conditional
to leverage the ES2015 output of RXJS. This unveils a problem though
since this would also mean that `ES2015` output of the framework Angular
packages would be used instead of the available ES2020 output. Here is
the additional `es2020` conditional helpful as it allows the CLI to
prioritize `es2020`, fallback to `es2015` and lastly fallback to `default`.
if none do match for a certain package.

PR Close #43740
2021-10-06 10:55:44 -07:00

25 lines
914 B
TypeScript

/**
* @license
* Copyright Google LLC 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
*/
/**
* Jasmine asymmetric matcher that compares a given object ensuring that it matches deep
* with the other while also respecting the order of keys. This is useful when comparing
* the NodeJS `package.json` `exports` field where order matters.
*/
export function matchesObjectWithOrder(expected: any): jasmine.AsymmetricMatcher<any> {
return {
asymmetricMatch(actual: any): boolean {
// Use JSON stringify to compare the object with respect to the order of keys
// in the object, and its nested objects.
return JSON.stringify(actual) === JSON.stringify(expected);
},
jasmineToString(prettyPrint: typeof jasmine.pp): string {
return prettyPrint(expected);
}
};
}