Update ng cli; Add karma basic test setup without preprocessor

merge-requests/1/head
Florian Hartwich 2017-03-24 06:22:36 +01:00
parent 405fcaa309
commit 1fd4dba7f8
24 changed files with 227 additions and 204 deletions

View File

@ -1,6 +1,6 @@
{ {
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": { "project": {
"version": "1.0.0-beta.26",
"name": "basic-cli" "name": "basic-cli"
}, },
"apps": [ "apps": [
@ -13,16 +13,17 @@
], ],
"index": "index.html", "index": "index.html",
"main": "main.ts", "main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts", "test": "test.ts",
"tsconfig": "tsconfig.json", "tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app", "prefix": "app",
"mobile": false,
"styles": [ "styles": [
"styles.css" "styles.css"
], ],
"scripts": [], "scripts": [],
"environmentSource": "environments/environment.ts",
"environments": { "environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts", "dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts" "prod": "environments/environment.prod.ts"
} }
@ -33,6 +34,17 @@
"config": "./protractor.conf.js" "config": "./protractor.conf.js"
} }
}, },
"lint": [
{
"project": "src/tsconfig.app.json"
},
{
"project": "src/tsconfig.spec.json"
},
{
"project": "e2e/tsconfig.e2e.json"
}
],
"test": { "test": {
"karma": { "karma": {
"config": "./karma.conf.js" "config": "./karma.conf.js"
@ -40,18 +52,6 @@
}, },
"defaults": { "defaults": {
"styleExt": "css", "styleExt": "css",
"prefixInterfaces": false, "component": {}
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
} }
} }

40
basic-cli/.gitignore vendored
View File

@ -1,40 +0,0 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
# dependencies
/node_modules
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# misc
/.sass-cache
/connect.lock
/coverage/*
/libpeerconnection.log
npm-debug.log
testem.log
/typings
# e2e
/e2e/*.js
/e2e/*.map
#System Files
.DS_Store
Thumbs.db

View File

@ -1,8 +1,9 @@
# BasicCli # BasicCli
This project was generated with [angular-cli](https://github.com/angular/angular-cli) version 1.0.0-beta.26. This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.0.0.
## Development server ## Development server
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
## Code scaffolding ## Code scaffolding
@ -22,10 +23,6 @@ Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
Before running the tests make sure you are serving the app via `ng serve`. Before running the tests make sure you are serving the app via `ng serve`.
## Deploying to GitHub Pages
Run `ng github-pages:deploy` to deploy to GitHub Pages.
## Further help ## Further help
To get more help on the `angular-cli` use `ng help` or go check out the [Angular-CLI README](https://github.com/angular/angular-cli/blob/master/README.md). To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).

View File

@ -1,32 +0,0 @@
hardi@linux-pih0:~/bachelor/basic-cli> ng init
installing ng2
create .editorconfig
create README.md
create src/app/app.component.css
create src/app/app.component.html
create src/app/app.component.spec.ts
create src/app/app.component.ts
create src/app/app.module.ts
create src/assets/.gitkeep
create src/environments/environment.prod.ts
create src/environments/environment.ts
create src/favicon.ico
create src/index.html
create src/main.ts
create src/polyfills.ts
create src/styles.css
create src/test.ts
create src/tsconfig.json
create angular-cli.json
create e2e/app.e2e-spec.ts
create e2e/app.po.ts
create e2e/tsconfig.json
create .gitignore
create karma.conf.js
create package.json
create protractor.conf.js
create tslint.json
Directory is already under version control. Skipping initialization of git.
Installing packages for tooling via npm.
Installed packages for tooling via npm.
Project 'basic-cli' successfully created.

View File

@ -1,6 +1,6 @@
import { BasicCliPage } from './app.po'; import { BasicCliPage } from './app.po';
describe('basic-cli App', function() { describe('basic-cli App', () => {
let page: BasicCliPage; let page: BasicCliPage;
beforeEach(() => { beforeEach(() => {

View File

@ -0,0 +1,12 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/e2e",
"module": "commonjs",
"target": "es5",
"types":[
"jasmine",
"node"
]
}
}

View File

@ -4,35 +4,36 @@
module.exports = function (config) { module.exports = function (config) {
config.set({ config.set({
basePath: '', basePath: '',
frameworks: ['jasmine', 'angular-cli'], frameworks: ['jasmine', '@angular/cli'],
plugins: [ plugins: [
require('karma-jasmine'), require('karma-jasmine'),
require('karma-chrome-launcher'), require('karma-chrome-launcher'),
require('karma-remap-istanbul'), require('karma-jasmine-html-reporter'),
require('angular-cli/plugins/karma') require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma')
], ],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
files: [ files: [
{ pattern: './src/test.ts', watched: false } { pattern: './src/test.ts', watched: false }
], ],
preprocessors: { preprocessors: {
'./src/test.ts': ['angular-cli'] './src/test.ts': ['@angular/cli']
}, },
mime: { mime: {
'text/x-typescript': ['ts','tsx'] 'text/x-typescript': ['ts','tsx']
}, },
remapIstanbulReporter: { coverageIstanbulReporter: {
reports: { reports: [ 'html', 'lcovonly' ],
html: 'coverage', fixWebpackSourcePaths: true
lcovonly: './coverage/coverage.lcov'
}
}, },
angularCli: { angularCli: {
config: './angular-cli.json',
environment: 'dev' environment: 'dev'
}, },
reporters: config.angularCli && config.angularCli.codeCoverage reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'karma-remap-istanbul'] ? ['progress', 'coverage-istanbul']
: ['progress'], : ['progress', 'kjhtml'],
port: 9876, port: 9876,
colors: true, colors: true,
logLevel: config.LOG_INFO, logLevel: config.LOG_INFO,

View File

@ -2,46 +2,45 @@
"name": "basic-cli", "name": "basic-cli",
"version": "0.0.0", "version": "0.0.0",
"license": "MIT", "license": "MIT",
"angular-cli": {},
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"start": "ng serve", "start": "ng serve",
"lint": "tslint \"src/**/*.ts\" --project src/tsconfig.json --type-check && tslint \"e2e/**/*.ts\" --project e2e/tsconfig.json --type-check", "build": "ng build",
"test": "ng test", "test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false", "lint": "ng lint",
"e2e": "protractor" "e2e": "ng e2e"
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {
"@angular/common": "^2.3.1", "@angular/common": "^4.0.0",
"@angular/compiler": "^2.3.1", "@angular/compiler": "^4.0.0",
"@angular/core": "^2.3.1", "@angular/core": "^4.0.0",
"@angular/forms": "^2.3.1", "@angular/forms": "^4.0.0",
"@angular/http": "^2.3.1", "@angular/http": "^4.0.0",
"@angular/platform-browser": "^2.3.1", "@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^2.3.1", "@angular/platform-browser-dynamic": "^4.0.0",
"@angular/router": "^3.3.1", "@angular/router": "^4.0.0",
"core-js": "^2.4.1", "core-js": "^2.4.1",
"rxjs": "^5.0.1", "rxjs": "^5.1.0",
"ts-helpers": "^1.1.1", "zone.js": "^0.8.4"
"zone.js": "^0.7.2"
}, },
"devDependencies": { "devDependencies": {
"@angular/compiler-cli": "^2.3.1", "@angular/cli": "1.0.0",
"@angular/compiler-cli": "^4.0.0",
"@types/jasmine": "2.5.38", "@types/jasmine": "2.5.38",
"@types/node": "^6.0.42", "@types/node": "~6.0.60",
"angular-cli": "1.0.0-beta.26", "codelyzer": "~2.0.0",
"codelyzer": "~2.0.0-beta.1", "jasmine-core": "~2.5.2",
"jasmine-core": "2.5.2", "jasmine-spec-reporter": "~3.2.0",
"jasmine-spec-reporter": "2.5.0", "karma": "~1.4.1",
"karma": "1.2.0", "karma-chrome-launcher": "~2.0.0",
"karma-chrome-launcher": "^2.0.0", "karma-cli": "~1.0.1",
"karma-cli": "^1.0.1", "karma-jasmine": "~1.1.0",
"karma-jasmine": "^1.0.2", "karma-jasmine-html-reporter": "^0.2.2",
"karma-remap-istanbul": "^0.2.1", "karma-coverage-istanbul-reporter": "^0.2.0",
"protractor": "~4.0.13", "protractor": "~5.1.0",
"ts-node": "1.2.1", "ts-node": "~2.0.0",
"tslint": "^4.3.0", "tslint": "~4.5.0",
"typescript": "~2.0.3" "typescript": "~2.2.0"
} }
} }

View File

@ -1,8 +1,7 @@
// Protractor configuration file, see link for more information // Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts // https://github.com/angular/protractor/blob/master/lib/config.ts
/*global jasmine */ const { SpecReporter } = require('jasmine-spec-reporter');
var SpecReporter = require('jasmine-spec-reporter');
exports.config = { exports.config = {
allScriptsTimeout: 11000, allScriptsTimeout: 11000,
@ -20,13 +19,12 @@ exports.config = {
defaultTimeoutInterval: 30000, defaultTimeoutInterval: 30000,
print: function() {} print: function() {}
}, },
useAllAngular2AppRoots: true,
beforeLaunch: function() { beforeLaunch: function() {
require('ts-node').register({ require('ts-node').register({
project: 'e2e' project: 'e2e/tsconfig.e2e.json'
}); });
}, },
onPrepare: function() { onPrepare() {
jasmine.getEnv().addReporter(new SpecReporter()); jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
} }
}; };

View File

@ -1,17 +1,15 @@
/* tslint:disable:no-unused-variable */
import { TestBed, async } from '@angular/core/testing'; import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
describe('AppComponent', () => { describe('AppComponent', () => {
beforeEach(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ declarations: [
AppComponent AppComponent
], ],
}); }).compileComponents();
TestBed.compileComponents(); }));
});
it('should create the app', async(() => { it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent); const fixture = TestBed.createComponent(AppComponent);

View File

@ -1,7 +1,7 @@
// The file contents for the current environment will overwrite these during build. // The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do // The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead. // `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `angular-cli.json`. // The list of which env maps to which file can be found in `.angular-cli.json`.
export const environment = { export const environment = {
production: false production: false

View File

@ -1,9 +1,8 @@
import './polyfills.ts';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core'; import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module'; import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) { if (environment.production) {
enableProdMode(); enableProdMode();

View File

@ -1,19 +1,68 @@
// This file includes polyfills needed by Angular and is loaded before /**
// the app. You can add your own extra polyfills to this file. * This file includes polyfills needed by Angular and is loaded before the app.
import 'core-js/es6/symbol'; * You can add your own extra polyfills to this file.
import 'core-js/es6/object'; *
import 'core-js/es6/function'; * This file is divided into 2 sections:
import 'core-js/es6/parse-int'; * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
import 'core-js/es6/parse-float'; * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
import 'core-js/es6/number'; * file.
import 'core-js/es6/math'; *
import 'core-js/es6/string'; * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
import 'core-js/es6/date'; * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
import 'core-js/es6/array'; * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
import 'core-js/es6/regexp'; *
import 'core-js/es6/map'; * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
import 'core-js/es6/set'; */
import 'core-js/es6/reflect';
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
// import 'core-js/es6/symbol';
// import 'core-js/es6/object';
// import 'core-js/es6/function';
// import 'core-js/es6/parse-int';
// import 'core-js/es6/parse-float';
// import 'core-js/es6/number';
// import 'core-js/es6/math';
// import 'core-js/es6/string';
// import 'core-js/es6/date';
// import 'core-js/es6/array';
// import 'core-js/es6/regexp';
// import 'core-js/es6/map';
// import 'core-js/es6/set';
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.
/** IE10 and IE11 requires the following to support `@angular/animation`. */
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/** Evergreen browsers require these. **/
import 'core-js/es6/reflect';
import 'core-js/es7/reflect'; import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
/** ALL Firefox browsers require the following to support `@angular/animation`. **/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/***************************************************************************************************
* Zone JS is required by Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/
/**
* Date, currency, decimal and percent pipes.
* Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
*/
// import 'intl'; // Run `npm install --save intl`.

View File

@ -1,7 +1,5 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files // This file is required by karma.conf.js and loads recursively all the .spec and framework files
import './polyfills.ts';
import 'zone.js/dist/long-stack-trace-zone'; import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js'; import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test'; import 'zone.js/dist/sync-test';

View File

@ -0,0 +1,13 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"baseUrl": "",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}

View File

@ -1,18 +0,0 @@
{
"compilerOptions": {
"baseUrl": "",
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"mapRoot": "./",
"module": "es6",
"moduleResolution": "node",
"outDir": "../dist/out-tsc",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/@types"
]
}
}

View File

@ -0,0 +1,20 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/spec",
"module": "commonjs",
"target": "es5",
"baseUrl": "",
"types": [
"jasmine",
"node"
]
},
"files": [
"test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}

5
basic-cli/src/typings.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
/* SystemJS module definition */
declare var module: NodeModule;
interface NodeModule {
id: string;
}

View File

@ -1,16 +1,20 @@
{ {
"compileOnSave": false, "compileOnSave": false,
"compilerOptions": { "compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false, "declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
"outDir": "../dist/out-tsc-e2e",
"sourceMap": true,
"target": "es5", "target": "es5",
"typeRoots": [ "typeRoots": [
"../node_modules/@types" "node_modules/@types"
],
"lib": [
"es2016",
"dom"
] ]
} }
} }

View File

@ -46,7 +46,7 @@
"no-empty": false, "no-empty": false,
"no-empty-interface": true, "no-empty-interface": true,
"no-eval": true, "no-eval": true,
"no-inferrable-types": true, "no-inferrable-types": [true, "ignore-params"],
"no-shadowed-variable": true, "no-shadowed-variable": true,
"no-string-literal": false, "no-string-literal": false,
"no-string-throw": true, "no-string-throw": true,

View File

@ -29,8 +29,8 @@
"../node_modules/jquery-ui-bundle/jquery-ui.js", "../node_modules/jquery-ui-bundle/jquery-ui.js",
"../node_modules/bootstrap/dist/js/bootstrap.min.js" "../node_modules/bootstrap/dist/js/bootstrap.min.js"
], ],
"environmentSource": "environments/environment.ts",
"environments": { "environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts", "dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts", "prod": "environments/environment.prod.ts",
"e2e": "environments/environment.e2e.ts" "e2e": "environments/environment.e2e.ts"
@ -44,6 +44,11 @@
"config": "./protractor.conf.js" "config": "./protractor.conf.js"
} }
}, },
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": { "defaults": {
"styleExt": "css", "styleExt": "css",
"prefixInterfaces": false, "prefixInterfaces": false,

View File

@ -1,5 +1,5 @@
// Karma configuration // Karma configuration
// Generated on Thu Mar 23 2017 04:57:32 GMT+0100 (CET) // Generated on Thu Mar 2 2017 04:57:32 GMT+0100 (CET)
module.exports = function(config) { module.exports = function(config) {
config.set({ config.set({
@ -15,7 +15,7 @@ module.exports = function(config) {
// list of files / patterns to load in the browser // list of files / patterns to load in the browser
files: [ files: [
{ pattern: 'src/**/test.ts' } { pattern: 'src/**/*.spec.ts' }
], ],
@ -31,7 +31,6 @@ module.exports = function(config) {
], ],
// preprocess matching files before serving them to the browser // preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: { preprocessors: {
@ -41,7 +40,7 @@ module.exports = function(config) {
// test results reporter to use // test results reporter to use
// possible values: 'dots', 'progress' // possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter // available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'], reporters: ['spec'],
// web server port // web server port

View File

@ -37,15 +37,18 @@
"zone.js": "^0.7.2" "zone.js": "^0.7.2"
}, },
"devDependencies": { "devDependencies": {
"@angular/cli": "^1.0.0",
"@angular/compiler-cli": "^2.4.3", "@angular/compiler-cli": "^2.4.3",
"@types/jasmine": "2.5.38", "@types/jasmine": "2.5.38",
"@types/node": "^6.0.42", "@types/node": "^6.0.42",
"@types/socket.io-client": "^1.4.26", "@types/socket.io-client": "^1.4.26",
"angular-cli": "1.0.0-beta.25.5",
"codelyzer": "~2.0.0-beta.1", "codelyzer": "~2.0.0-beta.1",
"concurrently": "^2.0.0", "concurrently": "^2.0.0",
"jasmine": "^2.5.3", "jasmine": "^2.5.3",
"karma": "^1.5.0", "karma": "^1.5.0",
"karma-chrome-launcher": "^2.0.0",
"karma-jasmine": "^1.1.0",
"karma-spec-reporter": "0.0.30",
"ts-node": "1.2.1", "ts-node": "1.2.1",
"tslint": "^4.3.0", "tslint": "^4.3.0",
"typescript": "~2.0.3" "typescript": "~2.0.3"

View File

@ -0,0 +1,13 @@
describe("Blog Component", () => {
it("should succeed on basic logic check", () => {
expect(1+1).toEqual(2);
expect(true).toBe(true)
})
it("should fail on basic logic check error", () => {
expect(1+1).toEqual(2);
expect(true).toBe(false)
})
})