refactor(ngcc): un-nest accidentally nested `describe()` blocks (#34437)

PR Close #34437
This commit is contained in:
George Kalpakas 2019-12-05 21:02:57 +02:00 committed by Kara Erickson
parent cd8a837956
commit 9cabd6638e
1 changed files with 656 additions and 673 deletions

View File

@ -1664,6 +1664,7 @@ runInEachFileSystem(() => {
expect(quxDef.parameters[0].name).toEqual('x'); expect(quxDef.parameters[0].name).toEqual('x');
expect(quxDef.parameters[0].initializer).toBe(null); expect(quxDef.parameters[0].initializer).toBe(null);
}); });
});
describe('getImportOfIdentifier', () => { describe('getImportOfIdentifier', () => {
it('should find the import of an identifier', () => { it('should find the import of an identifier', () => {
@ -1672,8 +1673,8 @@ runInEachFileSystem(() => {
const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost);
const variableNode = const variableNode =
getDeclaration(program, _('/file_b.js'), 'b', isNamedVariableDeclaration); getDeclaration(program, _('/file_b.js'), 'b', isNamedVariableDeclaration);
const identifier = (variableNode.initializer && const identifier =
ts.isPropertyAccessExpression(variableNode.initializer)) ? (variableNode.initializer && ts.isPropertyAccessExpression(variableNode.initializer)) ?
variableNode.initializer.name : variableNode.initializer.name :
null; null;
@ -1699,8 +1700,7 @@ runInEachFileSystem(() => {
const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost);
const variableNode = const variableNode =
getDeclaration(program, _('/index.d.ts'), 'a', isNamedVariableDeclaration); getDeclaration(program, _('/index.d.ts'), 'a', isNamedVariableDeclaration);
const identifier = const identifier = ((variableNode.type as ts.TypeReferenceNode).typeName as ts.Identifier);
((variableNode.type as ts.TypeReferenceNode).typeName as ts.Identifier);
const importOfIdent = host.getImportOfIdentifier(identifier !); const importOfIdent = host.getImportOfIdentifier(identifier !);
expect(importOfIdent).toEqual({name: 'MyClass', from: './myclass.d.ts'}); expect(importOfIdent).toEqual({name: 'MyClass', from: './myclass.d.ts'});
@ -1712,8 +1712,7 @@ runInEachFileSystem(() => {
const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost);
const variableNode = const variableNode =
getDeclaration(program, _('/file_b.js'), 'd', isNamedVariableDeclaration); getDeclaration(program, _('/file_b.js'), 'd', isNamedVariableDeclaration);
const importOfIdent = const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
expect(importOfIdent).toBeNull(); expect(importOfIdent).toBeNull();
}); });
@ -1724,8 +1723,8 @@ runInEachFileSystem(() => {
const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost);
const variableNode = const variableNode =
getDeclaration(program, _('/file_c.js'), 'c', isNamedVariableDeclaration); getDeclaration(program, _('/file_c.js'), 'c', isNamedVariableDeclaration);
const identifier = (variableNode.initializer && const identifier =
ts.isPropertyAccessExpression(variableNode.initializer)) ? (variableNode.initializer && ts.isPropertyAccessExpression(variableNode.initializer)) ?
variableNode.initializer.name : variableNode.initializer.name :
null; null;
@ -1860,8 +1859,7 @@ runInEachFileSystem(() => {
describe('getClassSymbol()', () => { describe('getClassSymbol()', () => {
it('should return the class symbol for an ES2015 class', () => { it('should return the class symbol for an ES2015 class', () => {
loadTestFiles([SIMPLE_ES2015_CLASS_FILE]); loadTestFiles([SIMPLE_ES2015_CLASS_FILE]);
const {program, host: compilerHost} = const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name);
makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name);
const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost);
const node = getDeclaration( const node = getDeclaration(
program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
@ -1907,8 +1905,7 @@ runInEachFileSystem(() => {
const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost);
const outerNode = getDeclaration( const outerNode = getDeclaration(
program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
const innerNode = const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
const innerSymbol = host.getClassSymbol(innerNode) !; const innerSymbol = host.getClassSymbol(innerNode) !;
const outerSymbol = host.getClassSymbol(outerNode) !; const outerSymbol = host.getClassSymbol(outerNode) !;
@ -1923,8 +1920,7 @@ runInEachFileSystem(() => {
const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost);
const outerNode = getDeclaration( const outerNode = getDeclaration(
program, SIMPLE_CLASS_FILE.name, 'NoParensClass', isNamedVariableDeclaration); program, SIMPLE_CLASS_FILE.name, 'NoParensClass', isNamedVariableDeclaration);
const innerNode = const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
const classSymbol = host.getClassSymbol(outerNode); const classSymbol = host.getClassSymbol(outerNode);
expect(classSymbol).toBeDefined(); expect(classSymbol).toBeDefined();
@ -1939,8 +1935,7 @@ runInEachFileSystem(() => {
const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost);
const outerNode = getDeclaration( const outerNode = getDeclaration(
program, SIMPLE_CLASS_FILE.name, 'InnerParensClass', isNamedVariableDeclaration); program, SIMPLE_CLASS_FILE.name, 'InnerParensClass', isNamedVariableDeclaration);
const innerNode = const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
const classSymbol = host.getClassSymbol(outerNode); const classSymbol = host.getClassSymbol(outerNode);
expect(classSymbol).toBeDefined(); expect(classSymbol).toBeDefined();
@ -1959,8 +1954,7 @@ runInEachFileSystem(() => {
expect(classSymbol).toBeUndefined(); expect(classSymbol).toBeUndefined();
}); });
it('should return undefined if variable declaration is not initialized using an IIFE', it('should return undefined if variable declaration is not initialized using an IIFE', () => {
() => {
const testFile = { const testFile = {
name: _('/test.js'), name: _('/test.js'),
contents: `var MyClass = null;`, contents: `var MyClass = null;`,
@ -1968,8 +1962,7 @@ runInEachFileSystem(() => {
loadTestFiles([testFile]); loadTestFiles([testFile]);
const {program, host: compilerHost} = makeTestBundleProgram(testFile.name); const {program, host: compilerHost} = makeTestBundleProgram(testFile.name);
const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost);
const node = const node = getDeclaration(program, testFile.name, 'MyClass', isNamedVariableDeclaration);
getDeclaration(program, testFile.name, 'MyClass', isNamedVariableDeclaration);
const classSymbol = host.getClassSymbol(node); const classSymbol = host.getClassSymbol(node);
expect(classSymbol).toBeUndefined(); expect(classSymbol).toBeUndefined();
@ -1979,33 +1972,29 @@ runInEachFileSystem(() => {
describe('isClass()', () => { describe('isClass()', () => {
it('should return true if a given node is a TS class declaration', () => { it('should return true if a given node is a TS class declaration', () => {
loadTestFiles([SIMPLE_ES2015_CLASS_FILE]); loadTestFiles([SIMPLE_ES2015_CLASS_FILE]);
const {program, host: compilerHost} = const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name);
makeTestBundleProgram(SIMPLE_ES2015_CLASS_FILE.name);
const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost);
const node = getDeclaration( const node = getDeclaration(
program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
expect(host.isClass(node)).toBe(true); expect(host.isClass(node)).toBe(true);
}); });
it('should return true if a given node is the outer variable declaration of a class', it('should return true if a given node is the outer variable declaration of a class', () => {
() => {
loadTestFiles([SIMPLE_CLASS_FILE]); loadTestFiles([SIMPLE_CLASS_FILE]);
const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost);
const node = getDeclaration( const node =
program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration);
expect(host.isClass(node)).toBe(true); expect(host.isClass(node)).toBe(true);
}); });
it('should return true if a given node is the inner variable declaration of a class', it('should return true if a given node is the inner variable declaration of a class', () => {
() => {
loadTestFiles([SIMPLE_CLASS_FILE]); loadTestFiles([SIMPLE_CLASS_FILE]);
const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name); const {program, host: compilerHost} = makeTestBundleProgram(SIMPLE_CLASS_FILE.name);
const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost); const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost);
const outerNode = getDeclaration( const outerNode =
program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration); getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', ts.isVariableDeclaration);
const innerNode = const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
expect(host.isClass(innerNode)).toBe(true); expect(host.isClass(innerNode)).toBe(true);
}); });
@ -2182,8 +2171,7 @@ runInEachFileSystem(() => {
const secondaryFile = getSourceFileOrError(program, DECORATED_FILES[1].name); const secondaryFile = getSourceFileOrError(program, DECORATED_FILES[1].name);
const classSymbolsPrimary = host.findClassSymbols(primaryFile); const classSymbolsPrimary = host.findClassSymbols(primaryFile);
const classDecoratorsPrimary = const classDecoratorsPrimary = classSymbolsPrimary.map(s => host.getDecoratorsOfSymbol(s));
classSymbolsPrimary.map(s => host.getDecoratorsOfSymbol(s));
expect(classDecoratorsPrimary.length).toEqual(2); expect(classDecoratorsPrimary.length).toEqual(2);
expect(classDecoratorsPrimary[0] !.map(d => d.name)).toEqual(['Directive']); expect(classDecoratorsPrimary[0] !.map(d => d.name)).toEqual(['Directive']);
expect(classDecoratorsPrimary[1] !.map(d => d.name)).toEqual(['Directive']); expect(classDecoratorsPrimary[1] !.map(d => d.name)).toEqual(['Directive']);
@ -2205,8 +2193,7 @@ runInEachFileSystem(() => {
const dts = makeTestBundleProgram(_('/typings/index.d.ts')); const dts = makeTestBundleProgram(_('/typings/index.d.ts'));
const class1 = const class1 =
getDeclaration(program, _('/src/class1.js'), 'Class1', ts.isVariableDeclaration); getDeclaration(program, _('/src/class1.js'), 'Class1', ts.isVariableDeclaration);
const host = const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts);
new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts);
const dtsDeclaration = host.getDtsDeclaration(class1); const dtsDeclaration = host.getDtsDeclaration(class1);
expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/class1.d.ts')); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/class1.d.ts'));
@ -2230,8 +2217,8 @@ runInEachFileSystem(() => {
loadTestFiles(TYPINGS_DTS_FILES); loadTestFiles(TYPINGS_DTS_FILES);
const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js'));
const dts = makeTestBundleProgram(_('/typings/index.d.ts')); const dts = makeTestBundleProgram(_('/typings/index.d.ts'));
const missingClass = getDeclaration( const missingClass =
program, _('/src/class1.js'), 'MissingClass1', ts.isVariableDeclaration); getDeclaration(program, _('/src/class1.js'), 'MissingClass1', ts.isVariableDeclaration);
const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts); const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts);
expect(host.getDtsDeclaration(missingClass)).toBe(null); expect(host.getDtsDeclaration(missingClass)).toBe(null);
@ -2255,10 +2242,9 @@ runInEachFileSystem(() => {
loadTestFiles(TYPINGS_DTS_FILES); loadTestFiles(TYPINGS_DTS_FILES);
const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js')); const {program, host: compilerHost} = makeTestBundleProgram(_('/src/index.js'));
const dts = makeTestBundleProgram(_('/typings/index.d.ts')); const dts = makeTestBundleProgram(_('/typings/index.d.ts'));
const class1 = getDeclaration( const class1 =
program, _('/src/flat-file.js'), 'Class1', ts.isVariableDeclaration); getDeclaration(program, _('/src/flat-file.js'), 'Class1', ts.isVariableDeclaration);
const host = const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts);
new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts);
const dtsDeclaration = host.getDtsDeclaration(class1); const dtsDeclaration = host.getDtsDeclaration(class1);
expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/class1.d.ts')); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/class1.d.ts'));
@ -2285,8 +2271,7 @@ runInEachFileSystem(() => {
const dts = makeTestBundleProgram(_('/typings/index.d.ts')); const dts = makeTestBundleProgram(_('/typings/index.d.ts'));
const internalClass = getDeclaration( const internalClass = getDeclaration(
program, _('/src/internal.js'), 'InternalClass', ts.isVariableDeclaration); program, _('/src/internal.js'), 'InternalClass', ts.isVariableDeclaration);
const host = const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts);
new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts);
const dtsDeclaration = host.getDtsDeclaration(internalClass); const dtsDeclaration = host.getDtsDeclaration(internalClass);
expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/internal.d.ts')); expect(dtsDeclaration !.getSourceFile().fileName).toEqual(_('/typings/internal.d.ts'));
@ -2302,8 +2287,7 @@ runInEachFileSystem(() => {
getDeclaration(program, _('/src/class2.js'), 'Class2', ts.isVariableDeclaration); getDeclaration(program, _('/src/class2.js'), 'Class2', ts.isVariableDeclaration);
const internalClass2 = const internalClass2 =
getDeclaration(program, _('/src/internal.js'), 'Class2', ts.isVariableDeclaration); getDeclaration(program, _('/src/internal.js'), 'Class2', ts.isVariableDeclaration);
const host = const host = new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts);
new UmdReflectionHost(new MockLogger(), false, program, compilerHost, dts);
const class2DtsDeclaration = host.getDtsDeclaration(class2); const class2DtsDeclaration = host.getDtsDeclaration(class2);
expect(class2DtsDeclaration !.getSourceFile().fileName) expect(class2DtsDeclaration !.getSourceFile().fileName)
@ -2423,5 +2407,4 @@ runInEachFileSystem(() => {
}); });
}); });
}); });
});
}); });