refactor(ivy): avoid code duplication in `ngcc` tests (#28963)
PR Close #28963
This commit is contained in:
parent
a8d84660e5
commit
c439e14d39
|
@ -92,8 +92,9 @@ describe('DecorationAnalyzer', () => {
|
||||||
let testHandler: jasmine.SpyObj<DecoratorHandler<any, any>>;
|
let testHandler: jasmine.SpyObj<DecoratorHandler<any, any>>;
|
||||||
let result: DecorationAnalyses;
|
let result: DecorationAnalyses;
|
||||||
|
|
||||||
beforeEach(() => {
|
// Helpers
|
||||||
const {options, host, ...bundle} = makeTestBundleProgram([TEST_PROGRAM]);
|
const setUpAndAnalyzeProgram = (...progArgs: Parameters<typeof makeTestBundleProgram>) => {
|
||||||
|
const {options, host, ...bundle} = makeTestBundleProgram(...progArgs);
|
||||||
program = bundle.program;
|
program = bundle.program;
|
||||||
|
|
||||||
const reflectionHost = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
const reflectionHost = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
||||||
|
@ -104,14 +105,18 @@ describe('DecorationAnalyzer', () => {
|
||||||
testHandler = createTestHandler();
|
testHandler = createTestHandler();
|
||||||
analyzer.handlers = [testHandler];
|
analyzer.handlers = [testHandler];
|
||||||
result = analyzer.analyzeProgram();
|
result = analyzer.analyzeProgram();
|
||||||
});
|
};
|
||||||
|
|
||||||
|
describe('basic usage', () => {
|
||||||
|
beforeEach(() => setUpAndAnalyzeProgram([TEST_PROGRAM]));
|
||||||
|
|
||||||
it('should return an object containing a reference to the original source file', () => {
|
it('should return an object containing a reference to the original source file', () => {
|
||||||
const file = program.getSourceFile(TEST_PROGRAM.name) !;
|
const file = program.getSourceFile(TEST_PROGRAM.name) !;
|
||||||
expect(result.get(file) !.sourceFile).toBe(file);
|
expect(result.get(file) !.sourceFile).toBe(file);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call detect on the decorator handlers with each class from the parsed file', () => {
|
it('should call detect on the decorator handlers with each class from the parsed file',
|
||||||
|
() => {
|
||||||
expect(testHandler.detect).toHaveBeenCalledTimes(2);
|
expect(testHandler.detect).toHaveBeenCalledTimes(2);
|
||||||
expect(testHandler.detect.calls.allArgs()[0][1]).toEqual([jasmine.objectContaining(
|
expect(testHandler.detect.calls.allArgs()[0][1]).toEqual([jasmine.objectContaining(
|
||||||
{name: 'Component'})]);
|
{name: 'Component'})]);
|
||||||
|
@ -133,21 +138,15 @@ describe('DecorationAnalyzer', () => {
|
||||||
expect(testHandler.compile).toHaveBeenCalledTimes(1);
|
expect(testHandler.compile).toHaveBeenCalledTimes(1);
|
||||||
expect(testHandler.compile.calls.allArgs()[0][1]).toEqual('Component');
|
expect(testHandler.compile.calls.allArgs()[0][1]).toEqual('Component');
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('internal components', () => {
|
describe('internal components', () => {
|
||||||
|
beforeEach(() => setUpAndAnalyzeProgram(INTERNAL_COMPONENT_PROGRAM));
|
||||||
|
|
||||||
// The problem of exposing the type of these internal components in the .d.ts typing files
|
// The problem of exposing the type of these internal components in the .d.ts typing files
|
||||||
// is not yet solved.
|
// is not yet solved.
|
||||||
it('should analyze an internally imported component, which is not publicly exported from the entry-point',
|
it('should analyze an internally imported component, which is not publicly exported from the entry-point',
|
||||||
() => {
|
() => {
|
||||||
const {program, options, host} = makeTestBundleProgram(INTERNAL_COMPONENT_PROGRAM);
|
|
||||||
const reflectionHost = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
|
||||||
const referencesRegistry = new NgccReferencesRegistry(reflectionHost);
|
|
||||||
const analyzer = new DecorationAnalyzer(
|
|
||||||
program, options, host, program.getTypeChecker(), reflectionHost, referencesRegistry,
|
|
||||||
[AbsoluteFsPath.fromUnchecked('/')], false);
|
|
||||||
const testHandler = createTestHandler();
|
|
||||||
analyzer.handlers = [testHandler];
|
|
||||||
const result = analyzer.analyzeProgram();
|
|
||||||
const file = program.getSourceFile('component.js') !;
|
const file = program.getSourceFile('component.js') !;
|
||||||
const analysis = result.get(file) !;
|
const analysis = result.get(file) !;
|
||||||
expect(analysis).toBeDefined();
|
expect(analysis).toBeDefined();
|
||||||
|
@ -157,15 +156,6 @@ describe('DecorationAnalyzer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should analyze an internally defined component, which is not exported at all', () => {
|
it('should analyze an internally defined component, which is not exported at all', () => {
|
||||||
const {program, options, host} = makeTestBundleProgram(INTERNAL_COMPONENT_PROGRAM);
|
|
||||||
const reflectionHost = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
|
||||||
const referencesRegistry = new NgccReferencesRegistry(reflectionHost);
|
|
||||||
const analyzer = new DecorationAnalyzer(
|
|
||||||
program, options, host, program.getTypeChecker(), reflectionHost, referencesRegistry,
|
|
||||||
[AbsoluteFsPath.fromUnchecked('/')], false);
|
|
||||||
const testHandler = createTestHandler();
|
|
||||||
analyzer.handlers = [testHandler];
|
|
||||||
const result = analyzer.analyzeProgram();
|
|
||||||
const file = program.getSourceFile('entrypoint.js') !;
|
const file = program.getSourceFile('entrypoint.js') !;
|
||||||
const analysis = result.get(file) !;
|
const analysis = result.get(file) !;
|
||||||
expect(analysis).toBeDefined();
|
expect(analysis).toBeDefined();
|
||||||
|
|
Loading…
Reference in New Issue