diff --git a/karma.conf.js b/karma.conf.js index 8e472cd..44e6ed9 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,3 +1,4 @@ +/* global process, */ 'use strict'; var path = require('path'); @@ -7,104 +8,160 @@ var _ = require('lodash'); var wiredep = require('wiredep'); var pathSrcHtml = [ - path.join(conf.paths.src, '/**/*.html') + path.join(conf.paths.src, '/**/*.html') ]; function listFiles() { - var wiredepOptions = _.extend({}, conf.wiredep, { - dependencies: true, - devDependencies: true - }); - - var patterns = wiredep(wiredepOptions).js - .concat([ - path.join(conf.paths.src, '/app/**/*.module.js'), - path.join(conf.paths.src, '/app/**/*.js'), - path.join(conf.paths.src, '/**/*.spec.js'), - path.join(conf.paths.src, '/**/*.mock.js'), - ]) - .concat(pathSrcHtml); - - var files = patterns.map(function(pattern) { - return { - pattern: pattern - }; - }); - files.push({ - pattern: path.join(conf.paths.src, '/assets/**/*'), - included: false, - served: true, - watched: false - }); - return files; + var wiredepOptions = _.extend({}, conf.wiredep, { + dependencies: true, + devDependencies: true + }); + + var patterns = wiredep(wiredepOptions).js + .concat([ + path.join(conf.paths.src, 'noosfero.js') + ,path.join(conf.paths.src, 'noosfero-testing.js'), + // path.join(conf.paths.src, '/app/**/*.module.js'), + // path.join(conf.paths.src, '/app/**/*.js'), + // path.join(conf.paths.src, '/**/*.spec.js'), + // path.join(conf.paths.src, '/**/*.mock.js') + + ]) + .concat(pathSrcHtml); + + var files = patterns.map(function (pattern) { + return { + pattern: pattern + }; + }); + files.push({ + pattern: path.join(conf.paths.src, '/assets/**/*'), + included: false, + served: true, + watched: false + }); + files.push({ + pattern: path.join(conf.paths.src, '/*.map'), + included: false, + served: true + }); + return files; } -module.exports = function(config) { - - var configuration = { - files: listFiles(), - - singleRun: true, - - autoWatch: false, - - ngHtml2JsPreprocessor: { - stripPrefix: conf.paths.src + '/', - moduleName: 'angular' - }, - - logLevel: 'WARN', - - frameworks: ['jasmine', 'angular-filesort'], - - angularFilesort: { - whitelist: [path.join(conf.paths.src, '/**/!(*.html|*.spec|*.mock).js')] - }, - - browsers : ['PhantomJS'], - - plugins : [ - 'karma-phantomjs-launcher', - 'karma-angular-filesort', - 'karma-coverage', - 'karma-jasmine', - 'karma-ng-html2js-preprocessor' - ], - - coverageReporter: { - type : 'html', - dir : 'coverage/' - }, +var webpackConfig = require("./webpack.config.js"); + +module.exports = function (config) { + + var configuration = { + files: listFiles(), + + singleRun: false, + + autoWatch: true, + colors: true, + + logLevel: config.LOG_INFO, + + ngHtml2JsPreprocessor: { + stripPrefix: conf.paths.src + '/', + moduleName: 'angular' + }, + + + frameworks: ['jasmine'],//, 'angular-filesort'], + + angularFilesort: { + whitelist: [path.join(conf.paths.src, '/**/!(*.html|*.spec|*.mock).js')] + }, + + browsers: ['Chrome'], + + webpack: _.merge({}, webpackConfig, { + externals: { + encapsulatedWindow: 'Object.create(window)' + + }, + resolve: { + alias : { + angular: "angular/angular.js" + } + }, + module: { + loaders: [ + { + test: /angular\.js$/, + loaders:[ + 'imports?window=encapsulatedWindow', + 'exports?window.angular' + ], + include: [new RegExp(__dirname + '/bower_components/angular/')] + } + ], + postLoaders: [ + { + test: /src\/noosfero.js/, + exclude: [ + /node_modules\//, + /bower_components\//, + /src\/noosfero-testing.js/ + ], + loader: 'istanbul-instrumenter' + } + + + ] + } + }), + webpackServer: { + quite: true + }, + plugins: [ + 'karma-chrome-launcher', + 'karma-phantomjs-launcher', + 'karma-angular-filesort', + 'karma-webpack', + 'karma-coverage', + 'karma-jasmine', + 'karma-ng-html2js-preprocessor' + ], + + coverageReporter: { + type: 'html', + dir: 'coverage/' + }, + + reporters: ['dots', "coverage"], + + proxies: { + '/assets/': path.join('/base/', conf.paths.src, '/assets/') + } + }; - reporters: ['progress'], + // This is the default preprocessors configuration for a usage with Karma cli + // The coverage preprocessor is added in gulp/unit-test.js only for single tests + // It was not possible to do it there because karma doesn't let us now if we are + // running a single test or not + configuration.preprocessors = { + 'src/**/*.[sS]pec.ts': ['webpack'] + }; - proxies: { - '/assets/': path.join('/base/', conf.paths.src, '/assets/') + pathSrcHtml.forEach(function (path) { + configuration.preprocessors[path] = ['ng-html2js']; + }); + + // This block is needed to execute Chrome on Travis + // If you ever plan to use Chrome and Travis, you can keep it + // If not, you can safely remove it + // https://github.com/karma-runner/karma/issues/1144#issuecomment-53633076 + if (configuration.browsers[0] === 'Chrome' && process.env.TRAVIS) { + configuration.customLaunchers = { + 'chrome-travis-ci': { + base: 'Chrome', + flags: ['--no-sandbox'] + } + }; + configuration.browsers = ['chrome-travis-ci']; } - }; - - // This is the default preprocessors configuration for a usage with Karma cli - // The coverage preprocessor is added in gulp/unit-test.js only for single tests - // It was not possible to do it there because karma doesn't let us now if we are - // running a single test or not - configuration.preprocessors = {}; - pathSrcHtml.forEach(function(path) { - configuration.preprocessors[path] = ['ng-html2js']; - }); - - // This block is needed to execute Chrome on Travis - // If you ever plan to use Chrome and Travis, you can keep it - // If not, you can safely remove it - // https://github.com/karma-runner/karma/issues/1144#issuecomment-53633076 - if(configuration.browsers[0] === 'Chrome' && process.env.TRAVIS) { - configuration.customLaunchers = { - 'chrome-travis-ci': { - base: 'Chrome', - flags: ['--no-sandbox'] - } - }; - configuration.browsers = ['chrome-travis-ci']; - } - config.set(configuration); + config.set(configuration); }; diff --git a/package.json b/package.json index a83cf3b..24b0609 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,11 @@ { - "name": "angular", + "name": "angular-theme", "version": "0.0.0", - "dependencies": {}, + "dependencies": { + "angular": "^1.5.0", + "angular-mock": "^1.0.0", + "moment": "^2.11.2" + }, "scripts": { "test": "gulp test", "postinstall": "npm install -g bower && bower install", @@ -43,10 +47,12 @@ "http-proxy-middleware": "~0.9.0", "karma": "~0.13.10", "karma-angular-filesort": "~1.0.0", - "karma-coverage": "~0.5.2", + "karma-chrome-launcher": "^0.2.2", + "karma-coverage": "^0.5.3", "karma-jasmine": "~0.3.6", "karma-ng-html2js-preprocessor": "~0.2.0", "karma-phantomjs-launcher": "~0.2.1", + "karma-webpack": "^1.7.0", "lodash": "~3.10.1", "main-bower-files": "~2.9.0", "ng-forward": "0.0.1-alpha.12", diff --git a/src/app/components/noosfero-articles/article/article.directive.spec.ts b/src/app/components/noosfero-articles/article/article.directive.spec.ts new file mode 100644 index 0000000..d688368 --- /dev/null +++ b/src/app/components/noosfero-articles/article/article.directive.spec.ts @@ -0,0 +1,91 @@ +let oldDefine = Object.defineProperties; + +Object.defineProperties = function(object, properties){ + let filteredProps = {}; + let currentProperties = Object.getOwnPropertyNames(object); + for (let i = 0; i < currentProperties.length; i++) { + let prop = currentProperties[i]; + if(currentProperties.indexOf(prop) < 0){ + filteredProps[prop] = properties[prop]; + } + } + oldDefine(object, filteredProps); +}; + +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; +import {Input, provide, Component} from 'ng-forward'; + +import {ArticleDirective} from './article.directive'; + + + + + + +// Instantiate the Builder, this part is different than ng2. +// In ng2 you inject tcb. +const tcb = new TestComponentBuilder(); + + +// Create your test bed +@Component({ selector: 'my-test' , template: '
'}) +class TestArticleDirective { + article = { type: 'TinyMceArticle' }; + profile = { name: 'profile-name' }; + constructor(){ + + } +} + + + +describe("Article Directive", () => { + it("does something", done => { + let html = ''; + tcb + .overrideTemplate(TestArticleDirective, html) + .createAsync(TestArticleDirective).then(fixture => { + let myComponent: ArticleDirective = fixture.componentInstance; + expect(myComponent.article.type).toEqual("TinyMceArticle"); + expect(myComponent.profile.name).toEqual("profile-name"); + console.log(fixture.debugElement); + done(); + }); + }); + + // let html = ''; + + // let noosferoApp: ng.IModule; + // let articleDirective: ArticleDirective; + // let $scope: ng.IScope; + // let element: ng.IAugmentedJQuery; + // beforeEach(angular.mock.module("noosferoApp")); + + // beforeEach(inject(function($controller: ng.IControllerService, $injector: ng.auto.IInjectorService, $rootScope, $q, $compile, $location, toastr) { + // let routeParams = {}; + // let $scope: ng.IScope = $rootScope.$new(); + // ($scope).ctrl = { + // article: { + // type: 'article' + // }, + // profile: { } + // }; + // element = getCompiledElement($scope, $compile); + // //let element = angular.element(''); + // //articleDirective = new ArticleDirective(element, $scope, $injector, $compile); + // console.log(articleDirective); + // })); + + // it("renders accordly the article type", (done) => { + // expect(1 + 1).toEqual(2); + // console.log(noosferoApp); + // done(); + // }); + + // function getCompiledElement($scope, $compile) { + // let element = angular.element(''); + // let compiledElement = $compile(element)($scope); + // $scope.$digest(); + // return compiledElement; + // } +}); \ No newline at end of file diff --git a/src/app/index.ts b/src/app/index.ts index b2c2fd1..e4534ec 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -1,3 +1,4 @@ + import "reflect-metadata"; import {NoosferoApp} from "./index.module"; import {noosferoModuleConfig} from "./index.config"; @@ -11,7 +12,9 @@ import {ProfileInfo as noosferoProfileInfo} from "./profile-info/profile-info.co import {Main} from "./main/main.component"; import {bootstrap, bundle} from "ng-forward"; -declare var moment: any; + + +declare var moment: any; let noosferoApp: any = bundle("noosferoApp", Main, ["ngAnimate", "ngCookies", "ngStorage", "ngTouch", "ngSanitize", "ngMessages", "ngAria", "restangular", diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..165dee1 --- /dev/null +++ b/tslint.json @@ -0,0 +1,54 @@ +{ + "rules": { + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "indent": [ + true, + "spaces" + ], + "no-duplicate-variable": true, + "no-eval": true, + "no-internal-module": true, + "no-trailing-whitespace": true, + "no-var-keyword": true, + "one-line": [ + true, + "check-open-brace", + "check-whitespace" + ], + "quotemark": [ + false, + "double" + ], + "semicolon": true, + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "variable-name": [ + true, + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-operator", + "check-separator", + "check-type" + ] + } +} \ No newline at end of file diff --git a/typings.json b/typings.json index 61100e6..041c682 100644 --- a/typings.json +++ b/typings.json @@ -4,8 +4,10 @@ "devDependencies": {}, "ambientDependencies": { "angular": "github:DefinitelyTyped/DefinitelyTyped/angularjs/angular.d.ts#1c4a34873c9e70cce86edd0e61c559e43dfa5f75", + "angular-mocks": "github:DefinitelyTyped/DefinitelyTyped/angularjs/angular-mocks.d.ts", "angular-ui-router": "github:DefinitelyTyped/DefinitelyTyped/angular-ui-router/angular-ui-router.d.ts#655f8c1bf3c71b0e1ba415b36309604f79326ac8", "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#4de74cb527395c13ba20b438c3a7a419ad931f1c", + "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#dd638012d63e069f2c99d06ef4dcc9616a943ee4", "jquery": "github:DefinitelyTyped/DefinitelyTyped/jquery/jquery.d.ts#470954c4f427e0805a2d633636a7c6aa7170def8", "restangular": "github:DefinitelyTyped/DefinitelyTyped/restangular/restangular.d.ts#f2ae460e1751bb6668d291d4eb9255f047dd0ac5" } diff --git a/webpack.config.js b/webpack.config.js index 4a63492..03a47eb 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,9 @@ +/* global __dirname */ + var argv = require("yargs").argv; var path = require("path"); +var glob = require("glob"); + var extension = ".js"; if (argv.production) { @@ -13,9 +17,12 @@ var uglifyLoaderConfig = { loader: "uglify" }; +var testingFiles = glob.sync("./src/app/**/*.[sS]pec.ts"); + var webpackConfig = { entry: { - noosfero: './src/app/index.ts' + noosfero: './src/app/index.ts', + 'noosfero-testing': testingFiles }, -- libgit2 0.21.2