From 4d80ce5b4ab7b336e32b4b79abfd46abd5e66e86 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Sun, 12 Jul 2015 19:10:58 +0100 Subject: [PATCH] chore(doc-gen): add some tests for typescript-definition-package --- docs/typescript-definition-package/index.js | 17 ++++++- .../mocks/mockPackage.js | 11 +++++ .../processors/createTypeDefinitionFile.js | 15 +----- .../createTypeDefinitionFile.spec.js | 48 +++++++++++++++++++ 4 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 docs/typescript-definition-package/mocks/mockPackage.js create mode 100644 docs/typescript-definition-package/processors/createTypeDefinitionFile.spec.js diff --git a/docs/typescript-definition-package/index.js b/docs/typescript-definition-package/index.js index 0a3c804bb7e7ef..532cfe5d3d1edd 100644 --- a/docs/typescript-definition-package/index.js +++ b/docs/typescript-definition-package/index.js @@ -29,7 +29,7 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage, renderDocsProcessor.extraData.versionInfo = versionInfo; }) -.config(function(readFilesProcessor, inlineTagProcessor, readTypeScriptModules) { +.config(function(readFilesProcessor, inlineTagProcessor, readTypeScriptModules, createTypeDefinitionFile) { // Don't run unwanted processors readFilesProcessor.$enabled = false; // We are not using the normal file reading processor @@ -42,6 +42,21 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage, 'angular2/router.ts' ]; readTypeScriptModules.basePath = path.resolve(path.resolve(__dirname, '../../modules')); + + createTypeDefinitionFile.typeDefinitions = [ + { + id: 'angular2/angular2', + modules: { + 'angular2/angular2': 'angular2/angular2', + } + }, + { + id: 'angular2/router', + modules: { + 'angular2/router': 'angular2/router' + } + } + ]; }) diff --git a/docs/typescript-definition-package/mocks/mockPackage.js b/docs/typescript-definition-package/mocks/mockPackage.js new file mode 100644 index 00000000000000..692309100060de --- /dev/null +++ b/docs/typescript-definition-package/mocks/mockPackage.js @@ -0,0 +1,11 @@ +var Package = require('dgeni').Package; + +module.exports = function mockPackage() { + + return new Package('mockPackage', [require('../')]) + + // provide a mock log service + .factory('log', function() { return require('dgeni/lib/mocks/log')(false); }) +// .factory('templateEngine', function() { return {}; }); + +}; diff --git a/docs/typescript-definition-package/processors/createTypeDefinitionFile.js b/docs/typescript-definition-package/processors/createTypeDefinitionFile.js index cdce0ccf70183d..f3bc002caa6592 100644 --- a/docs/typescript-definition-package/processors/createTypeDefinitionFile.js +++ b/docs/typescript-definition-package/processors/createTypeDefinitionFile.js @@ -13,20 +13,7 @@ module.exports = function createTypeDefinitionFile(log) { }, dtsPath: 'typings', dtsExtension: '.d.ts', - typeDefinitions: [ - { - id: 'angular2/angular2', - modules: { - 'angular2/angular2': 'angular2/angular2', - } - }, - { - id: 'angular2/router', - modules: { - 'angular2/router': 'angular2/router' - } - } - ], + typeDefinitions: [], $process: function(docs) { var dtsPath = this.dtsPath; var dtsExtension = this.dtsExtension; diff --git a/docs/typescript-definition-package/processors/createTypeDefinitionFile.spec.js b/docs/typescript-definition-package/processors/createTypeDefinitionFile.spec.js new file mode 100644 index 00000000000000..1bf15092d55643 --- /dev/null +++ b/docs/typescript-definition-package/processors/createTypeDefinitionFile.spec.js @@ -0,0 +1,48 @@ +var mockPackage = require('../mocks/mockPackage'); +var Dgeni = require('dgeni'); +var path = require('canonical-path'); +var _ = require('lodash'); + +describe('createTypeDefinitionFile processor', function() { + var dgeni, injector, processor; + + beforeEach(function() { + dgeni = new Dgeni([mockPackage()]); + injector = dgeni.configureInjector(); + processor = injector.get('createTypeDefinitionFile'); + + // Initialize the processor + processor.typeDefinitions = [{ + id: 'angular2/angular2', + modules: { 'angular2/angular2': 'angular2/angular2' } + }]; + }); + + + + describe('classes with private constructors', function() { + + it('should convert heritage from `implements` into `extends`', function() { + + // Create some mock docs for testing + var docs = [ + { + id: 'angular2/angular2', + exports: [ + { docType: 'class', heritage: 'implements Xyz', constructorDoc: { private: true } } + ] + } + ]; + + docs = processor.$process(docs); + + expect(docs.length).toEqual(1); + expect(docs[0].docType).toEqual('type-definition'); + + var moduleDoc = docs[0].moduleDocs['angular2/angular2'].doc; + expect(moduleDoc.exports.length).toEqual(2); + expect(moduleDoc.exports[0].heritage).toEqual('extends Xyz'); + }); + }); + +}); \ No newline at end of file