From de3f67e835fcfd504f1603abf3e29be1d7b1914c Mon Sep 17 00:00:00 2001 From: Matteo Perelli Date: Thu, 15 Dec 2016 10:35:21 +0100 Subject: [PATCH 01/20] Starting commit for e2e and unit tests --- e2e/app.e2e-spec.ts | 14 ++++++++++++++ e2e/app.po.ts | 11 +++++++++++ e2e/tsconfig.json | 16 ++++++++++++++++ package.json | 5 ++++- protractor.conf.js | 32 ++++++++++++++++++++++++++++++++ src/tests/.gitkeep | 0 6 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 e2e/app.e2e-spec.ts create mode 100644 e2e/app.po.ts create mode 100644 e2e/tsconfig.json create mode 100644 protractor.conf.js create mode 100644 src/tests/.gitkeep diff --git a/e2e/app.e2e-spec.ts b/e2e/app.e2e-spec.ts new file mode 100644 index 0000000000..748e4b7861 --- /dev/null +++ b/e2e/app.e2e-spec.ts @@ -0,0 +1,14 @@ +import { ProtractorPage } from './app.po'; + +describe('protractor App', function() { + let page: ProtractorPage; + + beforeEach(() => { + page = new ProtractorPage(); + }); + + it('should display message saying app works', () => { + page.navigateTo(); + expect(page.getParagraphText()).toEqual('app works!'); + }); +}); diff --git a/e2e/app.po.ts b/e2e/app.po.ts new file mode 100644 index 0000000000..b4ee755213 --- /dev/null +++ b/e2e/app.po.ts @@ -0,0 +1,11 @@ +import { browser, element, by } from 'protractor'; + +export class ProtractorPage { + navigateTo() { + return browser.get('/'); + } + + getParagraphText() { + return element(by.css('app-root h1')).getText(); + } +} diff --git a/e2e/tsconfig.json b/e2e/tsconfig.json new file mode 100644 index 0000000000..656bdb14ff --- /dev/null +++ b/e2e/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "declaration": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "module": "commonjs", + "moduleResolution": "node", + "outDir": "../dist/out-tsc-e2e", + "sourceMap": true, + "target": "es5", + "typeRoots": [ + "../node_modules/@types" + ] + } +} diff --git a/package.json b/package.json index f3972c23b5..6a6509fad0 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,10 @@ "debug:build": "node-nightly --inspect --debug-brk node_modules/webpack/bin/webpack.js", "debug:build:prod": "node-nightly --inspect --debug-brk node_modules/webpack/bin/webpack.js --config webpack.prod.config.ts", "lint": "tslint \"src/**/*.ts\" || true", - "global": "npm install -g angular-cli nodemon npm-check-updates rimraf ts-node typedoc typescript webpack webpack-bundle-size-analyzer marked node-gyp" + "global": "npm install -g angular-cli nodemon npm-check-updates rimraf ts-node typedoc typescript webpack webpack-bundle-size-analyzer marked node-gyp protractor", + "postglobal": "npm run webdriver:update -- --standalone", + "webdriver:start": "webdriver-manager start", + "webdriver:update": "webdriver-manager update" }, "dependencies": { "@angular/common": "2.2.4", diff --git a/protractor.conf.js b/protractor.conf.js new file mode 100644 index 0000000000..169743b34d --- /dev/null +++ b/protractor.conf.js @@ -0,0 +1,32 @@ +// Protractor configuration file, see link for more information +// https://github.com/angular/protractor/blob/master/docs/referenceConf.js + +/*global jasmine */ +var SpecReporter = require('jasmine-spec-reporter'); + +exports.config = { + allScriptsTimeout: 11000, + specs: [ + './e2e/**/*.e2e-spec.ts' + ], + capabilities: { + 'browserName': 'chrome' + }, + directConnect: true, + baseUrl: 'http://localhost:4200/', + framework: 'jasmine', + jasmineNodeOpts: { + showColors: true, + defaultTimeoutInterval: 30000, + print: function() {} + }, + useAllAngular2AppRoots: true, + beforeLaunch: function() { + require('ts-node').register({ + project: 'e2e' + }); + }, + onPrepare: function() { + jasmine.getEnv().addReporter(new SpecReporter()); + } +}; diff --git a/src/tests/.gitkeep b/src/tests/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 From 4b5d9d5dc67c67eb75a2bc1573aeb24199a6b1cf Mon Sep 17 00:00:00 2001 From: Matteo Perelli Date: Tue, 20 Dec 2016 14:43:25 +0100 Subject: [PATCH 02/20] Protractor configuration --- e2e/app.e2e-spec.ts | 9 +++++-- e2e/app.po.ts | 10 ++++--- package.json | 12 ++++++--- protractor.conf.js | 63 +++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 80 insertions(+), 14 deletions(-) diff --git a/e2e/app.e2e-spec.ts b/e2e/app.e2e-spec.ts index 748e4b7861..ee7b101f96 100644 --- a/e2e/app.e2e-spec.ts +++ b/e2e/app.e2e-spec.ts @@ -7,8 +7,13 @@ describe('protractor App', function() { page = new ProtractorPage(); }); - it('should display message saying app works', () => { + it('should display title "DSpace"', () => { page.navigateTo(); - expect(page.getParagraphText()).toEqual('app works!'); + expect(page.getPageTitleText()).toEqual('DSpace'); + }); + + it('should display title "Hello, World!"', () => { + page.navigateTo(); + expect(page.getFirstPText()).toEqual('Hello, World!'); }); }); diff --git a/e2e/app.po.ts b/e2e/app.po.ts index b4ee755213..164c524620 100644 --- a/e2e/app.po.ts +++ b/e2e/app.po.ts @@ -5,7 +5,11 @@ export class ProtractorPage { return browser.get('/'); } - getParagraphText() { - return element(by.css('app-root h1')).getText(); + getPageTitleText() { + return browser.getTitle(); } -} + + getFirstPText() { + return element(by.xpath('//p[1]')).getText(); + } +} \ No newline at end of file diff --git a/package.json b/package.json index 6a6509fad0..2441f93a50 100644 --- a/package.json +++ b/package.json @@ -46,9 +46,11 @@ "debug:build:prod": "node-nightly --inspect --debug-brk node_modules/webpack/bin/webpack.js --config webpack.prod.config.ts", "lint": "tslint \"src/**/*.ts\" || true", "global": "npm install -g angular-cli nodemon npm-check-updates rimraf ts-node typedoc typescript webpack webpack-bundle-size-analyzer marked node-gyp protractor", - "postglobal": "npm run webdriver:update -- --standalone", - "webdriver:start": "webdriver-manager start", - "webdriver:update": "webdriver-manager update" + "postglobal": "npm link protractor", + "protractor": "protractor", + "e2e": "npm run protractor", + "webdriver:start": "webdriver-manager start --seleniumPort 4444", + "webdriver:update": "webdriver-manager update --standalone" }, "dependencies": { "@angular/common": "2.2.4", @@ -128,6 +130,8 @@ "webpack-bundle-analyzer": "1.4.1", "webpack-dev-middleware": "1.8.4", "webpack-dev-server": "2.1.0-beta.11", - "webpack-merge": "1.0.2" + "webpack-merge": "1.0.2", + "jasmine-spec-reporter": "~2.7.0", + "protractor-istanbul-plugin": "~2.0.0" } } diff --git a/protractor.conf.js b/protractor.conf.js index 169743b34d..b128c26297 100644 --- a/protractor.conf.js +++ b/protractor.conf.js @@ -6,14 +6,67 @@ var SpecReporter = require('jasmine-spec-reporter'); exports.config = { allScriptsTimeout: 11000, + // ----------------------------------------------------------------- + // Uncomment to run tests using a remote Selenium server + //seleniumAddress: 'http://selenium.address:4444/wd/hub', + // Change to 'false' to run tests using a remote Selenium server + directConnect: true, + // Change if the website to test is not on the localhost + baseUrl: 'http://localhost:4200/', + // ----------------------------------------------------------------- specs: [ './e2e/**/*.e2e-spec.ts' ], - capabilities: { - 'browserName': 'chrome' - }, - directConnect: true, - baseUrl: 'http://localhost:4200/', + // ----------------------------------------------------------------- + // Browser and Capabilities: PhantomJS + // ----------------------------------------------------------------- + // capabilities: { + // 'browserName': 'phantomjs', + // 'version': '', + // 'platform': 'ANY' + // }, + // ----------------------------------------------------------------- + // Browser and Capabilities: Chrome + // ----------------------------------------------------------------- + capabilities: { + 'browserName': 'chrome', + 'version': '', + 'platform': 'ANY' + }, + // ----------------------------------------------------------------- + // Browser and Capabilities: Firefox + // ----------------------------------------------------------------- + // capabilities: { + // 'browserName': 'firefox', + // 'version': '', + // 'platform': 'ANY' + // }, + + // ----------------------------------------------------------------- + // Browser and Capabilities: MultiCapabilities + // ----------------------------------------------------------------- + //multiCapabilities: [ + // { + // 'browserName': 'phantomjs', + // 'version': '', + // 'platform': 'ANY' + // }, + // { + // 'browserName': 'chrome', + // 'version': '', + // 'platform': 'ANY' + // } + // { + // 'browserName': 'firefox', + // 'version': '', + // 'platform': 'ANY' + // } + //], + + plugins : [{ + path: 'node_modules/protractor-istanbul-plugin' + }], + framework: 'jasmine', jasmineNodeOpts: { showColors: true, From d624a196189720c3a1c8be6ad93a303a7d90201a Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Wed, 21 Dec 2016 11:32:47 +0100 Subject: [PATCH 03/20] unit test added --- helpers.js | 24 ++++ karma.conf.js | 140 +++++++++++++++++++ package.json | 22 ++- protractor.conf.js | 4 +- spec-bundle.js | 62 +++++++++ src/tests/app.component.spec.ts | 51 +++++++ webpack.test.config.js | 238 ++++++++++++++++++++++++++++++++ webpack.test.js | 238 ++++++++++++++++++++++++++++++++ 8 files changed, 774 insertions(+), 5 deletions(-) create mode 100644 helpers.js create mode 100644 karma.conf.js create mode 100644 spec-bundle.js create mode 100644 src/tests/app.component.spec.ts create mode 100644 webpack.test.config.js create mode 100644 webpack.test.js diff --git a/helpers.js b/helpers.js new file mode 100644 index 0000000000..41c9c7741b --- /dev/null +++ b/helpers.js @@ -0,0 +1,24 @@ +/** + * @author: @AngularClass + */ +var path = require('path'); + +// Helper functions +var ROOT = path.resolve(__dirname, '..'); + +function hasProcessFlag(flag) { + return process.argv.join('').indexOf(flag) > -1; +} + +function isWebpackDevServer() { + return process.argv[1] && !! (/webpack-dev-server/.exec(process.argv[1])); +} + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [ROOT].concat(args)); +} + +exports.hasProcessFlag = hasProcessFlag; +exports.isWebpackDevServer = isWebpackDevServer; +exports.root = root; diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000000..03727fa355 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,140 @@ +/** + * @author: @AngularClass + */ + +module.exports = function(config) { + var webdriverConfig = { + hostname: '4science-devel1', + port: 4202 + } + + var testWebpackConfig = require('./webpack.test.config.js')({env: 'test'}); + + var configuration = { + + // base path that will be used to resolve all patterns (e.g. files, exclude) + basePath: '', + + /* + * Frameworks to use + * + * available frameworks: https://npmjs.org/browse/keyword/karma-adapter + */ + frameworks: ['jasmine'], + + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-phantomjs-launcher'), + require('karma-webdriver-launcher'), + require('karma-coverage'), + require('karma-remap-istanbul'), + require('karma-sourcemap-loader'), + require('karma-webpack') + ], + + // list of files to exclude + exclude: [ ], + + /* + * list of files / patterns to load in the browser + * + * we are building the test environment in ./spec-bundle.js + */ + files: [ { pattern: './spec-bundle.js', watched: false } ], + + /* + * preprocess matching files before serving them to the browser + * available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + */ + preprocessors: { './spec-bundle.js': ['coverage', 'webpack', 'sourcemap'] }, + + // Webpack Config at ./webpack.test.js + webpack: testWebpackConfig, + + coverageReporter: { + reporters:[ + {type: 'in-memory'}, + {type: 'json', subdir: '.', file: 'coverage-final.json'}, + {type : 'html', dir : 'coverage/'} + ] + }, + + remapCoverageReporter: { + 'text-summary': null, + json: './coverage/coverage.json', + html: './coverage/html' + }, + + remapIstanbulReporter: { + reports: { + html: 'coverage' + } + }, + + // Webpack please don't spam the console when running in karma! + webpackMiddleware: { stats: 'errors-only'}, + + /* + * test results reporter to use + * + * possible values: 'dots', 'progress' + * available reporters: https://npmjs.org/browse/keyword/karma-reporter + */ + reporters: [ 'coverage', 'karma-remap-istanbul' ], + + // web server port + port: 4212, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + /* + * level of logging + * possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + */ + logLevel: config.LOG_INFO, + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + /* + * start these browsers + * available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + */ + browsers: [ + 'Chrome' + ], + + customLaunchers: { + ChromeTravisCi: { + base: 'Chrome', + flags: ['--no-sandbox'] + }, + 'chrome': { + base: 'WebDriver', + config: webdriverConfig, + browserName: 'chrome', + }, + 'firefox': { + base: 'WebDriver', + config: webdriverConfig, + browserName: 'firefox', + } + }, + + /* + * Continuous Integration mode + * if true, Karma captures browsers, runs the tests and exits + */ + singleRun: false + }; + + if (process.env.TRAVIS){ + configuration.browsers = [ + 'ChromeTravisCi' + ]; + } + + config.set(configuration); +}; diff --git a/package.json b/package.json index 2441f93a50..f29465acfc 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,8 @@ "postglobal": "npm link protractor", "protractor": "protractor", "e2e": "npm run protractor", + "test": "karma start", + "coverage": "http-server -c-1 -o -p 4211 ./coverage", "webdriver:start": "webdriver-manager start --seleniumPort 4444", "webdriver:update": "webdriver-manager update --standalone" }, @@ -98,6 +100,7 @@ "@types/express": "4.0.34", "@types/express-serve-static-core": "4.0.39", "@types/hammerjs": "2.0.33", + "@types/jasmine": "^2.2.34", "@types/memory-cache": "0.0.29", "@types/mime": "0.0.29", "@types/morgan": "1.7.32", @@ -112,12 +115,27 @@ "cookie-parser": "1.4.3", "copy-webpack-plugin": "4.0.1", "imports-loader": "0.6.5", + "istanbul-instrumenter-loader": "0.2.0", + "jasmine-core": "~2.5.2", + "jasmine-spec-reporter": "~2.7.0", "json-loader": "0.5.4", + "karma": "^1.2.0", + "karma-chrome-launcher": "^2.0.0", + "karma-coverage": "^1.1.1", + "karma-jasmine": "^1.0.2", + "karma-sourcemap-loader": "^0.3.7", + "karma-webpack": "1.8.0", + "karma-cli": "^1.0.1", + "karma-remap-istanbul": "^0.2.1", + "karma-webdriver-launcher": "^1.0.4", + "karma-phantomjs-launcher": "^1.0.2", "node-sass": "3.13.0", "nodemon": "1.11.0", + "protractor-istanbul-plugin": "~2.0.0", "raw-loader": "0.5.1", "reflect-metadata": "0.1.8", "rimraf": "2.5.4", + "source-map-loader": "^0.1.5", "string-replace-loader": "1.0.5", "ts-helpers": "1.1.2", "ts-node": "1.7.0", @@ -130,8 +148,6 @@ "webpack-bundle-analyzer": "1.4.1", "webpack-dev-middleware": "1.8.4", "webpack-dev-server": "2.1.0-beta.11", - "webpack-merge": "1.0.2", - "jasmine-spec-reporter": "~2.7.0", - "protractor-istanbul-plugin": "~2.0.0" + "webpack-merge": "1.0.2" } } diff --git a/protractor.conf.js b/protractor.conf.js index b128c26297..56a84875a1 100644 --- a/protractor.conf.js +++ b/protractor.conf.js @@ -12,7 +12,7 @@ exports.config = { // Change to 'false' to run tests using a remote Selenium server directConnect: true, // Change if the website to test is not on the localhost - baseUrl: 'http://localhost:4200/', + baseUrl: 'http://localhost:3000/', // ----------------------------------------------------------------- specs: [ './e2e/**/*.e2e-spec.ts' @@ -66,7 +66,7 @@ exports.config = { plugins : [{ path: 'node_modules/protractor-istanbul-plugin' }], - + framework: 'jasmine', jasmineNodeOpts: { showColors: true, diff --git a/spec-bundle.js b/spec-bundle.js new file mode 100644 index 0000000000..45954f4088 --- /dev/null +++ b/spec-bundle.js @@ -0,0 +1,62 @@ +/** + * @author: @AngularClass + */ + +/* + * When testing with webpack and ES6, we have to do some extra + * things to get testing to work right. Because we are gonna write tests + * in ES6 too, we have to compile those as well. That's handled in + * karma.conf.js with the karma-webpack plugin. This is the entry + * file for webpack test. Just like webpack will create a bundle.js + * file for our client, when we run test, it will compile and bundle them + * all here! Crazy huh. So we need to do some setup + */ +Error.stackTraceLimit = Infinity; + +require('core-js/es6'); +require('core-js/es7/reflect'); + +// Typescript emit helpers polyfill +require('ts-helpers'); + +require('zone.js/dist/zone'); +require('zone.js/dist/long-stack-trace-zone'); +require('zone.js/dist/proxy'); // since zone.js 0.6.15 +require('zone.js/dist/sync-test'); +require('zone.js/dist/jasmine-patch'); // put here since zone.js 0.6.14 +require('zone.js/dist/async-test'); +require('zone.js/dist/fake-async-test'); + +// RxJS +require('rxjs/Rx'); + +var testing = require('@angular/core/testing'); +var browser = require('@angular/platform-browser-dynamic/testing'); + +testing.TestBed.initTestEnvironment( + browser.BrowserDynamicTestingModule, + browser.platformBrowserDynamicTesting() +); + +/* + * Ok, this is kinda crazy. We can use the context method on + * require that webpack created in order to tell webpack + * what files we actually want to require or import. + * Below, context will be a function/object with file names as keys. + * Using that regex we are saying look in ../src then find + * any file that ends with spec.ts and get its path. By passing in true + * we say do this recursively + */ +var testContext = require.context('./src/tests', true, /\.spec\.ts/); + +/* + * get all the files, for each file, call the context function + * that will require the file and load it up here. Context will + * loop and require those spec files here + */ +function requireAll(requireContext) { + return requireContext.keys().map(requireContext); +} + +// requires and returns all modules that match +var modules = requireAll(testContext); diff --git a/src/tests/app.component.spec.ts b/src/tests/app.component.spec.ts new file mode 100644 index 0000000000..833b2f0253 --- /dev/null +++ b/src/tests/app.component.spec.ts @@ -0,0 +1,51 @@ +import { + async, + TestBed +} from '@angular/core/testing'; +import { + Component, + ChangeDetectionStrategy, + ViewEncapsulation, + OnDestroy, + OnInit, HostListener +} from "@angular/core"; +import { TranslateService } from "ng2-translate"; +import { HostWindowState } from "../app/shared/host-window.reducer"; +import { Store } from "@ngrx/store"; +import { HostWindowActions } from "../app/shared/host-window.actions"; + +// Load the implementations that should be tested +import { AppComponent } from '../app/app.component'; + + +describe('App', () => { + // provide our implementations or mocks to the dependency injector + /*beforeEach(() => TestBed.configureTestingModule({ + providers: [ + AppComponent, + { + provide: TranslateService, + useClass: class { dispatch = jasmine.createSpy('dispatch') } + }, + { + provide: Store, + useClass: class { dispatch = jasmine.createSpy('dispatch') } + } + ]}));*/ + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + AppComponent + ], + }); + TestBed.compileComponents(); + }); + + it('should create the app', async(() => { + let fixture = TestBed.createComponent(AppComponent); + let app = fixture.debugElement.componentInstance; + expect(app).toBeTruthy(); + })); + +}); diff --git a/webpack.test.config.js b/webpack.test.config.js new file mode 100644 index 0000000000..79fb87df6a --- /dev/null +++ b/webpack.test.config.js @@ -0,0 +1,238 @@ +/** + * @author: @AngularClass + */ + +const helpers = require('./helpers'); +const path = require('path'); + +/** + * Webpack Plugins + */ +const ProvidePlugin = require('webpack/lib/ProvidePlugin'); +const DefinePlugin = require('webpack/lib/DefinePlugin'); +const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin'); +const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin'); + +/** + * Webpack Constants + */ +const ENV = process.env.ENV = process.env.NODE_ENV = 'test'; + +/** + * Webpack configuration + * + * See: http://webpack.github.io/docs/configuration.html#cli + */ +module.exports = function (options) { + return { + + /** + * Source map for Karma from the help of karma-sourcemap-loader & karma-webpack + * + * Do not change, leave as is or it wont work. + * See: https://github.com/webpack/karma-webpack#source-maps + */ + devtool: 'inline-source-map', + + /** + * Options affecting the resolving of modules. + * + * See: http://webpack.github.io/docs/configuration.html#resolve + */ + resolve: { + + /** + * An array of extensions that should be used to resolve modules. + * + * See: http://webpack.github.io/docs/configuration.html#resolve-extensions + */ + extensions: ['.ts', '.js'], + + /** + * Make sure root is src + */ + modules: [ path.resolve(__dirname, 'src'), 'node_modules' ] + + }, + + /** + * Options affecting the normal modules. + * + * See: http://webpack.github.io/docs/configuration.html#module + * + * 'use:' revered back to 'loader:' as a temp. workaround for #1188 + * See: https://github.com/AngularClass/angular2-webpack-starter/issues/1188#issuecomment-262872034 + */ + module: { + + rules: [ + + /** + * Source map loader support for *.js files + * Extracts SourceMaps for source files that as added as sourceMappingURL comment. + * + * See: https://github.com/webpack/source-map-loader + */ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [ + // these packages have problems with their sourcemaps + helpers.root('node_modules/rxjs'), + helpers.root('node_modules/@angular') + ] + }, + + /** + * Typescript loader support for .ts and Angular 2 async routes via .async.ts + * + * See: https://github.com/s-panferov/awesome-typescript-loader + */ + { + test: /\.ts$/, + loader: 'awesome-typescript-loader', + query: { + // use inline sourcemaps for "karma-remap-coverage" reporter + sourceMap: false, + inlineSourceMap: true, + compilerOptions: { + + // Remove TypeScript helpers to be injected + // below by DefinePlugin + removeComments: true + + } + }, + exclude: [/\.e2e\.ts$/] + }, + + /** + * Json loader support for *.json files. + * + * See: https://github.com/webpack/json-loader + */ + { + test: /\.json$/, + loader: 'json-loader', + exclude: [helpers.root('src/index.html')] + }, + + /** + * Raw loader support for *.css files + * Returns file content as string + * + * See: https://github.com/webpack/raw-loader + */ + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [helpers.root('src/index.html')] + }, + + /** + * Raw loader support for *.html + * Returns file content as string + * + * See: https://github.com/webpack/raw-loader + */ + { + test: /\.html$/, + loader: 'raw-loader', + exclude: [helpers.root('src/index.html')] + }, + + /** + * Instruments JS files with Istanbul for subsequent code coverage reporting. + * Instrument only testing sources. + * + * See: https://github.com/deepsweet/istanbul-instrumenter-loader + */ + { + enforce: 'post', + test: /\.(js|ts)$/, + loader: 'istanbul-instrumenter-loader', + include: helpers.root('src'), + exclude: [ + /\.(e2e|spec)\.ts$/, + /node_modules/ + ] + } + + ] + }, + + /** + * Add additional plugins to the compiler. + * + * See: http://webpack.github.io/docs/configuration.html#plugins + */ + plugins: [ + + /** + * Plugin: DefinePlugin + * Description: Define free variables. + * Useful for having development builds with debug logging or adding global constants. + * + * Environment helpers + * + * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin + */ + // NOTE: when adding more properties make sure you include them in custom-typings.d.ts + new DefinePlugin({ + 'ENV': JSON.stringify(ENV), + 'HMR': false, + 'process.env': { + 'ENV': JSON.stringify(ENV), + 'NODE_ENV': JSON.stringify(ENV), + 'HMR': false, + } + }), + + /** + * Plugin: ContextReplacementPlugin + * Description: Provides context to Angular's use of System.import + * + * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin + * See: https://github.com/angular/angular/issues/11580 + */ + new ContextReplacementPlugin( + // The (\\|\/) piece accounts for path separators in *nix and Windows + /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/, + helpers.root('src'), // location of your src + { + // your Angular Async Route paths relative to this root directory + } + ), + + /** + * Plugin LoaderOptionsPlugin (experimental) + * + * See: https://gist.github.com/sokra/27b24881210b56bbaff7 + */ + new LoaderOptionsPlugin({ + debug: true, + options: { + + } + }), + + ], + + /** + * Include polyfills or mocks for various node stuff + * Description: Node configuration + * + * See: https://webpack.github.io/docs/configuration.html#node + */ + node: { + global: true, + process: false, + crypto: 'empty', + module: false, + clearImmediate: false, + setImmediate: false + } + + }; +} diff --git a/webpack.test.js b/webpack.test.js new file mode 100644 index 0000000000..79fb87df6a --- /dev/null +++ b/webpack.test.js @@ -0,0 +1,238 @@ +/** + * @author: @AngularClass + */ + +const helpers = require('./helpers'); +const path = require('path'); + +/** + * Webpack Plugins + */ +const ProvidePlugin = require('webpack/lib/ProvidePlugin'); +const DefinePlugin = require('webpack/lib/DefinePlugin'); +const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin'); +const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin'); + +/** + * Webpack Constants + */ +const ENV = process.env.ENV = process.env.NODE_ENV = 'test'; + +/** + * Webpack configuration + * + * See: http://webpack.github.io/docs/configuration.html#cli + */ +module.exports = function (options) { + return { + + /** + * Source map for Karma from the help of karma-sourcemap-loader & karma-webpack + * + * Do not change, leave as is or it wont work. + * See: https://github.com/webpack/karma-webpack#source-maps + */ + devtool: 'inline-source-map', + + /** + * Options affecting the resolving of modules. + * + * See: http://webpack.github.io/docs/configuration.html#resolve + */ + resolve: { + + /** + * An array of extensions that should be used to resolve modules. + * + * See: http://webpack.github.io/docs/configuration.html#resolve-extensions + */ + extensions: ['.ts', '.js'], + + /** + * Make sure root is src + */ + modules: [ path.resolve(__dirname, 'src'), 'node_modules' ] + + }, + + /** + * Options affecting the normal modules. + * + * See: http://webpack.github.io/docs/configuration.html#module + * + * 'use:' revered back to 'loader:' as a temp. workaround for #1188 + * See: https://github.com/AngularClass/angular2-webpack-starter/issues/1188#issuecomment-262872034 + */ + module: { + + rules: [ + + /** + * Source map loader support for *.js files + * Extracts SourceMaps for source files that as added as sourceMappingURL comment. + * + * See: https://github.com/webpack/source-map-loader + */ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [ + // these packages have problems with their sourcemaps + helpers.root('node_modules/rxjs'), + helpers.root('node_modules/@angular') + ] + }, + + /** + * Typescript loader support for .ts and Angular 2 async routes via .async.ts + * + * See: https://github.com/s-panferov/awesome-typescript-loader + */ + { + test: /\.ts$/, + loader: 'awesome-typescript-loader', + query: { + // use inline sourcemaps for "karma-remap-coverage" reporter + sourceMap: false, + inlineSourceMap: true, + compilerOptions: { + + // Remove TypeScript helpers to be injected + // below by DefinePlugin + removeComments: true + + } + }, + exclude: [/\.e2e\.ts$/] + }, + + /** + * Json loader support for *.json files. + * + * See: https://github.com/webpack/json-loader + */ + { + test: /\.json$/, + loader: 'json-loader', + exclude: [helpers.root('src/index.html')] + }, + + /** + * Raw loader support for *.css files + * Returns file content as string + * + * See: https://github.com/webpack/raw-loader + */ + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [helpers.root('src/index.html')] + }, + + /** + * Raw loader support for *.html + * Returns file content as string + * + * See: https://github.com/webpack/raw-loader + */ + { + test: /\.html$/, + loader: 'raw-loader', + exclude: [helpers.root('src/index.html')] + }, + + /** + * Instruments JS files with Istanbul for subsequent code coverage reporting. + * Instrument only testing sources. + * + * See: https://github.com/deepsweet/istanbul-instrumenter-loader + */ + { + enforce: 'post', + test: /\.(js|ts)$/, + loader: 'istanbul-instrumenter-loader', + include: helpers.root('src'), + exclude: [ + /\.(e2e|spec)\.ts$/, + /node_modules/ + ] + } + + ] + }, + + /** + * Add additional plugins to the compiler. + * + * See: http://webpack.github.io/docs/configuration.html#plugins + */ + plugins: [ + + /** + * Plugin: DefinePlugin + * Description: Define free variables. + * Useful for having development builds with debug logging or adding global constants. + * + * Environment helpers + * + * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin + */ + // NOTE: when adding more properties make sure you include them in custom-typings.d.ts + new DefinePlugin({ + 'ENV': JSON.stringify(ENV), + 'HMR': false, + 'process.env': { + 'ENV': JSON.stringify(ENV), + 'NODE_ENV': JSON.stringify(ENV), + 'HMR': false, + } + }), + + /** + * Plugin: ContextReplacementPlugin + * Description: Provides context to Angular's use of System.import + * + * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin + * See: https://github.com/angular/angular/issues/11580 + */ + new ContextReplacementPlugin( + // The (\\|\/) piece accounts for path separators in *nix and Windows + /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/, + helpers.root('src'), // location of your src + { + // your Angular Async Route paths relative to this root directory + } + ), + + /** + * Plugin LoaderOptionsPlugin (experimental) + * + * See: https://gist.github.com/sokra/27b24881210b56bbaff7 + */ + new LoaderOptionsPlugin({ + debug: true, + options: { + + } + }), + + ], + + /** + * Include polyfills or mocks for various node stuff + * Description: Node configuration + * + * See: https://webpack.github.io/docs/configuration.html#node + */ + node: { + global: true, + process: false, + crypto: 'empty', + module: false, + clearImmediate: false, + setImmediate: false + } + + }; +} From f2e7e5dc31083499dda3cba8555553349c6a5233 Mon Sep 17 00:00:00 2001 From: Matteo Perelli Date: Thu, 22 Dec 2016 10:00:37 +0100 Subject: [PATCH 04/20] Config file fix --- karma.conf.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 03727fa355..2b3b24a057 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -3,13 +3,15 @@ */ module.exports = function(config) { - var webdriverConfig = { - hostname: '4science-devel1', - port: 4202 - } - + var testWebpackConfig = require('./webpack.test.config.js')({env: 'test'}); + // Uncomment and change to run tests on a remote Selenium server + var webdriverConfig = { + hostname: 'localhost', + port: 4444 + } + var configuration = { // base path that will be used to resolve all patterns (e.g. files, exclude) @@ -83,8 +85,8 @@ module.exports = function(config) { */ reporters: [ 'coverage', 'karma-remap-istanbul' ], - // web server port - port: 4212, + // Karma web server port + port: 9876, // enable / disable colors in the output (reporters and logs) colors: true, @@ -104,19 +106,25 @@ module.exports = function(config) { */ browsers: [ 'Chrome' + //'ChromeTravisCi', + //'SeleniumChrome', + //'SeleniumFirefox' ], customLaunchers: { - ChromeTravisCi: { + // Continuous integraation with Chrome - launcher + 'ChromeTravisCi': { base: 'Chrome', flags: ['--no-sandbox'] }, - 'chrome': { + // Remote Selenium Server with Chrome - launcher + 'SeleniumChrome': { base: 'WebDriver', config: webdriverConfig, browserName: 'chrome', }, - 'firefox': { + // Remote Selenium Server with Firefox - launcher + 'SeleniumFirefox': { base: 'WebDriver', config: webdriverConfig, browserName: 'firefox', From 95a39ef88ce34996ab87fdcf1c52aa2eb6095b4f Mon Sep 17 00:00:00 2001 From: Matteo Perelli Date: Thu, 22 Dec 2016 12:05:58 +0100 Subject: [PATCH 05/20] Config file fix --- karma.conf.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 2b3b24a057..9061846541 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -58,7 +58,7 @@ module.exports = function(config) { reporters:[ {type: 'in-memory'}, {type: 'json', subdir: '.', file: 'coverage-final.json'}, - {type : 'html', dir : 'coverage/'} + {type: 'html', dir : 'coverage/'} ] }, @@ -98,7 +98,7 @@ module.exports = function(config) { logLevel: config.LOG_INFO, // enable / disable watching file and executing tests whenever any file changes - autoWatch: true, + autoWatch: false, /* * start these browsers From 2eabedd3cc5c473aa14a78c93b9efa69db18df2d Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 22 Dec 2016 12:07:33 +0100 Subject: [PATCH 06/20] unit test modified --- karma.conf.js | 10 +++-- package.json | 20 ++++++---- spec-bundle.js | 2 +- src/tests/app.component.spec.ts | 65 +++++++++++++++++++++++++++------ webpack.test.config.js | 5 ++- 5 files changed, 78 insertions(+), 24 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 03727fa355..d0a75826fb 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -28,6 +28,7 @@ module.exports = function(config) { require('karma-phantomjs-launcher'), require('karma-webdriver-launcher'), require('karma-coverage'), + require('karma-mocha-reporter'), require('karma-remap-istanbul'), require('karma-sourcemap-loader'), require('karma-webpack') @@ -67,6 +68,9 @@ module.exports = function(config) { }, remapIstanbulReporter: { + remapOptions: { + basePath: './src/app' + }, reports: { html: 'coverage' } @@ -81,7 +85,7 @@ module.exports = function(config) { * possible values: 'dots', 'progress' * available reporters: https://npmjs.org/browse/keyword/karma-reporter */ - reporters: [ 'coverage', 'karma-remap-istanbul' ], + reporters: [ 'mocha', 'coverage', 'karma-remap-istanbul' ], // web server port port: 4212, @@ -96,7 +100,7 @@ module.exports = function(config) { logLevel: config.LOG_INFO, // enable / disable watching file and executing tests whenever any file changes - autoWatch: true, + autoWatch: false, /* * start these browsers @@ -127,7 +131,7 @@ module.exports = function(config) { * Continuous Integration mode * if true, Karma captures browsers, runs the tests and exits */ - singleRun: false + singleRun: true }; if (process.env.TRAVIS){ diff --git a/package.json b/package.json index f29465acfc..b4b6d456ef 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,9 @@ "clean:scss:ts": "rimraf **/*.scss.ts", "clean:css:shim:ts": "rimraf **/*.css.shim.ts", "clean:scss:shim:ts": "rimraf **/*.scss.shim.ts", + "clean:coverage": "rimraf coverage", "clean:prod": "npm run clean:ngc && npm run clean:json && npm run clean:css && npm run clean:css:ts && npm run clean:scss:ts && npm run clean:css:shim:ts && npm run clean:scss:shim:ts && npm run clean:dist", - "clean": "npm run clean:log && npm run clean:dist && npm run clean:prod && npm run clean:node", + "clean": "npm run clean:log && npm run clean:dist && npm run clean:prod && npm run clean:coverage && npm run clean:node", "sass": "node-sass src -o src --include-path node_modules --output-style compressed -q", "sass:watch": "node-sass -w src -o src --include-path node_modules --output-style compressed -q", "prebuild": "npm run clean:dist && npm run sass", @@ -83,6 +84,7 @@ "compression": "1.6.2", "express": "4.14.0", "font-awesome": "4.7.0", + "http-server": "^0.9.0", "js.clone": "0.0.3", "methods": "1.1.2", "morgan": "1.7.0", @@ -114,21 +116,24 @@ "concurrently": "3.1.0", "cookie-parser": "1.4.3", "copy-webpack-plugin": "4.0.1", + "css-loader": "^0.26.0", + "html-webpack-plugin": "^2.21.0", "imports-loader": "0.6.5", - "istanbul-instrumenter-loader": "0.2.0", + "istanbul-instrumenter-loader": "1.1.0", "jasmine-core": "~2.5.2", "jasmine-spec-reporter": "~2.7.0", "json-loader": "0.5.4", "karma": "^1.2.0", "karma-chrome-launcher": "^2.0.0", + "karma-cli": "^1.0.1", "karma-coverage": "^1.1.1", "karma-jasmine": "^1.0.2", - "karma-sourcemap-loader": "^0.3.7", - "karma-webpack": "1.8.0", - "karma-cli": "^1.0.1", - "karma-remap-istanbul": "^0.2.1", - "karma-webdriver-launcher": "^1.0.4", + "karma-mocha-reporter": "^2.0.0", "karma-phantomjs-launcher": "^1.0.2", + "karma-remap-istanbul": "^0.4.0", + "karma-sourcemap-loader": "^0.3.7", + "karma-webdriver-launcher": "^1.0.4", + "karma-webpack": "1.8.0", "node-sass": "3.13.0", "nodemon": "1.11.0", "protractor-istanbul-plugin": "~2.0.0", @@ -137,6 +142,7 @@ "rimraf": "2.5.4", "source-map-loader": "^0.1.5", "string-replace-loader": "1.0.5", + "to-string-loader": "^1.1.4", "ts-helpers": "1.1.2", "ts-node": "1.7.0", "tslint": "4.0.2", diff --git a/spec-bundle.js b/spec-bundle.js index 45954f4088..36026d530f 100644 --- a/spec-bundle.js +++ b/spec-bundle.js @@ -47,7 +47,7 @@ testing.TestBed.initTestEnvironment( * any file that ends with spec.ts and get its path. By passing in true * we say do this recursively */ -var testContext = require.context('./src/tests', true, /\.spec\.ts/); +var testContext = require.context('./src', true, /\.spec\.ts/); /* * get all the files, for each file, call the context function diff --git a/src/tests/app.component.spec.ts b/src/tests/app.component.spec.ts index 833b2f0253..42bcc40a66 100644 --- a/src/tests/app.component.spec.ts +++ b/src/tests/app.component.spec.ts @@ -1,21 +1,20 @@ import { async, + ComponentFixture, + inject, TestBed } from '@angular/core/testing'; import { - Component, - ChangeDetectionStrategy, - ViewEncapsulation, - OnDestroy, - OnInit, HostListener + CUSTOM_ELEMENTS_SCHEMA, } from "@angular/core"; -import { TranslateService } from "ng2-translate"; -import { HostWindowState } from "../app/shared/host-window.reducer"; +import { TranslateModule } from "ng2-translate"; +import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap'; import { Store } from "@ngrx/store"; -import { HostWindowActions } from "../app/shared/host-window.actions"; + // Load the implementations that should be tested import { AppComponent } from '../app/app.component'; +import { HeaderComponent } from '../app/header/header.component'; describe('App', () => { @@ -35,17 +34,61 @@ describe('App', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ - AppComponent + providers: [ + AppComponent, + { + provide: Store, + useClass: class { dispatch = jasmine.createSpy('dispatch') } + } ], + declarations: [ + HeaderComponent + ], + imports: [TranslateModule.forRoot(), NgbCollapseModule.forRoot()], + schemas: [ CUSTOM_ELEMENTS_SCHEMA ] }); TestBed.compileComponents(); }); - it('should create the app', async(() => { + /*it('should create the app', async(() => { let fixture = TestBed.createComponent(AppComponent); let app = fixture.debugElement.componentInstance; expect(app).toBeTruthy(); + }));*/ + + it('should create the app', inject([ AppComponent ], (app: AppComponent) => { + expect(app).toBeTruthy(); })); + /* beforeEach(() => { + return TestBed.configureTestingModule({ + declarations: [AppComponent], + providers: [ + { + provide: TranslateService, + useClass: class { dispatch = jasmine.createSpy('dispatch') } + }, + { + provide: Store, + useClass: class { dispatch = jasmine.createSpy('dispatch') } + } + ] + }); + });*/ + + /*it('should create component', async(() => { + TestBed.compileComponents().then(() => { + const fixture = TestBed.createComponent(AppComponent); + + // Access the dependency injected component instance + const app = fixture.componentInstance; + + // Perform test using fixture and service + expect(true).toBe(true); + }); + }));*/ + + it('true is true', () => expect(true).toBe(true)); + }); + diff --git a/webpack.test.config.js b/webpack.test.config.js index 79fb87df6a..768ff712cd 100644 --- a/webpack.test.config.js +++ b/webpack.test.config.js @@ -91,7 +91,8 @@ module.exports = function (options) { */ { test: /\.ts$/, - loader: 'awesome-typescript-loader', + loaders: ['awesome-typescript-loader', 'angular2-template-loader'], + /*loader: 'awesome-typescript-loader', query: { // use inline sourcemaps for "karma-remap-coverage" reporter sourceMap: false, @@ -103,7 +104,7 @@ module.exports = function (options) { removeComments: true } - }, + },*/ exclude: [/\.e2e\.ts$/] }, From e9df2915e8a2c02933084b69073d64a7c3bcb01e Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 22 Dec 2016 12:11:48 +0100 Subject: [PATCH 07/20] test2.spec.ts added --- src/tests/test2.spec.ts | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/tests/test2.spec.ts diff --git a/src/tests/test2.spec.ts b/src/tests/test2.spec.ts new file mode 100644 index 0000000000..0169943357 --- /dev/null +++ b/src/tests/test2.spec.ts @@ -0,0 +1,58 @@ +/** + * Created by Giuseppe on 21/12/2016. + */ +// ... test imports +import { + async, + ComponentFixture, + inject, + TestBed +} from '@angular/core/testing'; +import { + CUSTOM_ELEMENTS_SCHEMA, + DebugElement +} from "@angular/core"; +import { TranslateModule } from "ng2-translate"; +import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap'; +import { Store } from "@ngrx/store"; + + +// Load the implementations that should be tested +import { AppComponent } from '../app/app.component'; +import { HeaderComponent } from '../app/header/header.component'; + +import { CommonModule } from '@angular/common'; + +let comp: AppComponent; +let fixture: ComponentFixture; +let de: DebugElement; +let el: HTMLElement; + + +describe('greeting component', () => { + + let fixture: ComponentFixture; + + beforeEach(() => { + return TestBed.configureTestingModule({ + imports: [ CommonModule, TranslateModule.forRoot(), NgbCollapseModule.forRoot()], + declarations: [ AppComponent, HeaderComponent ], // declare the test component + providers: [ + AppComponent, + { + provide: Store, + useClass: class { dispatch = jasmine.createSpy('dispatch') } + } + ], + schemas: [ CUSTOM_ELEMENTS_SCHEMA ] + }).compileComponents().then(() => { + fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); + }); + }); + + it('should create component', inject([AppComponent], (app: AppComponent) => { + // Perform test using fixture and service + expect(app).toBeTruthy(); + })); +}); From 1404e257319088502b6189ea0b55a4701242aaa6 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 22 Dec 2016 12:17:29 +0100 Subject: [PATCH 08/20] test2.spec.ts removed --- src/tests/test2.spec.ts | 58 ----------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 src/tests/test2.spec.ts diff --git a/src/tests/test2.spec.ts b/src/tests/test2.spec.ts deleted file mode 100644 index 0169943357..0000000000 --- a/src/tests/test2.spec.ts +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Created by Giuseppe on 21/12/2016. - */ -// ... test imports -import { - async, - ComponentFixture, - inject, - TestBed -} from '@angular/core/testing'; -import { - CUSTOM_ELEMENTS_SCHEMA, - DebugElement -} from "@angular/core"; -import { TranslateModule } from "ng2-translate"; -import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap'; -import { Store } from "@ngrx/store"; - - -// Load the implementations that should be tested -import { AppComponent } from '../app/app.component'; -import { HeaderComponent } from '../app/header/header.component'; - -import { CommonModule } from '@angular/common'; - -let comp: AppComponent; -let fixture: ComponentFixture; -let de: DebugElement; -let el: HTMLElement; - - -describe('greeting component', () => { - - let fixture: ComponentFixture; - - beforeEach(() => { - return TestBed.configureTestingModule({ - imports: [ CommonModule, TranslateModule.forRoot(), NgbCollapseModule.forRoot()], - declarations: [ AppComponent, HeaderComponent ], // declare the test component - providers: [ - AppComponent, - { - provide: Store, - useClass: class { dispatch = jasmine.createSpy('dispatch') } - } - ], - schemas: [ CUSTOM_ELEMENTS_SCHEMA ] - }).compileComponents().then(() => { - fixture = TestBed.createComponent(AppComponent); - fixture.detectChanges(); - }); - }); - - it('should create component', inject([AppComponent], (app: AppComponent) => { - // Perform test using fixture and service - expect(app).toBeTruthy(); - })); -}); From a58daf037d40050fcf47dcec3242c6e0bc03a920 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 22 Dec 2016 17:55:48 +0100 Subject: [PATCH 09/20] unit test modified --- helpers.js | 2 +- karma.conf.js | 13 +- package.json | 16 +-- spec-bundle.js | 2 +- src/tests/app.component.spec.ts | 77 +++-------- webpack.test.js | 238 -------------------------------- 6 files changed, 33 insertions(+), 315 deletions(-) delete mode 100644 webpack.test.js diff --git a/helpers.js b/helpers.js index 41c9c7741b..ed4330d342 100644 --- a/helpers.js +++ b/helpers.js @@ -4,7 +4,7 @@ var path = require('path'); // Helper functions -var ROOT = path.resolve(__dirname, '..'); +var ROOT = path.resolve(__dirname, '.'); function hasProcessFlag(flag) { return process.argv.join('').indexOf(flag) > -1; diff --git a/karma.conf.js b/karma.conf.js index 425e9aa335..fa0920e1b1 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -3,15 +3,15 @@ */ module.exports = function(config) { - + var testWebpackConfig = require('./webpack.test.config.js')({env: 'test'}); // Uncomment and change to run tests on a remote Selenium server var webdriverConfig = { hostname: 'localhost', port: 4444 - } - + }; + var configuration = { // base path that will be used to resolve all patterns (e.g. files, exclude) @@ -70,9 +70,6 @@ module.exports = function(config) { }, remapIstanbulReporter: { - remapOptions: { - basePath: './src/app' - }, reports: { html: 'coverage' } @@ -125,13 +122,13 @@ module.exports = function(config) { 'SeleniumChrome': { base: 'WebDriver', config: webdriverConfig, - browserName: 'chrome', + browserName: 'chrome' }, // Remote Selenium Server with Firefox - launcher 'SeleniumFirefox': { base: 'WebDriver', config: webdriverConfig, - browserName: 'firefox', + browserName: 'firefox' } }, diff --git a/package.json b/package.json index b4b6d456ef..5e8b4da1ca 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,11 @@ "clean:node": "rimraf node_modules/*", "clean:ngc": "rimraf **/*.ngfactory.ts", "clean:json": "rimraf *.records.json", - "clean:css": "rimraf **/*.css", - "clean:css:ts": "rimraf **/*.css.ts", - "clean:scss:ts": "rimraf **/*.scss.ts", - "clean:css:shim:ts": "rimraf **/*.css.shim.ts", - "clean:scss:shim:ts": "rimraf **/*.scss.shim.ts", + "clean:css": "rimraf src/**/*.css", + "clean:css:ts": "rimraf src/**/*.css.ts", + "clean:scss:ts": "rimraf src/**/*.scss.ts", + "clean:css:shim:ts": "rimraf src/**/*.css.shim.ts", + "clean:scss:shim:ts": "rimraf src/**/*.scss.shim.ts", "clean:coverage": "rimraf coverage", "clean:prod": "npm run clean:ngc && npm run clean:json && npm run clean:css && npm run clean:css:ts && npm run clean:scss:ts && npm run clean:css:shim:ts && npm run clean:scss:shim:ts && npm run clean:dist", "clean": "npm run clean:log && npm run clean:dist && npm run clean:prod && npm run clean:coverage && npm run clean:node", @@ -51,7 +51,7 @@ "protractor": "protractor", "e2e": "npm run protractor", "test": "karma start", - "coverage": "http-server -c-1 -o -p 4211 ./coverage", + "coverage": "http-server -c-1 -o ./coverage", "webdriver:start": "webdriver-manager start --seleniumPort 4444", "webdriver:update": "webdriver-manager update --standalone" }, @@ -119,7 +119,7 @@ "css-loader": "^0.26.0", "html-webpack-plugin": "^2.21.0", "imports-loader": "0.6.5", - "istanbul-instrumenter-loader": "1.1.0", + "istanbul-instrumenter-loader": "^0.2.0", "jasmine-core": "~2.5.2", "jasmine-spec-reporter": "~2.7.0", "json-loader": "0.5.4", @@ -130,7 +130,7 @@ "karma-jasmine": "^1.0.2", "karma-mocha-reporter": "^2.0.0", "karma-phantomjs-launcher": "^1.0.2", - "karma-remap-istanbul": "^0.4.0", + "karma-remap-istanbul": "^0.2.1", "karma-sourcemap-loader": "^0.3.7", "karma-webdriver-launcher": "^1.0.4", "karma-webpack": "1.8.0", diff --git a/spec-bundle.js b/spec-bundle.js index 36026d530f..45954f4088 100644 --- a/spec-bundle.js +++ b/spec-bundle.js @@ -47,7 +47,7 @@ testing.TestBed.initTestEnvironment( * any file that ends with spec.ts and get its path. By passing in true * we say do this recursively */ -var testContext = require.context('./src', true, /\.spec\.ts/); +var testContext = require.context('./src/tests', true, /\.spec\.ts/); /* * get all the files, for each file, call the context function diff --git a/src/tests/app.component.spec.ts b/src/tests/app.component.spec.ts index 42bcc40a66..973753a252 100644 --- a/src/tests/app.component.spec.ts +++ b/src/tests/app.component.spec.ts @@ -1,3 +1,4 @@ +// ... test imports import { async, ComponentFixture, @@ -6,6 +7,7 @@ import { } from '@angular/core/testing'; import { CUSTOM_ELEMENTS_SCHEMA, + DebugElement } from "@angular/core"; import { TranslateModule } from "ng2-translate"; import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap'; @@ -16,24 +18,20 @@ import { Store } from "@ngrx/store"; import { AppComponent } from '../app/app.component'; import { HeaderComponent } from '../app/header/header.component'; +import { CommonModule } from '@angular/common'; -describe('App', () => { - // provide our implementations or mocks to the dependency injector - /*beforeEach(() => TestBed.configureTestingModule({ - providers: [ - AppComponent, - { - provide: TranslateService, - useClass: class { dispatch = jasmine.createSpy('dispatch') } - }, - { - provide: Store, - useClass: class { dispatch = jasmine.createSpy('dispatch') } - } - ]}));*/ +let comp: AppComponent; +let fixture: ComponentFixture; +let de: DebugElement; +let el: HTMLElement; + + +describe('greeting component', () => { beforeEach(() => { - TestBed.configureTestingModule({ + return TestBed.configureTestingModule({ + imports: [ CommonModule, TranslateModule.forRoot(), NgbCollapseModule.forRoot()], + declarations: [ AppComponent, HeaderComponent ], // declare the test component providers: [ AppComponent, { @@ -41,54 +39,15 @@ describe('App', () => { useClass: class { dispatch = jasmine.createSpy('dispatch') } } ], - declarations: [ - HeaderComponent - ], - imports: [TranslateModule.forRoot(), NgbCollapseModule.forRoot()], schemas: [ CUSTOM_ELEMENTS_SCHEMA ] + }).compileComponents().then(() => { + fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); }); - TestBed.compileComponents(); }); - /*it('should create the app', async(() => { - let fixture = TestBed.createComponent(AppComponent); - let app = fixture.debugElement.componentInstance; - expect(app).toBeTruthy(); - }));*/ - - it('should create the app', inject([ AppComponent ], (app: AppComponent) => { + it('should create component', inject([AppComponent], (app: AppComponent) => { + // Perform test using fixture and service expect(app).toBeTruthy(); })); - - /* beforeEach(() => { - return TestBed.configureTestingModule({ - declarations: [AppComponent], - providers: [ - { - provide: TranslateService, - useClass: class { dispatch = jasmine.createSpy('dispatch') } - }, - { - provide: Store, - useClass: class { dispatch = jasmine.createSpy('dispatch') } - } - ] - }); - });*/ - - /*it('should create component', async(() => { - TestBed.compileComponents().then(() => { - const fixture = TestBed.createComponent(AppComponent); - - // Access the dependency injected component instance - const app = fixture.componentInstance; - - // Perform test using fixture and service - expect(true).toBe(true); - }); - }));*/ - - it('true is true', () => expect(true).toBe(true)); - }); - diff --git a/webpack.test.js b/webpack.test.js deleted file mode 100644 index 79fb87df6a..0000000000 --- a/webpack.test.js +++ /dev/null @@ -1,238 +0,0 @@ -/** - * @author: @AngularClass - */ - -const helpers = require('./helpers'); -const path = require('path'); - -/** - * Webpack Plugins - */ -const ProvidePlugin = require('webpack/lib/ProvidePlugin'); -const DefinePlugin = require('webpack/lib/DefinePlugin'); -const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin'); -const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin'); - -/** - * Webpack Constants - */ -const ENV = process.env.ENV = process.env.NODE_ENV = 'test'; - -/** - * Webpack configuration - * - * See: http://webpack.github.io/docs/configuration.html#cli - */ -module.exports = function (options) { - return { - - /** - * Source map for Karma from the help of karma-sourcemap-loader & karma-webpack - * - * Do not change, leave as is or it wont work. - * See: https://github.com/webpack/karma-webpack#source-maps - */ - devtool: 'inline-source-map', - - /** - * Options affecting the resolving of modules. - * - * See: http://webpack.github.io/docs/configuration.html#resolve - */ - resolve: { - - /** - * An array of extensions that should be used to resolve modules. - * - * See: http://webpack.github.io/docs/configuration.html#resolve-extensions - */ - extensions: ['.ts', '.js'], - - /** - * Make sure root is src - */ - modules: [ path.resolve(__dirname, 'src'), 'node_modules' ] - - }, - - /** - * Options affecting the normal modules. - * - * See: http://webpack.github.io/docs/configuration.html#module - * - * 'use:' revered back to 'loader:' as a temp. workaround for #1188 - * See: https://github.com/AngularClass/angular2-webpack-starter/issues/1188#issuecomment-262872034 - */ - module: { - - rules: [ - - /** - * Source map loader support for *.js files - * Extracts SourceMaps for source files that as added as sourceMappingURL comment. - * - * See: https://github.com/webpack/source-map-loader - */ - { - enforce: 'pre', - test: /\.js$/, - loader: 'source-map-loader', - exclude: [ - // these packages have problems with their sourcemaps - helpers.root('node_modules/rxjs'), - helpers.root('node_modules/@angular') - ] - }, - - /** - * Typescript loader support for .ts and Angular 2 async routes via .async.ts - * - * See: https://github.com/s-panferov/awesome-typescript-loader - */ - { - test: /\.ts$/, - loader: 'awesome-typescript-loader', - query: { - // use inline sourcemaps for "karma-remap-coverage" reporter - sourceMap: false, - inlineSourceMap: true, - compilerOptions: { - - // Remove TypeScript helpers to be injected - // below by DefinePlugin - removeComments: true - - } - }, - exclude: [/\.e2e\.ts$/] - }, - - /** - * Json loader support for *.json files. - * - * See: https://github.com/webpack/json-loader - */ - { - test: /\.json$/, - loader: 'json-loader', - exclude: [helpers.root('src/index.html')] - }, - - /** - * Raw loader support for *.css files - * Returns file content as string - * - * See: https://github.com/webpack/raw-loader - */ - { - test: /\.css$/, - loader: ['to-string-loader', 'css-loader'], - exclude: [helpers.root('src/index.html')] - }, - - /** - * Raw loader support for *.html - * Returns file content as string - * - * See: https://github.com/webpack/raw-loader - */ - { - test: /\.html$/, - loader: 'raw-loader', - exclude: [helpers.root('src/index.html')] - }, - - /** - * Instruments JS files with Istanbul for subsequent code coverage reporting. - * Instrument only testing sources. - * - * See: https://github.com/deepsweet/istanbul-instrumenter-loader - */ - { - enforce: 'post', - test: /\.(js|ts)$/, - loader: 'istanbul-instrumenter-loader', - include: helpers.root('src'), - exclude: [ - /\.(e2e|spec)\.ts$/, - /node_modules/ - ] - } - - ] - }, - - /** - * Add additional plugins to the compiler. - * - * See: http://webpack.github.io/docs/configuration.html#plugins - */ - plugins: [ - - /** - * Plugin: DefinePlugin - * Description: Define free variables. - * Useful for having development builds with debug logging or adding global constants. - * - * Environment helpers - * - * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin - */ - // NOTE: when adding more properties make sure you include them in custom-typings.d.ts - new DefinePlugin({ - 'ENV': JSON.stringify(ENV), - 'HMR': false, - 'process.env': { - 'ENV': JSON.stringify(ENV), - 'NODE_ENV': JSON.stringify(ENV), - 'HMR': false, - } - }), - - /** - * Plugin: ContextReplacementPlugin - * Description: Provides context to Angular's use of System.import - * - * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin - * See: https://github.com/angular/angular/issues/11580 - */ - new ContextReplacementPlugin( - // The (\\|\/) piece accounts for path separators in *nix and Windows - /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/, - helpers.root('src'), // location of your src - { - // your Angular Async Route paths relative to this root directory - } - ), - - /** - * Plugin LoaderOptionsPlugin (experimental) - * - * See: https://gist.github.com/sokra/27b24881210b56bbaff7 - */ - new LoaderOptionsPlugin({ - debug: true, - options: { - - } - }), - - ], - - /** - * Include polyfills or mocks for various node stuff - * Description: Node configuration - * - * See: https://webpack.github.io/docs/configuration.html#node - */ - node: { - global: true, - process: false, - crypto: 'empty', - module: false, - clearImmediate: false, - setImmediate: false - } - - }; -} From dab61554689c99557f3167781d37ad070e475f0f Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 22 Dec 2016 18:17:45 +0100 Subject: [PATCH 10/20] unit test modified --- karma.conf.js | 2 +- src/tests/app.component.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index fa0920e1b1..826d74a601 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -84,7 +84,7 @@ module.exports = function(config) { * possible values: 'dots', 'progress' * available reporters: https://npmjs.org/browse/keyword/karma-reporter */ - reporters: [ 'mocha', 'coverage', 'karma-remap-istanbul' ], + reporters: [ 'mocha', 'coverage' ], // Karma web server port port: 9876, diff --git a/src/tests/app.component.spec.ts b/src/tests/app.component.spec.ts index 973753a252..d69b35850d 100644 --- a/src/tests/app.component.spec.ts +++ b/src/tests/app.component.spec.ts @@ -26,7 +26,7 @@ let de: DebugElement; let el: HTMLElement; -describe('greeting component', () => { +describe('App component', () => { beforeEach(() => { return TestBed.configureTestingModule({ From 8df306ba9a78fbf5964e194a7f32bbcb7db638f5 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 22 Dec 2016 18:33:27 +0100 Subject: [PATCH 11/20] package.json merged --- package.json | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index c587d10b02..c8a95414bb 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,7 @@ "clean:scss:shim:ts": "rimraf src/**/*.scss.shim.ts", "clean:coverage": "rimraf coverage", "clean:prod": "npm run clean:ngc && npm run clean:json && npm run clean:css && npm run clean:css:ts && npm run clean:scss:ts && npm run clean:css:shim:ts && npm run clean:scss:shim:ts && npm run clean:dist", -<<<<<<< HEAD - "clean": "npm run clean:log && npm run clean:dist && npm run clean:prod && npm run clean:coverage && npm run clean:node", -======= - "clean": "npm run clean:log && npm run clean:prod && npm run clean:node", ->>>>>>> 8cd58f824333de235535bdec5975c3b42fe0ba29 + "clean": "npm run clean:log && npm run clean:prod && npm run clean:coverage && npm run clean:node", "sass": "node-sass src -o src --include-path node_modules --output-style compressed -q", "sass:watch": "node-sass -w src -o src --include-path node_modules --output-style compressed -q", "rollup": "rollup -c rollup-server.js && rollup -c rollup-client.js", @@ -54,8 +50,7 @@ "debug:build:prod": "node-nightly --inspect --debug-brk node_modules/webpack/bin/webpack.js --config webpack.prod.config.ts", "docs": "typedoc --options typedoc.json ./src", "lint": "tslint \"src/**/*.ts\" || true", -<<<<<<< HEAD - "global": "npm install -g angular-cli nodemon npm-check-updates rimraf ts-node typedoc typescript webpack webpack-bundle-size-analyzer marked node-gyp protractor", + "global": "npm install -g angular-cli nodemon npm-check-updates rimraf ts-node typedoc typescript webpack webpack-bundle-size-analyzer rollup marked node-gyp protractor", "postglobal": "npm link protractor", "protractor": "protractor", "e2e": "npm run protractor", @@ -63,9 +58,6 @@ "coverage": "http-server -c-1 -o ./coverage", "webdriver:start": "webdriver-manager start --seleniumPort 4444", "webdriver:update": "webdriver-manager update --standalone" -======= - "global": "npm install -g angular-cli nodemon npm-check-updates rimraf ts-node typedoc typescript webpack webpack-bundle-size-analyzer rollup marked node-gyp" ->>>>>>> 8cd58f824333de235535bdec5975c3b42fe0ba29 }, "dependencies": { "@angular/common": "2.2.3", @@ -128,10 +120,9 @@ "concurrently": "3.1.0", "cookie-parser": "1.4.3", "copy-webpack-plugin": "4.0.1", -<<<<<<< HEAD "css-loader": "^0.26.0", "html-webpack-plugin": "^2.21.0", - "imports-loader": "0.6.5", + "imports-loader": "0.7.0", "istanbul-instrumenter-loader": "^0.2.0", "jasmine-core": "~2.5.2", "jasmine-spec-reporter": "~2.7.0", @@ -147,26 +138,18 @@ "karma-sourcemap-loader": "^0.3.7", "karma-webdriver-launcher": "^1.0.4", "karma-webpack": "1.8.0", - "node-sass": "3.13.0", -======= - "imports-loader": "0.7.0", - "json-loader": "0.5.4", "node-sass": "4.0.0", ->>>>>>> 8cd58f824333de235535bdec5975c3b42fe0ba29 "nodemon": "1.11.0", "protractor-istanbul-plugin": "~2.0.0", "raw-loader": "0.5.1", "reflect-metadata": "0.1.8", "rimraf": "2.5.4", -<<<<<<< HEAD - "source-map-loader": "^0.1.5", -======= "rollup": "0.37.0", "rollup-plugin-commonjs": "6.0.0", "rollup-plugin-node-globals": "1.1.0", "rollup-plugin-node-resolve": "2.0.0", "rollup-plugin-uglify": "1.0.1", ->>>>>>> 8cd58f824333de235535bdec5975c3b42fe0ba29 + "source-map-loader": "^0.1.5", "string-replace-loader": "1.0.5", "to-string-loader": "^1.1.4", "ts-helpers": "1.1.2", From 697a398dc7d7a258dc79851ff4c666b082bd235d Mon Sep 17 00:00:00 2001 From: Matteo Perelli Date: Thu, 22 Dec 2016 18:37:56 +0100 Subject: [PATCH 12/20] README.md update with tests --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/README.md b/README.md index a7b658b5c4..abb2d6130e 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,52 @@ npm run clean:prod npm run clean:dist ``` +## Tests +# Unit Test +Unit tests use Karma. You can find the configuration file at the same level of this README file: +`./karma.conf.js` +If you are going to use a remote test enviroment you need to edit the './karma.conf.js'. Follow the instructions you will find inside it. +To executing tests whenever any file changes you can modify the 'autoWatch' option to 'true' and 'singleRun' option to 'false'. +keeping Karma running, it's possible to see a tests report here: +http://localhost:9876/debug.html +A coverage report is also available at: +http://localhost:9876/ +after you run: +`npm run coverage` + +To correctly run the tests you need to run the build once with: +`npm run build` + +The default browser is Google Chrome. + +Place your tests at the following path: +`./src/tests` + +and run: +`npn run test` + +# E2E test +E2E tests use Protractor + Selenium server + browsers. You can find the configuration file at the same level of this README file: +`./protractor.conf.js` +Protractor must be installed as 'global' so, make sure you have runned: +`npm run global` +If you are going to execute tests locally you need to run (once time only): +`npm run webdriver:update` + +If you are going to use a remote test enviroment you need to edit the './protractor.conf.js'. Follow the instructions you will find inside it. +The default browser is Google Chrome. + +Protractor needs a functional instance of the DSpace interface to run the E2E tests, so you need to run: +`npm run watch:dev` + +or any command that bring up the DSpace interface. + +Place your tests at the following path: +`./e2e` + +and run: +`npm run e2e` + ## Other commands There are many more commands in the `scripts` section of `package.json`. Most of these are executed by one of the commands mentioned above. A command with a name that starts with `pre` or `post` will be executed automatically before or after the script with the matching name. e.g. if you type `npm run start` the `prestart` script will run first, then the `start` script will trigger. From b65e2f9442a9ce67150ffd93d34ec44ac375f294 Mon Sep 17 00:00:00 2001 From: Matteo Perelli Date: Thu, 22 Dec 2016 18:48:15 +0100 Subject: [PATCH 13/20] README.md update --- README.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index abb2d6130e..894f506f1e 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Then go to [http://localhost:3000](http://localhost:3000) in your browser * [Running the app](#running-the-app) * [Running in production mode](#running-in-production-mode) * [Cleaning](#cleaning) +* [Testing](#testing) * [Other commands](#other-commands) * [Recommended Editors/IDEs](#recommended-editorsides) * [Collaborating](#collaborating) @@ -85,21 +86,19 @@ npm run clean:prod npm run clean:dist ``` -## Tests -# Unit Test +## Testing +### Unit Test Unit tests use Karma. You can find the configuration file at the same level of this README file: `./karma.conf.js` If you are going to use a remote test enviroment you need to edit the './karma.conf.js'. Follow the instructions you will find inside it. To executing tests whenever any file changes you can modify the 'autoWatch' option to 'true' and 'singleRun' option to 'false'. -keeping Karma running, it's possible to see a tests report here: -http://localhost:9876/debug.html A coverage report is also available at: http://localhost:9876/ after you run: -`npm run coverage` +`npm run coverage`. To correctly run the tests you need to run the build once with: -`npm run build` +`npm run build`. The default browser is Google Chrome. @@ -109,13 +108,13 @@ Place your tests at the following path: and run: `npn run test` -# E2E test +### E2E test E2E tests use Protractor + Selenium server + browsers. You can find the configuration file at the same level of this README file: `./protractor.conf.js` Protractor must be installed as 'global' so, make sure you have runned: -`npm run global` +`npm run global`. If you are going to execute tests locally you need to run (once time only): -`npm run webdriver:update` +`npm run webdriver:update`. If you are going to use a remote test enviroment you need to edit the './protractor.conf.js'. Follow the instructions you will find inside it. The default browser is Google Chrome. @@ -157,8 +156,11 @@ See [the guide on the wiki](https://wiki.duraspace.org/display/DSPACE/DSpace+7+- dspace-angular ├── README.md * This document ├── app.json * Application manifest file +├── e2e * Folder for e2e test files +├── karma.conf.js * Unit Test configuration file ├── nodemon.json * Nodemon (https://nodemon.io/) configuration ├── package.json * This file describes the npm package for this project, its dependencies, scripts, etc. +├── protractor.conf.js * E2E tests configuration file ├── resources * Folder for static resources │   ├── i18n * Folder for i18n translations │   └── images * Folder for images @@ -179,6 +181,7 @@ dspace-angular │   ├── styles * Folder containing global styles. │   │   ├── main.scss * Global scss file │   │   └── variables.scss * Global sass variables file +│   ├── tests * Folder for unit test files │   └── typings.d.ts * File that allows you to add custom typings for libraries without TypeScript support ├── tsconfig.aot.json * TypeScript config for production builds ├── tsconfig.json * TypeScript config for development build From 48edf039ba005166df25f5621ffd201ec7b90051 Mon Sep 17 00:00:00 2001 From: Matteo Perelli Date: Thu, 22 Dec 2016 18:53:59 +0100 Subject: [PATCH 14/20] README.md update --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 894f506f1e..3cb7861bdc 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,7 @@ If you are going to execute tests locally you need to run (once time only): `npm run webdriver:update`. If you are going to use a remote test enviroment you need to edit the './protractor.conf.js'. Follow the instructions you will find inside it. + The default browser is Google Chrome. Protractor needs a functional instance of the DSpace interface to run the E2E tests, so you need to run: @@ -187,6 +188,7 @@ dspace-angular ├── tsconfig.json * TypeScript config for development build ├── tslint.json * TSLint (https://palantir.github.io/tslint/) configuration ├── webpack.config.ts * Webpack (https://webpack.github.io/) config for development builds +├── webpack.test.config.ts * Webpack (https://webpack.github.io/) config for testing └── webpack.prod.config.ts * Webpack (https://webpack.github.io/) config for production builds ``` From 29eee0dda66ae3c9b5c2491ae04ab3d41c58ae96 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 22 Dec 2016 19:20:06 +0100 Subject: [PATCH 15/20] package.json modified --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c8a95414bb..a7b60f7313 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "protractor": "protractor", "e2e": "npm run protractor", "test": "karma start", - "coverage": "http-server -c-1 -o ./coverage", + "coverage": "http-server -c-1 -o -p 4211 ./coverage", "webdriver:start": "webdriver-manager start --seleniumPort 4444", "webdriver:update": "webdriver-manager update --standalone" }, From dcbb33d7ba19b96d4c0775d87a64f3e0a98ca844 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 22 Dec 2016 19:25:54 +0100 Subject: [PATCH 16/20] package.json modified --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a7b60f7313..292e8ccb89 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "protractor": "protractor", "e2e": "npm run protractor", "test": "karma start", - "coverage": "http-server -c-1 -o -p 4211 ./coverage", + "coverage": "http-server -c-1 -o -p 9875 ./coverage", "webdriver:start": "webdriver-manager start --seleniumPort 4444", "webdriver:update": "webdriver-manager update --standalone" }, From 11c5e2ff7957b3122d005cf0f01c96d741e5988d Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 5 Jan 2017 11:29:25 +0100 Subject: [PATCH 17/20] Karma remap istanbul bug fix --- karma.conf.js | 4 ++-- tsconfig.json | 1 + webpack.test.config.js | 31 +++++++++++++++++-------------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 826d74a601..ccc4f2e193 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -15,7 +15,7 @@ module.exports = function(config) { var configuration = { // base path that will be used to resolve all patterns (e.g. files, exclude) - basePath: '', + basePath: '.', /* * Frameworks to use @@ -84,7 +84,7 @@ module.exports = function(config) { * possible values: 'dots', 'progress' * available reporters: https://npmjs.org/browse/keyword/karma-reporter */ - reporters: [ 'mocha', 'coverage' ], + reporters: [ 'mocha', 'coverage', 'karma-remap-istanbul' ], // Karma web server port port: 9876, diff --git a/tsconfig.json b/tsconfig.json index 226f3dbe19..6926f8cfff 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "removeComments": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, "allowUnreachableCode": false, "allowUnusedLabels": false, "noEmitHelpers": true, diff --git a/webpack.test.config.js b/webpack.test.config.js index 768ff712cd..cd288ce894 100644 --- a/webpack.test.config.js +++ b/webpack.test.config.js @@ -91,20 +91,23 @@ module.exports = function (options) { */ { test: /\.ts$/, - loaders: ['awesome-typescript-loader', 'angular2-template-loader'], - /*loader: 'awesome-typescript-loader', - query: { - // use inline sourcemaps for "karma-remap-coverage" reporter - sourceMap: false, - inlineSourceMap: true, - compilerOptions: { - - // Remove TypeScript helpers to be injected - // below by DefinePlugin - removeComments: true - - } - },*/ + loaders: [ + { + loader: 'awesome-typescript-loader', + query: { + // use inline sourcemaps for "karma-remap-coverage" reporter + sourceMap: false, + inlineSourceMap: true, + sourceRoot: false, + compilerOptions: { + // Remove TypeScript helpers to be injected + // below by DefinePlugin + removeComments: true + } + } + }, + 'angular2-template-loader' + ], exclude: [/\.e2e\.ts$/] }, From b5357e183685d9b867fbd70db635963ae2b2df52 Mon Sep 17 00:00:00 2001 From: Matteo Perelli Date: Tue, 10 Jan 2017 09:11:11 +0100 Subject: [PATCH 18/20] README.md update --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3cb7861bdc..a4f1f64f85 100644 --- a/README.md +++ b/README.md @@ -102,8 +102,7 @@ To correctly run the tests you need to run the build once with: The default browser is Google Chrome. -Place your tests at the following path: -`./src/tests` +Place your tests in the same location of the application source code files that they test. and run: `npn run test` @@ -111,8 +110,7 @@ and run: ### E2E test E2E tests use Protractor + Selenium server + browsers. You can find the configuration file at the same level of this README file: `./protractor.conf.js` -Protractor must be installed as 'global' so, make sure you have runned: -`npm run global`. +Protractor is installed as 'local' as a dev dependency. If you are going to execute tests locally you need to run (once time only): `npm run webdriver:update`. @@ -182,7 +180,6 @@ dspace-angular │   ├── styles * Folder containing global styles. │   │   ├── main.scss * Global scss file │   │   └── variables.scss * Global sass variables file -│   ├── tests * Folder for unit test files │   └── typings.d.ts * File that allows you to add custom typings for libraries without TypeScript support ├── tsconfig.aot.json * TypeScript config for production builds ├── tsconfig.json * TypeScript config for development build From 144324e0233dc7ae18bdb4d0195702a396ccb340 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Tue, 10 Jan 2017 09:45:29 +0100 Subject: [PATCH 19/20] Dir tests deleted test:watch added webpack library updated protractor installed locally --- karma.conf.js | 4 ++-- package.json | 17 +++++++++-------- spec-bundle.js | 2 +- src/{tests => app}/app.component.spec.ts | 4 ++-- src/tests/.gitkeep | 0 webpack.config.ts | 5 +++++ webpack.test.config.js | 4 ++++ 7 files changed, 23 insertions(+), 13 deletions(-) rename src/{tests => app}/app.component.spec.ts (91%) delete mode 100644 src/tests/.gitkeep diff --git a/karma.conf.js b/karma.conf.js index ccc4f2e193..43ad307a3c 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -99,7 +99,7 @@ module.exports = function(config) { logLevel: config.LOG_INFO, // enable / disable watching file and executing tests whenever any file changes - autoWatch: false, + //autoWatch: true, /* * start these browsers @@ -136,7 +136,7 @@ module.exports = function(config) { * Continuous Integration mode * if true, Karma captures browsers, runs the tests and exits */ - singleRun: true + //singleRun: true }; if (process.env.TRAVIS){ diff --git a/package.json b/package.json index 292e8ccb89..237bc43133 100644 --- a/package.json +++ b/package.json @@ -50,14 +50,14 @@ "debug:build:prod": "node-nightly --inspect --debug-brk node_modules/webpack/bin/webpack.js --config webpack.prod.config.ts", "docs": "typedoc --options typedoc.json ./src", "lint": "tslint \"src/**/*.ts\" || true", - "global": "npm install -g angular-cli nodemon npm-check-updates rimraf ts-node typedoc typescript webpack webpack-bundle-size-analyzer rollup marked node-gyp protractor", - "postglobal": "npm link protractor", - "protractor": "protractor", + "global": "npm install -g angular-cli nodemon npm-check-updates rimraf ts-node typedoc typescript webpack webpack-bundle-size-analyzer rollup marked node-gyp", + "protractor": "node node_modules/protractor/bin/protractor", "e2e": "npm run protractor", - "test": "karma start", + "test": "karma start --single-run", + "test:watch": "karma start --no-single-run --auto-watch", "coverage": "http-server -c-1 -o -p 9875 ./coverage", - "webdriver:start": "webdriver-manager start --seleniumPort 4444", - "webdriver:update": "webdriver-manager update --standalone" + "webdriver:start": "node node_modules/protractor/bin/webdriver-manager start --seleniumPort 4444", + "webdriver:update": "node node_modules/protractor/bin/webdriver-manager update --standalone" }, "dependencies": { "@angular/common": "2.2.3", @@ -140,6 +140,7 @@ "karma-webpack": "1.8.0", "node-sass": "4.0.0", "nodemon": "1.11.0", + "protractor": "~4.0.14", "protractor-istanbul-plugin": "~2.0.0", "raw-loader": "0.5.1", "reflect-metadata": "0.1.8", @@ -159,10 +160,10 @@ "typedoc": "0.5.1", "typescript": "2.0.10", "v8-lazy-parse-webpack-plugin": "0.3.0", - "webpack": "2.1.0-beta.27", + "webpack": "2.2.0-rc.3", "webpack-bundle-analyzer": "1.4.1", "webpack-dev-middleware": "1.9.0", - "webpack-dev-server": "2.1.0-beta.11", + "webpack-dev-server": "2.2.0-rc.0", "webpack-merge": "1.1.1" } } diff --git a/spec-bundle.js b/spec-bundle.js index 45954f4088..36026d530f 100644 --- a/spec-bundle.js +++ b/spec-bundle.js @@ -47,7 +47,7 @@ testing.TestBed.initTestEnvironment( * any file that ends with spec.ts and get its path. By passing in true * we say do this recursively */ -var testContext = require.context('./src/tests', true, /\.spec\.ts/); +var testContext = require.context('./src', true, /\.spec\.ts/); /* * get all the files, for each file, call the context function diff --git a/src/tests/app.component.spec.ts b/src/app/app.component.spec.ts similarity index 91% rename from src/tests/app.component.spec.ts rename to src/app/app.component.spec.ts index d69b35850d..4f53b0ba93 100644 --- a/src/tests/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -15,8 +15,8 @@ import { Store } from "@ngrx/store"; // Load the implementations that should be tested -import { AppComponent } from '../app/app.component'; -import { HeaderComponent } from '../app/header/header.component'; +import { AppComponent } from './app.component'; +import { HeaderComponent } from './header/header.component'; import { CommonModule } from '@angular/common'; diff --git a/src/tests/.gitkeep b/src/tests/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/webpack.config.ts b/webpack.config.ts index 1d4b927e13..e6128264b1 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -67,6 +67,11 @@ export var commonConfig = { } ], }, + + performance: { + hints: false + }, + plugins: [ // Use commonPlugins. ] diff --git a/webpack.test.config.js b/webpack.test.config.js index cd288ce894..4f3530e8de 100644 --- a/webpack.test.config.js +++ b/webpack.test.config.js @@ -166,6 +166,10 @@ module.exports = function (options) { ] }, + performance: { + hints: false + }, + /** * Add additional plugins to the compiler. * From 9994947ece063fbd2d8f7d106ec4c5d8e8e7018e Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Tue, 10 Jan 2017 17:40:56 +0100 Subject: [PATCH 20/20] roll back to webpack 2.1.0-beta.27 --- package.json | 6 ++++-- webpack.config.ts | 4 ---- webpack.test.config.js | 4 ---- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 237bc43133..44316b310e 100644 --- a/package.json +++ b/package.json @@ -115,6 +115,8 @@ "@types/webfontloader": "1.6.27", "angular2-template-loader": "0.6.0", "autoprefixer": "6.5.4", + "ajv": "4.2.0", + "ajv-keywords": "1.1.1", "awesome-typescript-loader": "2.2.4", "codelyzer": "2.0.0-beta.3", "concurrently": "3.1.0", @@ -160,10 +162,10 @@ "typedoc": "0.5.1", "typescript": "2.0.10", "v8-lazy-parse-webpack-plugin": "0.3.0", - "webpack": "2.2.0-rc.3", + "webpack": "2.1.0-beta.27", "webpack-bundle-analyzer": "1.4.1", "webpack-dev-middleware": "1.9.0", - "webpack-dev-server": "2.2.0-rc.0", + "webpack-dev-server": "2.1.0-beta.11", "webpack-merge": "1.1.1" } } diff --git a/webpack.config.ts b/webpack.config.ts index e6128264b1..065ac1cf6e 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -68,10 +68,6 @@ export var commonConfig = { ], }, - performance: { - hints: false - }, - plugins: [ // Use commonPlugins. ] diff --git a/webpack.test.config.js b/webpack.test.config.js index 4f3530e8de..cd288ce894 100644 --- a/webpack.test.config.js +++ b/webpack.test.config.js @@ -166,10 +166,6 @@ module.exports = function (options) { ] }, - performance: { - hints: false - }, - /** * Add additional plugins to the compiler. *