test(upgrade): log more info to help debug CI flakes (#28045)
Related Jira issue: FW-939 PR Close #28045
This commit is contained in:
parent
9bda4460fa
commit
a64a7a4041
@ -12,7 +12,7 @@ import * as angular from '../common/angular1';
|
|||||||
// We store the ng1 injector so that the provider in the module injector can access it
|
// We store the ng1 injector so that the provider in the module injector can access it
|
||||||
// Then we "get" the ng1 injector from the module injector, which triggers the provider to read
|
// Then we "get" the ng1 injector from the module injector, which triggers the provider to read
|
||||||
// the stored injector and release the reference to it.
|
// the stored injector and release the reference to it.
|
||||||
let tempInjectorRef: angular.IInjectorService|null;
|
let tempInjectorRef: angular.IInjectorService|null = null;
|
||||||
export function setTempInjectorRef(injector: angular.IInjectorService) {
|
export function setTempInjectorRef(injector: angular.IInjectorService) {
|
||||||
tempInjectorRef = injector;
|
tempInjectorRef = injector;
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ export function injectorFactory() {
|
|||||||
throw new Error('Trying to get the AngularJS injector before it being set.');
|
throw new Error('Trying to get the AngularJS injector before it being set.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const injector: angular.IInjectorService|null = tempInjectorRef;
|
const injector: angular.IInjectorService = tempInjectorRef;
|
||||||
tempInjectorRef = null; // clear the value to prevent memory leaks
|
tempInjectorRef = null; // clear the value to prevent memory leaks
|
||||||
return injector;
|
return injector;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Ng1Token} from '@angular/upgrade/static/src/common/angular1';
|
import {IInjectorService, Ng1Token} from '@angular/upgrade/static/src/common/angular1';
|
||||||
import {compileFactory, injectorFactory, parseFactory, rootScopeFactory, setTempInjectorRef} from '@angular/upgrade/static/src/static/angular1_providers';
|
import {compileFactory, injectorFactory, parseFactory, rootScopeFactory, setTempInjectorRef} from '@angular/upgrade/static/src/static/angular1_providers';
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -22,19 +22,30 @@ import {compileFactory, injectorFactory, parseFactory, rootScopeFactory, setTemp
|
|||||||
|
|
||||||
describe('injectorFactory', () => {
|
describe('injectorFactory', () => {
|
||||||
it('should return the injector value that was previously set', () => {
|
it('should return the injector value that was previously set', () => {
|
||||||
const mockInjector = {get: () => {}, has: () => false};
|
const mockInjector = {get: () => undefined, has: () => false};
|
||||||
setTempInjectorRef(mockInjector);
|
setTempInjectorRef(mockInjector);
|
||||||
const injector = injectorFactory();
|
const injector = injectorFactory();
|
||||||
expect(injector).toBe(mockInjector);
|
expect(injector).toBe(mockInjector);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw if the injector value has not been set yet', () => {
|
it('should throw if the injector value has not been set yet', () => {
|
||||||
const mockInjector = {get: () => {}, has: () => false};
|
let injector: IInjectorService|null = null;
|
||||||
expect(injectorFactory).toThrowError();
|
|
||||||
|
try {
|
||||||
|
injector = injectorFactory();
|
||||||
|
} catch {
|
||||||
|
// Throwing an error is the expected behavior.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normally, we should never get here (but sometimes we do on CI).
|
||||||
|
// Log some info to help debug the issue.
|
||||||
|
console.error(`Unexpected injector (${typeof injector}):`, injector);
|
||||||
|
fail(`Expected no injector, but got: ${jasmine.pp(injector)}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should unset the injector after the first call (to prevent memory leaks)', () => {
|
it('should unset the injector after the first call (to prevent memory leaks)', () => {
|
||||||
const mockInjector = {get: () => {}, has: () => false};
|
const mockInjector = {get: () => undefined, has: () => false};
|
||||||
setTempInjectorRef(mockInjector);
|
setTempInjectorRef(mockInjector);
|
||||||
injectorFactory();
|
injectorFactory();
|
||||||
expect(injectorFactory).toThrowError(); // ...because it has been unset
|
expect(injectorFactory).toThrowError(); // ...because it has been unset
|
||||||
|
Loading…
x
Reference in New Issue
Block a user