diff --git a/package.json b/package.json index f760ae0..601d287 100644 --- a/package.json +++ b/package.json @@ -32,17 +32,20 @@ "homepage": "https://github.com/TypeScript-Heroes/node-typescript-parser#readme", "devDependencies": { "@types/jest": "^20.0.1", + "@types/mock-fs": "^3.6.30", "@types/node": "^8.0.1", "del-cli": "^1.0.0", "jest": "^20.0.4", + "mock-fs": "^4.4.1", + "semantic-release": "^6.3.6", "ts-jest": "^20.0.6", "tslint": "^5.4.3", "tslint-config-airbnb": "^5.2.0", "tsutils": "^2.4.0", - "typedoc": "^0.7.1", - "semantic-release": "^6.3.6" + "typedoc": "^0.7.1" }, "dependencies": { + "lodash": "^4.17.4", "tslib": "^1.7.1", "typescript": "^2.4.1" } diff --git a/src/DeclarationIndex.ts b/src/DeclarationIndex.ts index 4abe3c3..05ab262 100644 --- a/src/DeclarationIndex.ts +++ b/src/DeclarationIndex.ts @@ -1,3 +1,4 @@ +import { difference, differenceWith, intersection, isEqual } from 'lodash'; import { join, normalize, relative, resolve } from 'path'; import { DeclarationInfo } from './declarations/DeclarationInfo'; @@ -34,10 +35,16 @@ function getNodeLibraryName(path: string): string { */ type Resources = { [name: string]: Resource }; -// export type DeltaIndex = { -// deleted: string[]; -// updated: { [declaration: string]: DeclarationInfo[] }; -// }; +/** + * IndexDelta type, is calculated by the declaration index to give an overview, what has changed in the index. + * Returns a list of deleted declarations, newly added declarations (with the corresponding infos) and + * which declarations have been updated (with all declarations under that name). + */ +export type IndexDelta = { + added: { [declaration: string]: DeclarationInfo[] }; + updated: { [declaration: string]: DeclarationInfo[] }; + deleted: string[]; +}; /** * Interface for file changes. Contains lists of file uri's to the specific action. @@ -119,6 +126,48 @@ export class DeclarationIndex { constructor(private parser: TypescriptParser, private rootPath: string) { } + /** + * Calculates the differences between two indices. Calculates removed, added and updated declarations. + * The updated declarations are calculated and all declarations that the new index contains are inserted in the list. + * + * @static + * @param {{ [declaration: string]: DeclarationInfo[] }} oldIndex + * @param {{ [declaration: string]: DeclarationInfo[] }} newIndex + * @returns {IndexDelta} + * @memberof DeclarationIndex + */ + public static calculateIndexDelta( + oldIndex: { [declaration: string]: DeclarationInfo[] }, + newIndex: { [declaration: string]: DeclarationInfo[] }, + ): IndexDelta { + const oldKeys = Object.keys(oldIndex); + const newKeys = Object.keys(newIndex); + + return { + added: difference(newKeys, oldKeys).reduce( + (obj, currentKey) => { + obj[currentKey] = newIndex[currentKey]; + return obj; + }, + {} as { [declaration: string]: DeclarationInfo[] }, + ), + updated: intersection(oldKeys, newKeys).reduce( + (obj, currentKey) => { + const old = oldIndex[currentKey]; + const neu = newIndex[currentKey]; + + if (differenceWith(neu, old, isEqual).length > 0 || differenceWith(old, neu, isEqual).length > 0) { + obj[currentKey] = neu; + } + + return obj; + }, + {} as { [declaration: string]: DeclarationInfo[] }, + ), + deleted: difference(oldKeys, newKeys), + }; + } + /** * Resets the whole index. Does delete everything. Period. * Is useful for unit testing or similar things. @@ -159,13 +208,14 @@ export class DeclarationIndex { /** * Is called when file events happen. Does reindex for the changed files and creates a new index. + * Returns the differences for the new index. * * @param {FileEvent[]} changes - * @returns {Promise} + * @returns {Promise} * * @memberof DeclarationIndex */ - public async reindexForChanges(changes: FileChanges): Promise { + public async reindexForChanges(changes: FileChanges): Promise { const rebuildResources: string[] = []; const removeResources: string[] = []; const rebuildFiles: string[] = []; @@ -212,11 +262,10 @@ export class DeclarationIndex { for (const key of Object.keys(resources)) { this.parsedResources[key] = resources[key]; } + const old = this._index || {}; this._index = await this.createIndex(this.parsedResources); - // return { - // deleted: removeResources, - // updated: await this.createIndex(resources), - // }; + + return DeclarationIndex.calculateIndexDelta(old, this._index); } /** diff --git a/test/TypescriptParser.spec.ts b/test/TypescriptParser.spec.ts index 6e2ac16..eef4aba 100644 --- a/test/TypescriptParser.spec.ts +++ b/test/TypescriptParser.spec.ts @@ -28,6 +28,16 @@ describe('TypescriptParser', () => { parser = new TypescriptParser(); }); + describe('Source parsing', () => { + + it('should parse a source code string correctly', async () => { + const parsed = await parser.parseSource(`import {foo} from 'bar'; class Foobar {}; const bar = new Foobar();`); + + expect(parsed).toMatchSnapshot(); + }); + + }); + describe('Import parsing', () => { const file = getWorkspaceFile('typescript-parser/importsOnly.ts'); diff --git a/test/__snapshots__/TypescriptParser.spec.ts.snap b/test/__snapshots__/TypescriptParser.spec.ts.snap index d5ba637..7caf067 100644 --- a/test/__snapshots__/TypescriptParser.spec.ts.snap +++ b/test/__snapshots__/TypescriptParser.spec.ts.snap @@ -890,3 +890,49 @@ StringImport { "start": 0, } `; + +exports[`TypescriptParser Source parsing should parse a source code string correctly 1`] = ` +File { + "declarations": Array [ + ClassDeclaration { + "end": 40, + "isExported": false, + "methods": Array [], + "name": "Foobar", + "properties": Array [], + "start": 25, + }, + VariableDeclaration { + "end": 67, + "isConst": true, + "isExported": false, + "name": "bar", + "start": 42, + "type": undefined, + }, + ], + "end": 67, + "exports": Array [], + "filePath": "inline.ts", + "imports": Array [ + NamedImport { + "end": 24, + "libraryName": "bar", + "specifiers": Array [ + SymbolSpecifier { + "alias": undefined, + "specifier": "foo", + }, + ], + "start": 0, + }, + ], + "resources": Array [], + "rootPath": "/", + "start": 0, + "usages": Array [ + "bar", + "Foobar", + ], +} +`; diff --git a/test/code-generators/TypescriptCodeGenerator.spec.ts b/test/code-generators/TypescriptCodeGenerator.spec.ts index 1031818..1cf78cb 100644 --- a/test/code-generators/TypescriptCodeGenerator.spec.ts +++ b/test/code-generators/TypescriptCodeGenerator.spec.ts @@ -1,10 +1,12 @@ import { TypescriptCodeGenerator } from '../../src/code-generators/TypescriptCodeGenerator'; import { TypescriptGenerationOptions } from '../../src/code-generators/TypescriptGenerationOptions'; +import { ClassDeclaration } from '../../src/declarations'; import { DeclarationVisibility } from '../../src/declarations/DeclarationVisibility'; import { MethodDeclaration } from '../../src/declarations/MethodDeclaration'; import { ParameterDeclaration } from '../../src/declarations/ParameterDeclaration'; import { PropertyDeclaration } from '../../src/declarations/PropertyDeclaration'; import { VariableDeclaration } from '../../src/declarations/VariableDeclaration'; +import { NotGeneratableYetError } from '../../src/errors/NotGeneratableYetError'; import { DefaultImport } from '../../src/imports/DefaultImport'; import { ExternalModuleImport } from '../../src/imports/ExternalModuleImport'; import { NamedImport } from '../../src/imports/NamedImport'; @@ -81,4 +83,10 @@ describe('TypescriptCodeGenerator', () => { }); } + + it('should throw on non generatable element', () => { + const generator = new TypescriptCodeGenerator(defaultOptions); + + expect(() => generator.generate(new ClassDeclaration('foo', true))).toThrow(NotGeneratableYetError); + }); }); diff --git a/test/declaration-index/DeclarationIndex.spec.ts b/test/declaration-index/DeclarationIndex.spec.ts index 7774b21..069665e 100644 --- a/test/declaration-index/DeclarationIndex.spec.ts +++ b/test/declaration-index/DeclarationIndex.spec.ts @@ -1,6 +1,8 @@ +import mockFs = require('mock-fs'); import { join, resolve } from 'path'; import { DeclarationIndex } from '../../src/DeclarationIndex'; +import { ClassDeclaration } from '../../src/declarations'; import { TypescriptParser } from '../../src/TypescriptParser'; describe('DeclarationIndex', () => { @@ -75,15 +77,325 @@ describe('DeclarationIndex', () => { const idx: any = declarationIndex; const resources = Object.assign(Object.create(null), idx.parsedResources); const resource = resources['/myReactTemplate']; - + delete resource.filePath; delete resource.rootPath; - + expect(resource).toMatchSnapshot(); }); }); + describe('reindexForChanges()', () => { + + afterEach(() => { + mockFs.restore(); + }); + + it('should correctly add a new created file', async () => { + await declarationIndex.buildIndex( + [ + join(rootPath, 'classes.ts'), + ], + ); + + expect(declarationIndex.index).toMatchSnapshot(); + + await declarationIndex.reindexForChanges({ + created: [join(rootPath, 'helper-functions.ts')], + updated: [], + deleted: [], + }); + + expect(declarationIndex.index).toMatchSnapshot(); + }); + + it('should correctly update a modified file', async () => { + + await declarationIndex.buildIndex( + [ + join(rootPath, 'classes.ts'), + ], + ); + + expect(declarationIndex.index).toMatchSnapshot(); + + mockFs({ + [join(rootPath, 'classes.ts')]: `export class MyClass { + public doSomething(): void { } + } + + export class FancierLibraryClass { + public doSomethingAwesome(): void { } + }`, + }); + + await declarationIndex.reindexForChanges({ + created: [], + updated: [join(rootPath, 'classes.ts')], + deleted: [], + }); + + expect(declarationIndex.index).toMatchSnapshot(); + }); + + it('should correctly remove a deleted file', async () => { + await declarationIndex.buildIndex( + [ + join(rootPath, 'classes.ts'), + ], + ); + + expect(declarationIndex.index).toMatchSnapshot(); + + await declarationIndex.reindexForChanges({ + created: [], + updated: [], + deleted: [join(rootPath, 'classes.ts')], + }); + + expect(declarationIndex.index).toMatchSnapshot(); + }); + + it('should correctly add a file that is exported', async () => { + mockFs({ + [join(rootPath, 'classes.ts')]: `export class MyClass { + public doSomething(): void { } + } + + export class FancierLibraryClass { + public doSomethingAwesome(): void { } + }`, + }); + + await declarationIndex.buildIndex( + [ + join(rootPath, 'classes.ts'), + ], + ); + + mockFs({ + [join(rootPath, 'foobar.ts')]: `export class Foobar{}`, + [join(rootPath, 'classes.ts')]: `export class MyClass { + public doSomething(): void { } + } + + export class FancierLibraryClass { + public doSomethingAwesome(): void { } + } + + export * from './foobar'`, + }); + + expect(declarationIndex.index).toMatchSnapshot(); + + await declarationIndex.reindexForChanges({ + created: [join(rootPath, 'foobar.ts')], + updated: [join(rootPath, 'classes.ts')], + deleted: [], + }); + + expect(declarationIndex.index).toMatchSnapshot(); + }); + + it('should correctly add an empty file', async () => { + mockFs({ + [join(rootPath, 'classes.ts')]: `export class MyClass { + public doSomething(): void { } + } + + export class FancierLibraryClass { + public doSomethingAwesome(): void { } + }`, + }); + + await declarationIndex.buildIndex( + [ + join(rootPath, 'classes.ts'), + ], + ); + + mockFs({ + [join(rootPath, 'foobar.ts')]: ``, + [join(rootPath, 'classes.ts')]: `export class MyClass { + public doSomething(): void { } + } + + export class FancierLibraryClass { + public doSomethingAwesome(): void { } + }`, + }); + + expect(declarationIndex.index).toMatchSnapshot(); + + await declarationIndex.reindexForChanges({ + created: [join(rootPath, 'foobar.ts')], + updated: [join(rootPath, 'classes.ts')], + deleted: [], + }); + + expect(declarationIndex.index).toMatchSnapshot(); + }); + + it('should correctly update a file that is exported', async () => { + mockFs({ + [join(rootPath, 'foobar.ts')]: `export class Foobar{}`, + [join(rootPath, 'classes.ts')]: `export class MyClass { + public doSomething(): void { } + } + + export class FancierLibraryClass { + public doSomethingAwesome(): void { } + }`, + }); + + await declarationIndex.buildIndex( + [ + join(rootPath, 'classes.ts'), + join(rootPath, 'foobar.ts'), + ], + ); + + mockFs({ + [join(rootPath, 'foobar.ts')]: `export class Foobar{} export class Barbaz{}`, + [join(rootPath, 'classes.ts')]: `export class MyClass { + public doSomething(): void { } + } + + export class FancierLibraryClass { + public doSomethingAwesome(): void { } + } + + export * from './foobar'`, + }); + + expect(declarationIndex.index).toMatchSnapshot(); + + await declarationIndex.reindexForChanges({ + created: [], + updated: [join(rootPath, 'classes.ts'), join(rootPath, 'foobar.ts')], + deleted: [], + }); + + expect(declarationIndex.index).toMatchSnapshot(); + }); + + it('should correctly remove an exported file', async () => { + mockFs({ + [join(rootPath, 'foobar.ts')]: `export class Foobar{}`, + [join(rootPath, 'classes.ts')]: `export class MyClass { + public doSomething(): void { } + } + + export class FancierLibraryClass { + public doSomethingAwesome(): void { } + } + + export * from './foobar'`, + }); + + await declarationIndex.buildIndex( + [ + join(rootPath, 'classes.ts'), + join(rootPath, 'foobar.ts'), + ], + ); + + expect(declarationIndex.index).toMatchSnapshot(); + + await declarationIndex.reindexForChanges({ + created: [], + updated: [join(rootPath, 'classes.ts')], + deleted: [join(rootPath, 'foobar.ts')], + }); + + expect(declarationIndex.index).toMatchSnapshot(); + }); + + }); + + describe('calculateIndexDelta()', () => { + + it('should calculate a newly added declaration', () => { + const oldIndex = {}; + const newIndex = { + Foobar: [{ declaration: new ClassDeclaration('Foobar', true, 0, 100), from: './foobar' }], + }; + + expect(DeclarationIndex.calculateIndexDelta(oldIndex, newIndex)).toMatchSnapshot(); + }); + + it('should calculate a removed declaration', () => { + const oldIndex = { + Foobar: [{ declaration: new ClassDeclaration('Foobar', true, 0, 100), from: './foobar' }], + }; + const newIndex = {}; + + expect(DeclarationIndex.calculateIndexDelta(oldIndex, newIndex)).toMatchSnapshot(); + }); + + it('should calculate correctly when nothing happend', () => { + const oldIndex = { + Foobar: [{ declaration: new ClassDeclaration('Foobar', true, 0, 100), from: './foobar' }], + }; + const newIndex = { + Foobar: [{ declaration: new ClassDeclaration('Foobar', true, 0, 100), from: './foobar' }], + }; + + expect(DeclarationIndex.calculateIndexDelta(oldIndex, newIndex)).toMatchSnapshot(); + }); + + it('should calculate an updated key (removed 1 declaration)', () => { + const oldIndex = { + Foobar: [ + { declaration: new ClassDeclaration('Foobar', true, 0, 100), from: './foobar' }, + { declaration: new ClassDeclaration('Foobar', true, 10, 100), from: './foobar2' }, + ], + }; + const newIndex = { + Foobar: [ + { declaration: new ClassDeclaration('Foobar', true, 0, 100), from: './foobar' }, + ], + }; + + expect(DeclarationIndex.calculateIndexDelta(oldIndex, newIndex)).toMatchSnapshot(); + }); + + it('should calculate an updated key (added 1 declaration)', () => { + const oldIndex = { + Foobar: [ + { declaration: new ClassDeclaration('Foobar', true, 0, 100), from: './foobar' }, + ], + }; + const newIndex = { + Foobar: [ + { declaration: new ClassDeclaration('Foobar', true, 0, 100), from: './foobar' }, + { declaration: new ClassDeclaration('Foobar', true, 10, 100), from: './foobar2' }, + ], + }; + + expect(DeclarationIndex.calculateIndexDelta(oldIndex, newIndex)).toMatchSnapshot(); + }); + + it('should calculate an updated key (changed 1 declaration', () => { + const oldIndex = { + Foobar: [ + { declaration: new ClassDeclaration('Foobar', true, 0, 100), from: './foobar' }, + { declaration: new ClassDeclaration('Foobar', true, 10, 100), from: './foobar2' }, + ], + }; + const newIndex = { + Foobar: [ + { declaration: new ClassDeclaration('Foobar', true, 0, 100), from: './foobar' }, + { declaration: new ClassDeclaration('Foobar', true, 15, 100), from: './foobar2' }, + ], + }; + + expect(DeclarationIndex.calculateIndexDelta(oldIndex, newIndex)).toMatchSnapshot(); + }); + + }); + describe('exports', () => { const folderRoot = join(rootPath, 'exports'); @@ -130,7 +442,7 @@ describe('DeclarationIndex', () => { expect(declarationIndex.index).toMatchSnapshot(); }); - + it('should export elements that are already exported correclty', async () => { await declarationIndex.buildIndex( [ diff --git a/test/declaration-index/__snapshots__/DeclarationIndex.spec.ts.snap b/test/declaration-index/__snapshots__/DeclarationIndex.spec.ts.snap index 8287a0b..a2c99fe 100644 --- a/test/declaration-index/__snapshots__/DeclarationIndex.spec.ts.snap +++ b/test/declaration-index/__snapshots__/DeclarationIndex.spec.ts.snap @@ -127,6 +127,134 @@ Array [ ] `; +exports[`DeclarationIndex calculateIndexDelta() should calculate a newly added declaration 1`] = ` +Object { + "added": Object { + "Foobar": Array [ + Object { + "declaration": ClassDeclaration { + "end": 100, + "isExported": true, + "methods": Array [], + "name": "Foobar", + "properties": Array [], + "start": 0, + }, + "from": "./foobar", + }, + ], + }, + "deleted": Array [], + "updated": Object {}, +} +`; + +exports[`DeclarationIndex calculateIndexDelta() should calculate a removed declaration 1`] = ` +Object { + "added": Object {}, + "deleted": Array [ + "Foobar", + ], + "updated": Object {}, +} +`; + +exports[`DeclarationIndex calculateIndexDelta() should calculate an updated key (added 1 declaration) 1`] = ` +Object { + "added": Object {}, + "deleted": Array [], + "updated": Object { + "Foobar": Array [ + Object { + "declaration": ClassDeclaration { + "end": 100, + "isExported": true, + "methods": Array [], + "name": "Foobar", + "properties": Array [], + "start": 0, + }, + "from": "./foobar", + }, + Object { + "declaration": ClassDeclaration { + "end": 100, + "isExported": true, + "methods": Array [], + "name": "Foobar", + "properties": Array [], + "start": 10, + }, + "from": "./foobar2", + }, + ], + }, +} +`; + +exports[`DeclarationIndex calculateIndexDelta() should calculate an updated key (changed 1 declaration 1`] = ` +Object { + "added": Object {}, + "deleted": Array [], + "updated": Object { + "Foobar": Array [ + Object { + "declaration": ClassDeclaration { + "end": 100, + "isExported": true, + "methods": Array [], + "name": "Foobar", + "properties": Array [], + "start": 0, + }, + "from": "./foobar", + }, + Object { + "declaration": ClassDeclaration { + "end": 100, + "isExported": true, + "methods": Array [], + "name": "Foobar", + "properties": Array [], + "start": 15, + }, + "from": "./foobar2", + }, + ], + }, +} +`; + +exports[`DeclarationIndex calculateIndexDelta() should calculate an updated key (removed 1 declaration) 1`] = ` +Object { + "added": Object {}, + "deleted": Array [], + "updated": Object { + "Foobar": Array [ + Object { + "declaration": ClassDeclaration { + "end": 100, + "isExported": true, + "methods": Array [], + "name": "Foobar", + "properties": Array [], + "start": 0, + }, + "from": "./foobar", + }, + ], + }, +} +`; + +exports[`DeclarationIndex calculateIndexDelta() should calculate correctly when nothing happend 1`] = ` +Object { + "added": Object {}, + "deleted": Array [], + "updated": Object {}, +} +`; + exports[`DeclarationIndex exports should export all elements correctly (export * from) 1`] = ` Object { "Class1": Array [ @@ -736,3 +864,1269 @@ Object { ], } `; + +exports[`DeclarationIndex reindexForChanges() should correctly add a file that is exported 1`] = ` +Object { + "FancierLibraryClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 379, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 329, + "isAbstract": false, + "name": "doSomethingAwesome", + "parameters": Array [], + "start": 292, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "FancierLibraryClass", + "properties": Array [], + "start": 205, + }, + "from": "/classes", + }, + ], + "MyClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 155, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 105, + "isAbstract": false, + "name": "doSomething", + "parameters": Array [], + "start": 75, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "MyClass", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], +} +`; + +exports[`DeclarationIndex reindexForChanges() should correctly add a file that is exported 2`] = ` +Object { + "FancierLibraryClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 379, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 329, + "isAbstract": false, + "name": "doSomethingAwesome", + "parameters": Array [], + "start": 292, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "FancierLibraryClass", + "properties": Array [], + "start": 205, + }, + "from": "/classes", + }, + ], + "Foobar": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 21, + "isExported": true, + "methods": Array [], + "name": "Foobar", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], + "MyClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 155, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 105, + "isAbstract": false, + "name": "doSomething", + "parameters": Array [], + "start": 75, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "MyClass", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], +} +`; + +exports[`DeclarationIndex reindexForChanges() should correctly add a new created file 1`] = ` +Object { + "Class1": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 164, + "isExported": true, + "methods": Array [], + "name": "Class1", + "properties": Array [], + "start": 141, + }, + "from": "/classes", + }, + ], + "Class2": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 188, + "isExported": true, + "methods": Array [], + "name": "Class2", + "properties": Array [], + "start": 165, + }, + "from": "/classes", + }, + ], + "Class3": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 212, + "isExported": true, + "methods": Array [], + "name": "Class3", + "properties": Array [], + "start": 189, + }, + "from": "/classes", + }, + ], + "Class4": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 236, + "isExported": true, + "methods": Array [], + "name": "Class4", + "properties": Array [], + "start": 213, + }, + "from": "/classes", + }, + ], + "Class5": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 260, + "isExported": true, + "methods": Array [], + "name": "Class5", + "properties": Array [], + "start": 237, + }, + "from": "/classes", + }, + ], + "Class6": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 284, + "isExported": true, + "methods": Array [], + "name": "Class6", + "properties": Array [], + "start": 261, + }, + "from": "/classes", + }, + ], + "Class7": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 308, + "isExported": true, + "methods": Array [], + "name": "Class7", + "properties": Array [], + "start": 285, + }, + "from": "/classes", + }, + ], + "Class8": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 332, + "isExported": true, + "methods": Array [], + "name": "Class8", + "properties": Array [], + "start": 309, + }, + "from": "/classes", + }, + ], + "Class9": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 356, + "isExported": true, + "methods": Array [], + "name": "Class9", + "properties": Array [], + "start": 333, + }, + "from": "/classes", + }, + ], + "FancierLibraryClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 139, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 137, + "isAbstract": false, + "name": "doSomethingAwesome", + "parameters": Array [], + "start": 100, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "FancierLibraryClass", + "properties": Array [], + "start": 61, + }, + "from": "/classes", + }, + ], + "MyClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 59, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 57, + "isAbstract": false, + "name": "doSomething", + "parameters": Array [], + "start": 27, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "MyClass", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], +} +`; + +exports[`DeclarationIndex reindexForChanges() should correctly add a new created file 2`] = ` +Object { + "Class1": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 164, + "isExported": true, + "methods": Array [], + "name": "Class1", + "properties": Array [], + "start": 141, + }, + "from": "/classes", + }, + ], + "Class2": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 188, + "isExported": true, + "methods": Array [], + "name": "Class2", + "properties": Array [], + "start": 165, + }, + "from": "/classes", + }, + ], + "Class3": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 212, + "isExported": true, + "methods": Array [], + "name": "Class3", + "properties": Array [], + "start": 189, + }, + "from": "/classes", + }, + ], + "Class4": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 236, + "isExported": true, + "methods": Array [], + "name": "Class4", + "properties": Array [], + "start": 213, + }, + "from": "/classes", + }, + ], + "Class5": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 260, + "isExported": true, + "methods": Array [], + "name": "Class5", + "properties": Array [], + "start": 237, + }, + "from": "/classes", + }, + ], + "Class6": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 284, + "isExported": true, + "methods": Array [], + "name": "Class6", + "properties": Array [], + "start": 261, + }, + "from": "/classes", + }, + ], + "Class7": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 308, + "isExported": true, + "methods": Array [], + "name": "Class7", + "properties": Array [], + "start": 285, + }, + "from": "/classes", + }, + ], + "Class8": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 332, + "isExported": true, + "methods": Array [], + "name": "Class8", + "properties": Array [], + "start": 309, + }, + "from": "/classes", + }, + ], + "Class9": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 356, + "isExported": true, + "methods": Array [], + "name": "Class9", + "properties": Array [], + "start": 333, + }, + "from": "/classes", + }, + ], + "FancierLibraryClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 139, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 137, + "isAbstract": false, + "name": "doSomethingAwesome", + "parameters": Array [], + "start": 100, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "FancierLibraryClass", + "properties": Array [], + "start": 61, + }, + "from": "/classes", + }, + ], + "MyClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 59, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 57, + "isAbstract": false, + "name": "doSomething", + "parameters": Array [], + "start": 27, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "MyClass", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], + "isNumber": Array [ + DeclarationInfo { + "declaration": FunctionDeclaration { + "end": 186, + "isExported": true, + "name": "isNumber", + "parameters": Array [ + ParameterDeclaration { + "end": 127, + "name": "str", + "start": 119, + "type": "any", + }, + ], + "start": 94, + "type": "str is number", + "variables": Array [], + }, + "from": "/helper-functions", + }, + ], + "isString": Array [ + DeclarationInfo { + "declaration": FunctionDeclaration { + "end": 92, + "isExported": true, + "name": "isString", + "parameters": Array [ + ParameterDeclaration { + "end": 33, + "name": "str", + "start": 25, + "type": "any", + }, + ], + "start": 0, + "type": "str is string", + "variables": Array [], + }, + "from": "/helper-functions", + }, + ], +} +`; + +exports[`DeclarationIndex reindexForChanges() should correctly add an empty file 1`] = ` +Object { + "FancierLibraryClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 379, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 329, + "isAbstract": false, + "name": "doSomethingAwesome", + "parameters": Array [], + "start": 292, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "FancierLibraryClass", + "properties": Array [], + "start": 205, + }, + "from": "/classes", + }, + ], + "MyClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 155, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 105, + "isAbstract": false, + "name": "doSomething", + "parameters": Array [], + "start": 75, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "MyClass", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], +} +`; + +exports[`DeclarationIndex reindexForChanges() should correctly add an empty file 2`] = ` +Object { + "FancierLibraryClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 379, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 329, + "isAbstract": false, + "name": "doSomethingAwesome", + "parameters": Array [], + "start": 292, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "FancierLibraryClass", + "properties": Array [], + "start": 205, + }, + "from": "/classes", + }, + ], + "MyClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 155, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 105, + "isAbstract": false, + "name": "doSomething", + "parameters": Array [], + "start": 75, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "MyClass", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], +} +`; + +exports[`DeclarationIndex reindexForChanges() should correctly remove a deleted file 1`] = ` +Object { + "Class1": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 164, + "isExported": true, + "methods": Array [], + "name": "Class1", + "properties": Array [], + "start": 141, + }, + "from": "/classes", + }, + ], + "Class2": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 188, + "isExported": true, + "methods": Array [], + "name": "Class2", + "properties": Array [], + "start": 165, + }, + "from": "/classes", + }, + ], + "Class3": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 212, + "isExported": true, + "methods": Array [], + "name": "Class3", + "properties": Array [], + "start": 189, + }, + "from": "/classes", + }, + ], + "Class4": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 236, + "isExported": true, + "methods": Array [], + "name": "Class4", + "properties": Array [], + "start": 213, + }, + "from": "/classes", + }, + ], + "Class5": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 260, + "isExported": true, + "methods": Array [], + "name": "Class5", + "properties": Array [], + "start": 237, + }, + "from": "/classes", + }, + ], + "Class6": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 284, + "isExported": true, + "methods": Array [], + "name": "Class6", + "properties": Array [], + "start": 261, + }, + "from": "/classes", + }, + ], + "Class7": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 308, + "isExported": true, + "methods": Array [], + "name": "Class7", + "properties": Array [], + "start": 285, + }, + "from": "/classes", + }, + ], + "Class8": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 332, + "isExported": true, + "methods": Array [], + "name": "Class8", + "properties": Array [], + "start": 309, + }, + "from": "/classes", + }, + ], + "Class9": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 356, + "isExported": true, + "methods": Array [], + "name": "Class9", + "properties": Array [], + "start": 333, + }, + "from": "/classes", + }, + ], + "FancierLibraryClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 139, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 137, + "isAbstract": false, + "name": "doSomethingAwesome", + "parameters": Array [], + "start": 100, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "FancierLibraryClass", + "properties": Array [], + "start": 61, + }, + "from": "/classes", + }, + ], + "MyClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 59, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 57, + "isAbstract": false, + "name": "doSomething", + "parameters": Array [], + "start": 27, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "MyClass", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], +} +`; + +exports[`DeclarationIndex reindexForChanges() should correctly remove a deleted file 2`] = `Object {}`; + +exports[`DeclarationIndex reindexForChanges() should correctly remove an exported file 1`] = ` +Object { + "FancierLibraryClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 379, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 329, + "isAbstract": false, + "name": "doSomethingAwesome", + "parameters": Array [], + "start": 292, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "FancierLibraryClass", + "properties": Array [], + "start": 205, + }, + "from": "/classes", + }, + ], + "Foobar": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 21, + "isExported": true, + "methods": Array [], + "name": "Foobar", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], + "MyClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 155, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 105, + "isAbstract": false, + "name": "doSomething", + "parameters": Array [], + "start": 75, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "MyClass", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], +} +`; + +exports[`DeclarationIndex reindexForChanges() should correctly remove an exported file 2`] = ` +Object { + "FancierLibraryClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 379, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 329, + "isAbstract": false, + "name": "doSomethingAwesome", + "parameters": Array [], + "start": 292, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "FancierLibraryClass", + "properties": Array [], + "start": 205, + }, + "from": "/classes", + }, + ], + "MyClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 155, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 105, + "isAbstract": false, + "name": "doSomething", + "parameters": Array [], + "start": 75, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "MyClass", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], +} +`; + +exports[`DeclarationIndex reindexForChanges() should correctly update a file that is exported 1`] = ` +Object { + "FancierLibraryClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 379, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 329, + "isAbstract": false, + "name": "doSomethingAwesome", + "parameters": Array [], + "start": 292, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "FancierLibraryClass", + "properties": Array [], + "start": 205, + }, + "from": "/classes", + }, + ], + "Foobar": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 21, + "isExported": true, + "methods": Array [], + "name": "Foobar", + "properties": Array [], + "start": 0, + }, + "from": "/foobar", + }, + ], + "MyClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 155, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 105, + "isAbstract": false, + "name": "doSomething", + "parameters": Array [], + "start": 75, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "MyClass", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], +} +`; + +exports[`DeclarationIndex reindexForChanges() should correctly update a file that is exported 2`] = ` +Object { + "Barbaz": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 43, + "isExported": true, + "methods": Array [], + "name": "Barbaz", + "properties": Array [], + "start": 22, + }, + "from": "/classes", + }, + ], + "FancierLibraryClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 379, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 329, + "isAbstract": false, + "name": "doSomethingAwesome", + "parameters": Array [], + "start": 292, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "FancierLibraryClass", + "properties": Array [], + "start": 205, + }, + "from": "/classes", + }, + ], + "Foobar": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 21, + "isExported": true, + "methods": Array [], + "name": "Foobar", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], + "MyClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 155, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 105, + "isAbstract": false, + "name": "doSomething", + "parameters": Array [], + "start": 75, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "MyClass", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], +} +`; + +exports[`DeclarationIndex reindexForChanges() should correctly update a modified file 1`] = ` +Object { + "Class1": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 164, + "isExported": true, + "methods": Array [], + "name": "Class1", + "properties": Array [], + "start": 141, + }, + "from": "/classes", + }, + ], + "Class2": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 188, + "isExported": true, + "methods": Array [], + "name": "Class2", + "properties": Array [], + "start": 165, + }, + "from": "/classes", + }, + ], + "Class3": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 212, + "isExported": true, + "methods": Array [], + "name": "Class3", + "properties": Array [], + "start": 189, + }, + "from": "/classes", + }, + ], + "Class4": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 236, + "isExported": true, + "methods": Array [], + "name": "Class4", + "properties": Array [], + "start": 213, + }, + "from": "/classes", + }, + ], + "Class5": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 260, + "isExported": true, + "methods": Array [], + "name": "Class5", + "properties": Array [], + "start": 237, + }, + "from": "/classes", + }, + ], + "Class6": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 284, + "isExported": true, + "methods": Array [], + "name": "Class6", + "properties": Array [], + "start": 261, + }, + "from": "/classes", + }, + ], + "Class7": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 308, + "isExported": true, + "methods": Array [], + "name": "Class7", + "properties": Array [], + "start": 285, + }, + "from": "/classes", + }, + ], + "Class8": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 332, + "isExported": true, + "methods": Array [], + "name": "Class8", + "properties": Array [], + "start": 309, + }, + "from": "/classes", + }, + ], + "Class9": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 356, + "isExported": true, + "methods": Array [], + "name": "Class9", + "properties": Array [], + "start": 333, + }, + "from": "/classes", + }, + ], + "FancierLibraryClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 139, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 137, + "isAbstract": false, + "name": "doSomethingAwesome", + "parameters": Array [], + "start": 100, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "FancierLibraryClass", + "properties": Array [], + "start": 61, + }, + "from": "/classes", + }, + ], + "MyClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 59, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 57, + "isAbstract": false, + "name": "doSomething", + "parameters": Array [], + "start": 27, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "MyClass", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], +} +`; + +exports[`DeclarationIndex reindexForChanges() should correctly update a modified file 2`] = ` +Object { + "FancierLibraryClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 379, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 329, + "isAbstract": false, + "name": "doSomethingAwesome", + "parameters": Array [], + "start": 292, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "FancierLibraryClass", + "properties": Array [], + "start": 205, + }, + "from": "/classes", + }, + ], + "MyClass": Array [ + DeclarationInfo { + "declaration": ClassDeclaration { + "end": 155, + "isExported": true, + "methods": Array [ + MethodDeclaration { + "end": 105, + "isAbstract": false, + "name": "doSomething", + "parameters": Array [], + "start": 75, + "type": "void", + "variables": Array [], + "visibility": 2, + }, + ], + "name": "MyClass", + "properties": Array [], + "start": 0, + }, + "from": "/classes", + }, + ], +} +`; diff --git a/test/declaration-index/specific-cases/body-parser/DeclarationIndex.body-parser.spec.ts b/test/declaration-index/specific-cases/body-parser/DeclarationIndex.body-parser.spec.ts index ce26a8d..8d3acb3 100644 --- a/test/declaration-index/specific-cases/body-parser/DeclarationIndex.body-parser.spec.ts +++ b/test/declaration-index/specific-cases/body-parser/DeclarationIndex.body-parser.spec.ts @@ -3,7 +3,7 @@ import { join, resolve } from 'path'; import { DeclarationIndex } from '../../../../src/DeclarationIndex'; import { TypescriptParser } from '../../../../src/TypescriptParser'; -describe('DeclarationIndex - specific case "body-parser"', () => { +describe.skip('DeclarationIndex - specific case "body-parser"', () => { const rootPath = resolve( __dirname, '..', '..', '..', '_workspace', 'declaration-index', 'specific-cases', 'body-parser',