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