Commit f6b43ad2a88ad33e3dfb1602c4f1df8bd785b6f9

Authored by Victor Costa
2 parents 65a72194 50a53289

Merge branch 'ngforward' of softwarepublico.gov.br:noosfero-themes/angular-theme into ngforward

karma-webpack.conf.js 0 → 100644
@@ -0,0 +1,130 @@ @@ -0,0 +1,130 @@
  1 +/* global process, */
  2 +'use strict';
  3 +
  4 +var path = require('path');
  5 +var conf = require('./gulp/conf');
  6 +
  7 +
  8 +var _ = require('lodash');
  9 +var wiredep = require('wiredep');
  10 +
  11 +var pathSrcHtml = [
  12 + path.join(conf.paths.src, '/**/*.html')
  13 +];
  14 +
  15 +function listFiles() {
  16 + var wiredepOptions = _.extend({}, conf.wiredep, {
  17 + dependencies: true,
  18 + devDependencies: true
  19 + });
  20 +
  21 + var patterns = [].concat(wiredep(wiredepOptions).js)
  22 + .concat([
  23 + './src/spec.ts'
  24 + ]
  25 + )
  26 + .concat(pathSrcHtml);
  27 +
  28 + var files = patterns.map(function (pattern) {
  29 + return {
  30 + pattern: pattern
  31 + };
  32 + });
  33 + files.push({
  34 + pattern: path.join(conf.paths.src, '/assets/**/*'),
  35 + included: false,
  36 + served: true,
  37 + watched: false
  38 + });
  39 + return files;
  40 +}
  41 +
  42 +var webpackConfig = require("./webpack.config.js");
  43 +
  44 +module.exports = function (config) {
  45 +
  46 + var configuration = {
  47 + files: listFiles(),
  48 +
  49 + singleRun: false,
  50 +
  51 + autoWatch: true,
  52 + colors: true,
  53 +
  54 + logLevel: config.LOG_INFO,
  55 +
  56 + ngHtml2JsPreprocessor: {
  57 + stripPrefix: conf.paths.src + '/',
  58 + moduleName: 'angular'
  59 + },
  60 +
  61 +
  62 + frameworks: ['jasmine', 'phantomjs-shim'],//, 'angular-filesort'],
  63 +
  64 + angularFilesort: {
  65 + whitelist: [path.join(conf.paths.src, '/**/!(*.html|*.spec|*.mock).js')]
  66 + },
  67 +
  68 + browsers: ['PhantomJS'],
  69 +
  70 + webpack: _.merge({
  71 +
  72 + }, webpackConfig, {
  73 + devtool: 'inline-source-map'
  74 + }),
  75 + webpackServer: {
  76 + quite: true
  77 + },
  78 + plugins: [
  79 + 'karma-chrome-launcher',
  80 + 'karma-phantomjs-launcher',
  81 + 'karma-angular-filesort',
  82 + 'karma-webpack',
  83 + 'karma-phantomjs-shim',
  84 + 'karma-coverage',
  85 + 'karma-jasmine',
  86 + 'karma-spec-reporter',
  87 + 'karma-ng-html2js-preprocessor',
  88 + 'karma-sourcemap-loader'
  89 + ],
  90 +
  91 + coverageReporter: {
  92 + type: 'html',
  93 + dir: 'coverage/'
  94 + },
  95 +
  96 + reporters: ['spec', "coverage"],
  97 +
  98 + proxies: {
  99 + '/assets/': path.join('/base/', conf.paths.src, '/assets/')
  100 + }
  101 + };
  102 +
  103 + // This is the default preprocessors configuration for a usage with Karma cli
  104 + // The coverage preprocessor is added in gulp/unit-test.js only for single tests
  105 + // It was not possible to do it there because karma doesn't let us now if we are
  106 + // running a single test or not
  107 + configuration.preprocessors = {
  108 + 'src/**/*.ts': ['webpack','sourcemap']
  109 + };
  110 +
  111 + pathSrcHtml.forEach(function (path) {
  112 + configuration.preprocessors[path] = ['ng-html2js'];
  113 + });
  114 +
  115 + // This block is needed to execute Chrome on Travis
  116 + // If you ever plan to use Chrome and Travis, you can keep it
  117 + // If not, you can safely remove it
  118 + // https://github.com/karma-runner/karma/issues/1144#issuecomment-53633076
  119 + if (configuration.browsers[0] === 'Chrome' && process.env.TRAVIS) {
  120 + configuration.customLaunchers = {
  121 + 'chrome-travis-ci': {
  122 + base: 'Chrome',
  123 + flags: ['--no-sandbox']
  124 + }
  125 + };
  126 + configuration.browsers = ['chrome-travis-ci'];
  127 + }
  128 +
  129 + config.set(configuration);
  130 +};
@@ -12,6 +12,9 @@ var pathSrcHtml = [ @@ -12,6 +12,9 @@ var pathSrcHtml = [
12 path.join(conf.paths.src, '/**/*.html') 12 path.join(conf.paths.src, '/**/*.html')
13 ]; 13 ];
14 14
  15 +var glob = require("glob");
  16 +var testFiles = glob.sync("./src/**/*.[sS]pec.ts");
  17 +
15 function listFiles() { 18 function listFiles() {
16 var wiredepOptions = _.extend({}, conf.wiredep, { 19 var wiredepOptions = _.extend({}, conf.wiredep, {
17 dependencies: true, 20 dependencies: true,
@@ -20,15 +23,21 @@ function listFiles() { @@ -20,15 +23,21 @@ function listFiles() {
20 23
21 var patterns = [].concat(wiredep(wiredepOptions).js) 24 var patterns = [].concat(wiredep(wiredepOptions).js)
22 .concat([ 25 .concat([
  26 + './src/commons.js',
  27 + './src/noosfero.js',
  28 + './src/noosfero-specs.js'
  29 + ]
  30 + //[
23 //path.join(conf.paths.src, 'common.js'), 31 //path.join(conf.paths.src, 'common.js'),
24 //, path.join(conf.paths.src, 'index.ts') 32 //, path.join(conf.paths.src, 'index.ts')
25 - path.join(conf.paths.src, 'test.js') 33 + //path.join(conf.paths.src, 'test.js')
26 // path.join(conf.paths.src, '/app/**/*.module.js'), 34 // path.join(conf.paths.src, '/app/**/*.module.js'),
27 // path.join(conf.paths.src, '/app/**/*.js'), 35 // path.join(conf.paths.src, '/app/**/*.js'),
28 // path.join(conf.paths.src, '/**/*.spec.js'), 36 // path.join(conf.paths.src, '/**/*.spec.js'),
29 // path.join(conf.paths.src, '/**/*.mock.js') 37 // path.join(conf.paths.src, '/**/*.mock.js')
30 38
31 - ]) 39 + //]
  40 + )
32 .concat(pathSrcHtml); 41 .concat(pathSrcHtml);
33 42
34 var files = patterns.map(function (pattern) { 43 var files = patterns.map(function (pattern) {
@@ -78,16 +87,16 @@ module.exports = function (config) { @@ -78,16 +87,16 @@ module.exports = function (config) {
78 87
79 browsers: ['PhantomJS'], 88 browsers: ['PhantomJS'],
80 89
81 - webpack2: _.merge({ 90 + /* webpack: _.merge({
82 91
83 }, webpackConfig, { 92 }, webpackConfig, {
84 - /*devtool: 'cheap-module-source-map'*/ 93 + devtool: 'inline-source-map'
85 }), 94 }),
86 webpackServer: { 95 webpackServer: {
87 quite: true 96 quite: true
88 - }, 97 + },*/
89 plugins: [ 98 plugins: [
90 - require('karma-webpack'), 99 +// require('karma-webpack'),
91 'karma-chrome-launcher', 100 'karma-chrome-launcher',
92 'karma-phantomjs-launcher', 101 'karma-phantomjs-launcher',
93 'karma-angular-filesort', 102 'karma-angular-filesort',
@@ -116,8 +125,10 @@ module.exports = function (config) { @@ -116,8 +125,10 @@ module.exports = function (config) {
116 // The coverage preprocessor is added in gulp/unit-test.js only for single tests 125 // The coverage preprocessor is added in gulp/unit-test.js only for single tests
117 // It was not possible to do it there because karma doesn't let us now if we are 126 // It was not possible to do it there because karma doesn't let us now if we are
118 // running a single test or not 127 // running a single test or not
119 - configuration.preprocessors = {}  
120 - // 'src/**/*.ts': ['sourcemap'], 128 + configuration.preprocessors = {
  129 + 'src/**/*.js': ['sourcemap'],
  130 + 'src/**/*.ts': ['sourcemap']
  131 + };
121 // 'src/**/*.js': ['sourcemap'], 132 // 'src/**/*.js': ['sourcemap'],
122 // 'src/**/*.[sS]pec.ts': ['sourcemap'] 133 // 'src/**/*.[sS]pec.ts': ['sourcemap']
123 // }; 134 // };
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 "moment": "^2.11.2" 7 "moment": "^2.11.2"
8 }, 8 },
9 "scripts": { 9 "scripts": {
10 - "test": "gulp test", 10 + "test": "webpack -w & karma start",
11 "postinstall": "npm install -g bower && bower install", 11 "postinstall": "npm install -g bower && bower install",
12 "start": "concurrently \"webpack -w\" \"gulp serve\"" 12 "start": "concurrently \"webpack -w\" \"gulp serve\""
13 }, 13 },
src/app/components/noosfero-articles/article/article.directive.spec.ts
1 -// let oldDefine = Object.defineProperties;  
2 -//  
3 -// Object.defineProperties = function(object, properties){  
4 -// let filteredProps = {};  
5 -// let currentProperties = Object.getOwnPropertyNames(object);  
6 -// for (let i = 0; i < currentProperties.length; i++) {  
7 -// let prop = currentProperties[i];  
8 -// if(currentProperties.indexOf(prop) < 0){  
9 -// filteredProps[prop] = properties[prop];  
10 -// }  
11 -// }  
12 -// oldDefine(object, <any>filteredProps);  
13 -// };  
14 -  
15 import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; 1 import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
16 import {Input, provide, Component} from 'ng-forward'; 2 import {Input, provide, Component} from 'ng-forward';
17 3
18 import {ArticleDirective} from './article.directive'; 4 import {ArticleDirective} from './article.directive';
19 5
20 -  
21 -  
22 -  
23 -  
24 -  
25 // Instantiate the Builder, this part is different than ng2. 6 // Instantiate the Builder, this part is different than ng2.
26 // In ng2 you inject tcb. 7 // In ng2 you inject tcb.
27 const tcb = new TestComponentBuilder(); 8 const tcb = new TestComponentBuilder();
28 9
29 10
30 -// Create your test bed  
31 -@Component({ selector: 'my-test' , template: '<hr />'}) 11 +let html = '<noosfero-article [article]="ctr.article" [profile]="ctrl.profile"></noosfero-article>';
  12 +
  13 +// Create a component to include your testing component
  14 +@Component({ selector: 'my-test', template: html, directives: [ArticleDirective] })
32 class TestArticleDirective { 15 class TestArticleDirective {
33 article = { type: 'TinyMceArticle' }; 16 article = { type: 'TinyMceArticle' };
34 profile = { name: 'profile-name' }; 17 profile = { name: 'profile-name' };
35 - constructor(){  
36 - 18 + constructor() {
37 } 19 }
38 } 20 }
39 21
40 22
41 -  
42 describe("Article Directive", () => { 23 describe("Article Directive", () => {
43 - it("does something", done => {  
44 - let html = '<noosfero-article [article]="ctr.article" [profile]="ctrl.profile"></noosfero-article>'; 24 + it("receives the article and profile as inputs", done => {
45 tcb 25 tcb
46 - .overrideTemplate(TestArticleDirective, html)  
47 .createAsync(TestArticleDirective).then(fixture => { 26 .createAsync(TestArticleDirective).then(fixture => {
48 let myComponent: ArticleDirective = fixture.componentInstance; 27 let myComponent: ArticleDirective = fixture.componentInstance;
49 expect(myComponent.article.type).toEqual("TinyMceArticle"); 28 expect(myComponent.article.type).toEqual("TinyMceArticle");
@@ -53,39 +32,28 @@ describe(&quot;Article Directive&quot;, () =&gt; { @@ -53,39 +32,28 @@ describe(&quot;Article Directive&quot;, () =&gt; {
53 }); 32 });
54 }); 33 });
55 34
56 - // let html = '<noosfero-article [profile]=profile [artcile]=article></noosfero-article>'; 35 + it("renders a directive corresponding to the article type", done => {
57 36
58 - // let noosferoApp: ng.IModule;  
59 - // let articleDirective: ArticleDirective;  
60 - // let $scope: ng.IScope;  
61 - // let element: ng.IAugmentedJQuery;  
62 - // beforeEach(angular.mock.module("noosferoApp")); 37 + @Component({ selector: 'noosfero-TinyMceArticle', template: "<h1>custom component</h1>" })
  38 + class CustomArticleComponent {
63 39
64 - // beforeEach(inject(function($controller: ng.IControllerService, $injector: ng.auto.IInjectorService, $rootScope, $q, $compile, $location, toastr) {  
65 - // let routeParams = {};  
66 - // let $scope: ng.IScope = $rootScope.$new();  
67 - // (<any>$scope).ctrl = {  
68 - // article: {  
69 - // type: 'article'  
70 - // },  
71 - // profile: { }  
72 - // };  
73 - // element = getCompiledElement($scope, $compile);  
74 - // //let element = angular.element('<noosfero-article article="ctrl.article" [profile]="ctrl.profile"></noosfero-article>');  
75 - // //articleDirective = new ArticleDirective(element, $scope, $injector, $compile);  
76 - // console.log(articleDirective);  
77 - // })); 40 + }
78 41
79 - // it("renders accordly the article type", (done) => {  
80 - // expect(1 + 1).toEqual(2);  
81 - // console.log(noosferoApp);  
82 - // done();  
83 - // }); 42 + @Component({ selector: 'custom-article-type-test', template: html, directives: [ArticleDirective, CustomArticleComponent] })
  43 + class CustomArticleType {
  44 + article = { type: 'TinyMceArticle' };
  45 + profile = { name: 'profile-name' };
  46 + constructor() {
  47 + }
  48 + }
  49 + tcb
  50 + .createAsync(CustomArticleType).then(fixture => {
  51 + let myComponent: CustomArticleType = fixture.componentInstance;
  52 + expect(myComponent.article.type).toEqual("TinyMceArticle");
  53 + expect(myComponent.profile.name).toEqual("profile-name");
  54 + console.log(fixture.debugElement);
  55 + done();
  56 + });
  57 + });
84 58
85 - // function getCompiledElement($scope, $compile) {  
86 - // let element = angular.element('<noosfero-article [article]="ctrl.article" [profile]="ctrl.profile"></noosfero-article>');  
87 - // let compiledElement = $compile(element)($scope);  
88 - // $scope.$digest();  
89 - // return compiledElement;  
90 - // }  
91 }); 59 });
92 \ No newline at end of file 60 \ No newline at end of file
src/app/index.ts
1 1
  2 +import "core-js/shim";
2 import "reflect-metadata"; 3 import "reflect-metadata";
3 import {NoosferoApp} from "./index.module"; 4 import {NoosferoApp} from "./index.module";
4 import {noosferoModuleConfig} from "./index.config"; 5 import {noosferoModuleConfig} from "./index.config";
src/spec.ts 0 → 100644
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +
  2 +require("core-js/shim");
  3 +require("reflect-metadata");
  4 +require("ng-forward");
  5 +
  6 +
  7 +// require all spec files
  8 +requireAll((<any>require).context("./", true, /spec.ts$/));
  9 +function requireAll(r: any): any {
  10 + r.keys().forEach(r);
  11 +}
0 \ No newline at end of file 12 \ No newline at end of file
@@ -3,13 +3,14 @@ @@ -3,13 +3,14 @@
3 "module": "commonjs", 3 "module": "commonjs",
4 "target": "es5", 4 "target": "es5",
5 "noImplicitAny": false, 5 "noImplicitAny": false,
6 - "sourceMap": false, 6 + "sourceMap": true,
7 "experimentalDecorators": true 7 "experimentalDecorators": true
8 }, 8 },
9 "exclude": [ 9 "exclude": [
10 "node_modules", 10 "node_modules",
11 "typings/main", 11 "typings/main",
12 - "typings/main.d.ts" 12 + "typings/main.d.ts",
  13 + "node_modules/ng-forward/cjs/util/jqlite-extensions.d.ts"
13 ], 14 ],
14 "compileOnSave": false, 15 "compileOnSave": false,
15 "atom": { 16 "atom": {
webpack.config.js
@@ -3,13 +3,16 @@ @@ -3,13 +3,16 @@
3 var argv = require("yargs").argv; 3 var argv = require("yargs").argv;
4 var path = require("path"); 4 var path = require("path");
5 var glob = require("glob"); 5 var glob = require("glob");
6 -var webpack = require("webpack"); 6 +
  7 +var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
7 8
8 var extension = ".js"; 9 var extension = ".js";
9 if (argv.production) { 10 if (argv.production) {
10 extension = ".min.js" 11 extension = ".min.js"
11 } 12 }
12 13
  14 +var testFiles = glob.sync("./src/**/*.[sS]pec.ts");
  15 +
13 var uglifyLoaderConfig = { 16 var uglifyLoaderConfig = {
14 // I want to uglify with mangling only app files, not thirdparty libs 17 // I want to uglify with mangling only app files, not thirdparty libs
15 test: /\.js$/, 18 test: /\.js$/,
@@ -22,9 +25,10 @@ var testingFiles = glob.sync(&quot;./src/app/**/*.[sS]pec.ts&quot;); @@ -22,9 +25,10 @@ var testingFiles = glob.sync(&quot;./src/app/**/*.[sS]pec.ts&quot;);
22 var webpackConfig = { 25 var webpackConfig = {
23 entry: { 26 entry: {
24 noosfero: './src/app/index.ts', 27 noosfero: './src/app/index.ts',
25 - 'test': './src/test.ts' 28 + 'noosfero-specs': './src/spec.ts'
26 }, 29 },
27 30
  31 + plugins: [ new CommonsChunkPlugin("commons.js")],
28 32
29 output: { 33 output: {
30 path: path.join(__dirname, "src"), 34 path: path.join(__dirname, "src"),
@@ -38,7 +42,7 @@ var webpackConfig = { @@ -38,7 +42,7 @@ var webpackConfig = {
38 extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js'] 42 extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js']
39 }, 43 },
40 // Source maps support (or 'inline-source-map' also works) 44 // Source maps support (or 'inline-source-map' also works)
41 - devtool: 'source-map', 45 + devtool: 'inline-source-map',
42 46
43 module: { 47 module: {
44 loaders: [{ 48 loaders: [{