Commit 69b2897c06beb6168a8bf79e46cf47d31e848177

Authored by ABNER SILVA DE OLIVEIRA
1 parent 4dc814d9

npm test now run the tests. sourcemap is working

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,19 @@ function listFiles() { @@ -20,15 +23,19 @@ function listFiles() {
20 23
21 var patterns = [].concat(wiredep(wiredepOptions).js) 24 var patterns = [].concat(wiredep(wiredepOptions).js)
22 .concat([ 25 .concat([
  26 + './src/noosfero-specs.js'
  27 + ]
  28 + //[
23 //path.join(conf.paths.src, 'common.js'), 29 //path.join(conf.paths.src, 'common.js'),
24 //, path.join(conf.paths.src, 'index.ts') 30 //, path.join(conf.paths.src, 'index.ts')
25 - path.join(conf.paths.src, 'test.js') 31 + //path.join(conf.paths.src, 'test.js')
26 // path.join(conf.paths.src, '/app/**/*.module.js'), 32 // path.join(conf.paths.src, '/app/**/*.module.js'),
27 // path.join(conf.paths.src, '/app/**/*.js'), 33 // path.join(conf.paths.src, '/app/**/*.js'),
28 // path.join(conf.paths.src, '/**/*.spec.js'), 34 // path.join(conf.paths.src, '/**/*.spec.js'),
29 // path.join(conf.paths.src, '/**/*.mock.js') 35 // path.join(conf.paths.src, '/**/*.mock.js')
30 36
31 - ]) 37 + //]
  38 + )
32 .concat(pathSrcHtml); 39 .concat(pathSrcHtml);
33 40
34 var files = patterns.map(function (pattern) { 41 var files = patterns.map(function (pattern) {
@@ -78,16 +85,16 @@ module.exports = function (config) { @@ -78,16 +85,16 @@ module.exports = function (config) {
78 85
79 browsers: ['PhantomJS'], 86 browsers: ['PhantomJS'],
80 87
81 - webpack2: _.merge({ 88 + /* webpack: _.merge({
82 89
83 }, webpackConfig, { 90 }, webpackConfig, {
84 - /*devtool: 'cheap-module-source-map'*/ 91 + devtool: 'inline-source-map'
85 }), 92 }),
86 webpackServer: { 93 webpackServer: {
87 quite: true 94 quite: true
88 - }, 95 + },*/
89 plugins: [ 96 plugins: [
90 - require('karma-webpack'), 97 +// require('karma-webpack'),
91 'karma-chrome-launcher', 98 'karma-chrome-launcher',
92 'karma-phantomjs-launcher', 99 'karma-phantomjs-launcher',
93 'karma-angular-filesort', 100 'karma-angular-filesort',
@@ -116,8 +123,9 @@ module.exports = function (config) { @@ -116,8 +123,9 @@ module.exports = function (config) {
116 // The coverage preprocessor is added in gulp/unit-test.js only for single tests 123 // 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 124 // 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 125 // running a single test or not
119 - configuration.preprocessors = {}  
120 - // 'src/**/*.ts': ['sourcemap'], 126 + configuration.preprocessors = {
  127 + 'src/**/*.js': ['sourcemap']
  128 + };
121 // 'src/**/*.js': ['sourcemap'], 129 // 'src/**/*.js': ['sourcemap'],
122 // 'src/**/*.[sS]pec.ts': ['sourcemap'] 130 // 'src/**/*.[sS]pec.ts': ['sourcemap']
123 // }; 131 // };
@@ -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 11 +// Create a component to include your testing component
31 @Component({ selector: 'my-test' , template: '<hr />'}) 12 @Component({ selector: 'my-test' , template: '<hr />'})
32 class TestArticleDirective { 13 class TestArticleDirective {
33 article = { type: 'TinyMceArticle' }; 14 article = { type: 'TinyMceArticle' };
34 profile = { name: 'profile-name' }; 15 profile = { name: 'profile-name' };
35 constructor(){ 16 constructor(){
36 -  
37 } 17 }
38 } 18 }
39 19
40 20
41 -  
42 describe("Article Directive", () => { 21 describe("Article Directive", () => {
43 - it("does something", done => { 22 + it("receives the article and profile as inputs", done => {
44 let html = '<noosfero-article [article]="ctr.article" [profile]="ctrl.profile"></noosfero-article>'; 23 let html = '<noosfero-article [article]="ctr.article" [profile]="ctrl.profile"></noosfero-article>';
45 tcb 24 tcb
46 .overrideTemplate(TestArticleDirective, html) 25 .overrideTemplate(TestArticleDirective, html)
@@ -53,39 +32,4 @@ describe(&quot;Article Directive&quot;, () =&gt; { @@ -53,39 +32,4 @@ describe(&quot;Article Directive&quot;, () =&gt; {
53 }); 32 });
54 }); 33 });
55 34
56 - // let html = '<noosfero-article [profile]=profile [artcile]=article></noosfero-article>';  
57 -  
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"));  
63 -  
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 - // }));  
78 -  
79 - // it("renders accordly the article type", (done) => {  
80 - // expect(1 + 1).toEqual(2);  
81 - // console.log(noosferoApp);  
82 - // done();  
83 - // });  
84 -  
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 }); 35 });
92 \ No newline at end of file 36 \ No newline at end of file
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
@@ -10,6 +10,8 @@ if (argv.production) { @@ -10,6 +10,8 @@ if (argv.production) {
10 extension = ".min.js" 10 extension = ".min.js"
11 } 11 }
12 12
  13 +var testFiles = glob.sync("./src/**/*.[sS]pec.ts");
  14 +
13 var uglifyLoaderConfig = { 15 var uglifyLoaderConfig = {
14 // I want to uglify with mangling only app files, not thirdparty libs 16 // I want to uglify with mangling only app files, not thirdparty libs
15 test: /\.js$/, 17 test: /\.js$/,
@@ -22,7 +24,7 @@ var testingFiles = glob.sync(&quot;./src/app/**/*.[sS]pec.ts&quot;); @@ -22,7 +24,7 @@ var testingFiles = glob.sync(&quot;./src/app/**/*.[sS]pec.ts&quot;);
22 var webpackConfig = { 24 var webpackConfig = {
23 entry: { 25 entry: {
24 noosfero: './src/app/index.ts', 26 noosfero: './src/app/index.ts',
25 - 'test': './src/test.ts' 27 + 'noosfero-specs': './src/spec.ts'
26 }, 28 },
27 29
28 30
@@ -38,7 +40,7 @@ var webpackConfig = { @@ -38,7 +40,7 @@ var webpackConfig = {
38 extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js'] 40 extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js']
39 }, 41 },
40 // Source maps support (or 'inline-source-map' also works) 42 // Source maps support (or 'inline-source-map' also works)
41 - devtool: 'source-map', 43 + devtool: 'inline-source-map',
42 44
43 module: { 45 module: {
44 loaders: [{ 46 loaders: [{