diff --git a/karma-webpack.conf.js b/karma-webpack.conf.js new file mode 100644 index 0000000..9b4c949 --- /dev/null +++ b/karma-webpack.conf.js @@ -0,0 +1,130 @@ +/* global process, */ +'use strict'; + +var path = require('path'); +var conf = require('./gulp/conf'); + + +var _ = require('lodash'); +var wiredep = require('wiredep'); + +var pathSrcHtml = [ + path.join(conf.paths.src, '/**/*.html') +]; + +function listFiles() { + var wiredepOptions = _.extend({}, conf.wiredep, { + dependencies: true, + devDependencies: true + }); + + var patterns = [].concat(wiredep(wiredepOptions).js) + .concat([ + './src/spec.ts' + ] + ) + .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 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', 'phantomjs-shim'],//, 'angular-filesort'], + + angularFilesort: { + whitelist: [path.join(conf.paths.src, '/**/!(*.html|*.spec|*.mock).js')] + }, + + browsers: ['PhantomJS'], + + webpack: _.merge({ + + }, webpackConfig, { + devtool: 'inline-source-map' + }), + webpackServer: { + quite: true + }, + plugins: [ + 'karma-chrome-launcher', + 'karma-phantomjs-launcher', + 'karma-angular-filesort', + 'karma-webpack', + 'karma-phantomjs-shim', + 'karma-coverage', + 'karma-jasmine', + 'karma-spec-reporter', + 'karma-ng-html2js-preprocessor', + 'karma-sourcemap-loader' + ], + + coverageReporter: { + type: 'html', + dir: 'coverage/' + }, + + reporters: ['spec', "coverage"], + + proxies: { + '/assets/': path.join('/base/', conf.paths.src, '/assets/') + } + }; + + // 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/**/*.ts': ['webpack','sourcemap'] + }; + + 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); +}; diff --git a/karma.conf.js b/karma.conf.js index d481e8b..5955f21 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -12,6 +12,9 @@ var pathSrcHtml = [ path.join(conf.paths.src, '/**/*.html') ]; +var glob = require("glob"); +var testFiles = glob.sync("./src/**/*.[sS]pec.ts"); + function listFiles() { var wiredepOptions = _.extend({}, conf.wiredep, { dependencies: true, @@ -20,15 +23,19 @@ function listFiles() { var patterns = [].concat(wiredep(wiredepOptions).js) .concat([ + './src/noosfero-specs.js' + ] + //[ //path.join(conf.paths.src, 'common.js'), //, path.join(conf.paths.src, 'index.ts') - path.join(conf.paths.src, 'test.js') + //path.join(conf.paths.src, 'test.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) { @@ -78,16 +85,16 @@ module.exports = function (config) { browsers: ['PhantomJS'], - webpack2: _.merge({ + /* webpack: _.merge({ }, webpackConfig, { - /*devtool: 'cheap-module-source-map'*/ + devtool: 'inline-source-map' }), webpackServer: { quite: true - }, + },*/ plugins: [ - require('karma-webpack'), +// require('karma-webpack'), 'karma-chrome-launcher', 'karma-phantomjs-launcher', 'karma-angular-filesort', @@ -116,8 +123,9 @@ module.exports = function (config) { // 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/**/*.ts': ['sourcemap'], + configuration.preprocessors = { + 'src/**/*.js': ['sourcemap'] + }; // 'src/**/*.js': ['sourcemap'], // 'src/**/*.[sS]pec.ts': ['sourcemap'] // }; diff --git a/package.json b/package.json index 280c6cc..8b416fa 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "moment": "^2.11.2" }, "scripts": { - "test": "gulp test", + "test": "webpack -w & karma start", "postinstall": "npm install -g bower && bower install", "start": "concurrently \"webpack -w\" \"gulp serve\"" }, diff --git a/src/app/components/noosfero-articles/article/article.directive.spec.ts b/src/app/components/noosfero-articles/article/article.directive.spec.ts index 6c2da04..89c6d0a 100644 --- a/src/app/components/noosfero-articles/article/article.directive.spec.ts +++ b/src/app/components/noosfero-articles/article/article.directive.spec.ts @@ -1,46 +1,25 @@ -// 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 +// Create a component to include your testing component @Component({ selector: 'my-test' , template: '
'}) class TestArticleDirective { article = { type: 'TinyMceArticle' }; profile = { name: 'profile-name' }; constructor(){ - } } - describe("Article Directive", () => { - it("does something", done => { + it("receives the article and profile as inputs", done => { let html = ''; tcb .overrideTemplate(TestArticleDirective, html) @@ -53,39 +32,4 @@ describe("Article Directive", () => { }); }); - // 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/spec.ts b/src/spec.ts new file mode 100644 index 0000000..238695c --- /dev/null +++ b/src/spec.ts @@ -0,0 +1,11 @@ + +require("core-js/shim"); +require("reflect-metadata"); +require("ng-forward"); + + +// require all spec files +requireAll((require).context("./", true, /spec.ts$/)); +function requireAll(r: any): any { + r.keys().forEach(r); +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index d9f2801..2ac2af1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,13 +3,14 @@ "module": "commonjs", "target": "es5", "noImplicitAny": false, - "sourceMap": false, + "sourceMap": true, "experimentalDecorators": true }, "exclude": [ "node_modules", "typings/main", - "typings/main.d.ts" + "typings/main.d.ts", + "node_modules/ng-forward/cjs/util/jqlite-extensions.d.ts" ], "compileOnSave": false, "atom": { diff --git a/webpack.config.js b/webpack.config.js index e1e2098..1d36066 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -10,6 +10,8 @@ if (argv.production) { extension = ".min.js" } +var testFiles = glob.sync("./src/**/*.[sS]pec.ts"); + var uglifyLoaderConfig = { // I want to uglify with mangling only app files, not thirdparty libs test: /\.js$/, @@ -22,7 +24,7 @@ var testingFiles = glob.sync("./src/app/**/*.[sS]pec.ts"); var webpackConfig = { entry: { noosfero: './src/app/index.ts', - 'test': './src/test.ts' + 'noosfero-specs': './src/spec.ts' }, @@ -38,7 +40,7 @@ var webpackConfig = { extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js'] }, // Source maps support (or 'inline-source-map' also works) - devtool: 'source-map', + devtool: 'inline-source-map', module: { loaders: [{ -- libgit2 0.21.2