зеркало из
1
0
Форкнуть 0

feat: setup Kendo UI for Angular preset

This commit is contained in:
Tsvetomir Tsonev 2017-11-29 09:04:28 +02:00
Родитель 9183e21f54
Коммит 56b21b6ee8
50 изменённых файлов: 13 добавлений и 10380 удалений

Просмотреть файл

@ -1,52 +0,0 @@
## Changelog (master)
### v4.0.0
* Breaking: Drop Node 4 support (because of `jsdom` upgrade)
* Feature: Custom test environment with newest version of `jsdom` ([#75](https://github.com/thymikee/jest-preset-angular/pull/75))
* Feature: Use universal `zone.js` instead of node-specific one ([#76](https://github.com/thymikee/jest-preset-angular/pull/76))
* Fix: `fakeAsync` not working with `zone.js` >= 0.8.11
### v3.0.1
* Breaking: Upgrade jest to 21
* Breaking: Upgrade ts-jest to 21
* Breaking: `moduleNameMapper` no longer maps absolute paths to `src` by default, you need to declare the mappings explicitly ([#53](https://github.com/thymikee/jest-preset-angular/pull/53))
* Fix: issues with `moduleNameMapper` not overriding mappings ([#53](https://github.com/thymikee/jest-preset-angular/pull/53))
### v2.0.5
* Fix: Bump to ts-jest 20.0.7
### v2.0.2
* Fix: Angular injection errors are now visible
* Fix: Escape template literals special chars ([#34](https://github.com/thymikee/jest-preset-angular/pull/34))
### v2.0.0
* Breaking: Upgrade to Jest 20
* Breaking: Better snapshot rendering
### v1.2.0
* Feature: Support absolute URLs in `templateUrl`
### v1.1.0
* Feature: Support snapshot testing ([#24](https://github.com/thymikee/jest-preset-angular/pull/24))
### v1.0.0
* Breaking change: `rxjs` is no longer auto included ([#18](https://github.com/thymikee/jest-preset-angular/pull/18))
### v0.1.0
* Fix: Coverage support ([#15](https://github.com/thymikee/jest-preset-angular/pull/15))
* Adjustment: Add `json` as a valid module extension ([#16](https://github.com/thymikee/jest-preset-angular/pull/16))
### v0.0.14
* Fix: Bump `jest-zone-patch` version with `zone.js` peer dependency
### v0.0.13
* Fix: Overhaul regex for styleUrls ([#10](https://github.com/thymikee/jest-preset-angular/pull/10))
### v0.0.10
* Fix: Improve global mocks
### v0.0.9
* Feature: Allow all folders within src for module resolution ([#6](https://github.com/thymikee/jest-preset-angular/pull/6))
### v0.0.8
* Fix: use `tsconfig.spec.json` instead of `tsconfig.app.json` as TS configuration for tests

225
README.md
Просмотреть файл

@ -1,224 +1,5 @@
# jest-preset-angular
[![CircleCI Build Status](https://circleci.com/gh/thymikee/jest-preset-angular.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/thymikee/jest-preset-angular)
[![NPM version](https://img.shields.io/npm/v/jest-preset-angular.svg)](https://www.npmjs.com/package/jest-preset-angular)
# Kendo UI for Angular - Jest Preset
A preset of [Jest](http://facebook.github.io/jest) configuration used by [Kendo UI for Angular](https://www.telerik.com/kendo-angular-ui/).
A preset of [Jest](http://facebook.github.io/jest) configuration for [Angular](https://angular.io/) projects.
Based on [jest-preset-angular](https://github.com/thymikee/jest-preset-angular) by Michał Pierzchała.
This is a part of the article: [Testing Angular faster with Jest](https://www.xfive.co/blog/testing-angular-faster-jest/).
*Note: This preset does not suport AngularJS (1.x). If you want to set up Jest with AngularJS, please see [this blog post](https://medium.com/aya-experience/testing-an-angularjs-app-with-jest-3029a613251).*
## Installation
```bash
yarn add --dev jest jest-preset-angular @types/jest
```
## Usage
In `src` directory create `setupJest.ts` file with following contents:
```js
import 'jest-preset-angular';
import './jestGlobalMocks'; // browser mocks globally available for every test
```
...and include this in your `package.json`:
```json
{
"jest": {
"preset": "jest-preset-angular",
"setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts"
}
}
```
## Exposed [configuration](https://github.com/thymikee/jest-preset-angular/blob/master/jest-preset.json)
```json
{
"globals": {
"ts-jest": {
"tsConfigFile": "src/tsconfig.spec.json"
},
"__TRANSFORM_HTML__": true
},
"transform": {
"^.+\\.(ts|js|html)$": "<rootDir>/node_modules/jest-preset-angular/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|js)$",
"moduleFileExtensions": [
"ts",
"js",
"html"
],
"moduleNameMapper": {
"app/(.*)": "<rootDir>/src/app/$1",
"assets/(.*)": "<rootDir>/src/assets/$1",
"environments/(.*)": "<rootDir>/src/environments/$1"
},
"transformIgnorePatterns": [
"node_modules/(?!@ngrx)"
]
}
```
### Brief explanation of config
* `<rootDir>` is a special syntax for root of your project (here by default it's project's root /)
* we're using some `"globals"` to pass information about where our tsconfig.json file is that we'd like to be able to transform HTML files through ts-jest
* `"transform"` – run every TS, JS, or HTML file through so called *preprocessor* (we'll get there); this lets Jest understand non-JS syntax
* `"testRegex"` – we want to run Jest on files that matches this regex
* `"moduleFileExtensions"` – our modules are TypeScript and JavaScript files
* `"moduleNameMapper"` – if you're using absolute imports here's how to tell Jest where to look for them; uses regex
* `"setupTestFrameworkScriptFile"` – this is the heart of our config, in this file we'll setup and patch environment within tests are running
* `"transformIgnorePatterns"` – unfortunately some modules (like @ngrx ) are released as TypeScript files, not pure JavaScript; in such cases we cannot ignore them (all node_modules are ignored by default), so they can be transformed through TS compiler like any other module in our project.
## [Preprocessor](https://github.com/thymikee/jest-preset-angular/blob/master/preprocessor.js)
Jest doesn't run in browser nor through dev server. It uses jsdom to abstract browser environment. So we have to cheat a little and inline our templates and get rid of styles (we're not testing CSS) because otherwise Angular will try to make XHR call for our templates and fail miserably.
I used a scrappy regex to accomplish this with minimum effort, but you can also write a babel plugin to make it bulletproof. And btw, don't bother about perf here – Jest heavily caches transforms. That's why you need to run Jest with `--no-cache` flag every time you change it.
## Angular testing environment setup
If you look at your `src/test.ts` (or similar bootstrapping test file) file you'll see similarities to [`setupJest.js`](https://github.com/thymikee/jest-preset-angular/blob/master/setupJest.js). What we're doing here is we're adding globals required by Angular. With [jest-zone-patch](https://github.com/thymikee/jest-zone-patch) we also make sure Jest test methods run in Zone context. Then we initialize the Angular testing environment like normal.
## Snapshot testing
**Since version 1.1.0** it's possible to [snapshot test](http://facebook.github.io/jest/docs/snapshot-testing.html#snapshot-testing-with-jest) your Angular components. Please note it's still under active development and may be a subject of change. You can lookup [example](/example/src/app) for details
Example:
`calc-component.spec.ts`
```js
// some initialization code
test('renders markup to snapshot', () => {
const fixture = TestBed.createComponent(AppComponent);
expect(fixture).toMatchSnapshot();
});
```
`__snapshots__/calc-component.spec.ts.snap`
```js
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`CalcComponent should snap 1`] = `
<app-calc
prop1={[Function Number]}
>
<p
class="a-default-class"
ng-reflect-klass="a-default-class"
ng-reflect-ng-class="[object Object]"
>
calc works!
</p>
</app-calc>
`;
```
## Troubleshooting
Problems may arise if you're using custom builds (this preset is tailored for `angular-cli` as firsty priority). Please be adivsed that every entry in default configuration may be overriden to best suite your app's needs.
### Absolute imports
TypeScript supports absolute imports. The preset (starting from v3.0.0) by default understands absolute imports referring to `src`, `app`, `assets` and `environments` directory, so instead:
```js
import MyComponent from '../../src/app/my.component';
import MyStuff from '../../src/testing/my.stuff';
```
you can use:
```js
import MyComponent from 'app/my.component';
import MyStuff from 'src/testing/my.stuff';
```
However, if your directory structure differ from that provided by `angular-cli` you can adjust `moduleNameMapper` in Jest config:
```js
{
"jest": {
"moduleNameMapper": {
"app/(.*)": "<rootDir>/src/to/app/$1", // override default, why not
"testing/(.*)": "<rootDir>/app/testing/$1" // add new mapping
}
}
}
```
### Custom tsconfig
Override `globals` object in Jest config:
```json
{
"jest": {
"globals": {
"ts-jest": {
"tsConfigFile": "src/tsconfig.custom.json"
},
"__TRANSFORM_HTML__": true
}
}
}
```
If you choose to overide `globals` in order to point at a specific tsconfig, you will need to add `"__TRANSFORM_HTML__": true` to the `globals` section too, otherwise you will get parse errors on any html templates.
### Unexpected token [import|export|other]
This means, that a file is not transformed through TypeScript compiler, e.g. because it is a JS file with TS syntax, or it is published to npm as uncompiled source files. Here's what you can do.
#### Adjust your `transformIgnorePatterns` whitelist:
```js
{
"jest": {
"transformIgnorePatterns": [
"node_modules/(?!@ngrx|angular2-ui-switch|ng-dynamic)"
]
}
}
```
By default Jest doesn't transform `node_modules`, because they should be valid JavaScript files. However, it happens that library authors assume that you'll compile their sources. So you have to tell this to Jest explicitly. Above snippet means that `@ngrx`, `angular2-ui-switch` and `ng-dynamic` will be transforemed, even though they're `node_modules`.
#### Allow JS files in your TS `compilerOptions`
```json
{
"compilerOptions": {
"allowJs": true
}
}
```
This tells `ts-jest` (a preprocessor this preset using to transform TS files) to treat JS files the same as TS ones.
#### Transpile js files through `babel-jest`
Some vendors publish their sources without transpiling. You need to say jest to transpile such files manually since `typescript` (and thus `ts-jest` used by this preset) do not transpile them.
1. Install `babel-preset-env` and add `.babelrc` (or modify existing if needed) with that contents:
```
{
"presets": ["env"]
}
```
2. Update Jest configuration (by default TypeScript process untranspiled JS files which is source of the problem):
```js
{
"jest": {
"transform": {
"^.+\\.(ts|html)$": "<rootDir>/node_modules/jest-preset-angular/preprocessor.js",
"^.+\\.js$": "babel-jest"
},
}
}
```
### Observable ... is not a function
Since v1.0 this preset doesn't import whole `rxjs` library by default for variety of reasons. This may result in breaking your tests that relied on this behavior. It may however become cumbersome to include e.g. `rxjs/add/operator/map` or `rxjs/add/operator/do` for every test, so as a workaround you can include common operators or other necessary imports in your `setupJest.ts` file:
```js
import 'jest-preset-angular';
// common rxjs imports
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/catch';
// ...
import './jestGlobalMocks';
```

Просмотреть файл

@ -1,23 +0,0 @@
machine:
environment:
YARN_VERSION: 0.22.0
PATH: "${PATH}:${HOME}/.yarn/bin:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"
node:
version: 7
dependencies:
pre:
- |
if [[ ! -e ~/.yarn/bin/yarn || $(yarn --version) != "${YARN_VERSION}" ]]; then
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version $YARN_VERSION
fi
cache_directories:
- ~/.yarn
- ~/.cache/yarn
override:
- yarn install --no-progress
- cd example && yarn install --no-progress
test:
override:
- yarn run test:ci
- yarn link && cd example && yarn link jest-preset-angular && yarn run test:ci && yarn run test:coverage

Просмотреть файл

@ -1,57 +0,0 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "example"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json"
},
{
"project": "src/tsconfig.spec.json"
},
{
"project": "e2e/tsconfig.e2e.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}

Просмотреть файл

@ -1,13 +0,0 @@
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false

42
example/.gitignore поставляемый
Просмотреть файл

@ -1,42 +0,0 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
/out-tsc
# dependencies
/node_modules
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# 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

Просмотреть файл

@ -1,28 +0,0 @@
# Example
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.0.0.
## 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.
## Code scaffolding
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive/pipe/service/class/module`.
## Build
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.
## Running unit tests
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
## Running end-to-end tests
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`.
## 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).

Просмотреть файл

@ -1 +0,0 @@
module.exports = 'test-image-stub';

Просмотреть файл

@ -1,14 +0,0 @@
import { ExamplePage } from './app.po';
describe('example App', () => {
let page: ExamplePage;
beforeEach(() => {
page = new ExamplePage();
});
it('should display message saying app works', () => {
page.navigateTo();
expect(page.getParagraphText()).toEqual('app works!');
});
});

Просмотреть файл

@ -1,11 +0,0 @@
import { browser, element, by } from 'protractor';
export class ExamplePage {
navigateTo() {
return browser.get('/');
}
getParagraphText() {
return element(by.css('app-root h1')).getText();
}
}

Просмотреть файл

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

Просмотреть файл

@ -1,44 +0,0 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
files: [
{ pattern: './src/test.ts', watched: false }
],
preprocessors: {
'./src/test.ts': ['@angular/cli']
},
mime: {
'text/x-typescript': ['ts','tsx']
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};

Просмотреть файл

@ -1,59 +0,0 @@
{
"name": "example",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "jest",
"test:watch": "jest --watch",
"test:ci": "jest --runInBand",
"test:coverage": "jest --coverage",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^4.1.0",
"@angular/common": "^4.1.0",
"@angular/compiler": "^4.1.0",
"@angular/core": "^4.1.0",
"@angular/forms": "^4.1.0",
"@angular/http": "^4.1.0",
"@angular/platform-browser": "^4.1.0",
"@angular/platform-browser-dynamic": "^4.1.0",
"@angular/router": "^4.1.0",
"core-js": "^2.4.1",
"rxjs": "^5.1.0",
"zone.js": "^0.8.18"
},
"devDependencies": {
"@angular/cli": "1.0.0",
"@angular/compiler-cli": "^4.1.0",
"@types/jest": "^19.2.2",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"jest": "^21.0.1",
"jest-preset-angular": "^3.0.1",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^0.2.0",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "~2.3.0"
},
"jest": {
"preset": "jest-preset-angular",
"setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts",
"moduleNameMapper": {
"\\.(jpg|jpeg|png)$": "<rootDir>/__mocks__/image.js"
}
}
}

Просмотреть файл

@ -1,30 +0,0 @@
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { 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() {}
},
beforeLaunch: function() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
},
onPrepare() {
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};

Просмотреть файл

@ -1,31 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`AppComponent snaps 1`] = `
<app-root
hasClass={[Function Boolean]}
title={[Function String]}
variableWithPrecedingDolar={[Function Number]}
>
<h1>
app works!
<app-calc />
<span>
aaa $1234
</span>
<span>
ddd
</span>
\`test'chars""
</h1>
</app-root>
`;

Просмотреть файл

Просмотреть файл

@ -1,7 +0,0 @@
<h1>
{{title}}
<app-calc [hasAClass]="hasClass"></app-calc>
<span>aaa ${{variableWithPrecedingDolar}}</span>
<span *ngIf="hasClass">ddd</span>
`test'chars""
</h1>

Просмотреть файл

@ -1,63 +0,0 @@
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {TestBed, async, fakeAsync, tick} from '@angular/core/testing';
import {NO_ERRORS_SCHEMA} from '@angular/core';
import {AppComponent} from './app.component';
describe('AppComponent', () => {
let fixture;
beforeEach(
async(() => {
TestBed.configureTestingModule({
declarations: [AppComponent],
imports: [NoopAnimationsModule],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
});
it(
'should create the app',
async(() => {
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
})
);
it('snaps', () => {
expect(fixture).toMatchSnapshot();
});
it(
`should have as title 'app works!'`,
async(() => {
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app works!');
})
);
it(
'should render title in a h1 tag',
async(() => {
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('app works!');
})
);
it('looks async but is synchronous', <any>fakeAsync((): void => {
let flag = false;
setTimeout(() => {
flag = true;
}, 100);
expect(flag).toBe(false);
tick(50);
expect(flag).toBe(false);
tick(50);
expect(flag).toBe(true);
}));
});

Просмотреть файл

@ -1,28 +0,0 @@
import { Component, HostBinding } from '@angular/core';
import {trigger, transition, style, animate} from '@angular/animations';
@Component({
selector: 'app-root',
animations: [slideToLeft()],
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
@HostBinding('@routerTransition')
title = 'app works!';
hasClass = true;
variableWithPrecedingDolar = 1234;
}
function slideToLeft() {
return trigger('routerTransition', [
transition(':enter', [
style({transform: 'translateX(200%)', position: 'fixed', width: '100%'}),
animate('0.5s ease-in-out', style({transform: 'translateX(0%)'}))
]),
transition(':leave', [
style({transform: 'translateX(0%)', position: 'fixed', width: '100%'}),
animate('0.5s ease-in-out', style({transform: 'translateX(-200%)'}))
])
])
}

Просмотреть файл

@ -1,25 +0,0 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { CalcComponent } from './calc/calc.component';
import { SimpleComponent } from './simple/simple.component';
@NgModule({
declarations: [
AppComponent,
CalcComponent,
SimpleComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

Просмотреть файл

@ -1,24 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`CalcComponent should snap 1`] = `
<app-calc
hasAClass="false"
image={[Function String]}
prop1={[Function Number]}
>
<p
class="a-default-class"
ng-reflect-klass="a-default-class"
ng-reflect-ng-class="[object Object]"
>
calc works!
1337
another text node
test-image-stub
</p>
</app-calc>
`;

Просмотреть файл

Просмотреть файл

@ -1,24 +0,0 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CalcComponent } from 'app/calc/calc.component';
describe('CalcComponent', () => {
let component: CalcComponent;
let fixture: ComponentFixture<CalcComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [CalcComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CalcComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should snap', () => {
expect(fixture).toMatchSnapshot();
});
});

Просмотреть файл

@ -1,40 +0,0 @@
import { Component, OnInit, Input } from '@angular/core';
import { Observable } from 'rxjs/Observable';
const image = require('assets/its_something.png');
@Component({
selector: 'app-calc',
template: `
<p
class="a-default-class"
[ngClass]="{
'a-class': hasAClass
}"
>
calc works!
{{prop1}}
another text node
{{image}}
</p>
`,
styleUrls: ['./calc.component.css']
})
export class CalcComponent implements OnInit {
@Input() hasAClass = false;
prop1: number;
image: string;
observable$: Observable<string>;
constructor() {
this.init();
this.prop1 = 1337;
this.image = image;
}
ngOnInit() {
}
init() {
return 'Imma method';
}
}

Просмотреть файл

@ -1,12 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`SimpleComponent snapshots 1`] = `
<app-simple>
<p>
simple works!
</p>
</app-simple>
`;

Просмотреть файл

Просмотреть файл

@ -1,3 +0,0 @@
<p>
simple works!
</p>

Просмотреть файл

@ -1,29 +0,0 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { SimpleComponent } from './simple.component';
describe('SimpleComponent', () => {
let component: SimpleComponent;
let fixture: ComponentFixture<SimpleComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SimpleComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SimpleComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('snapshots', () => {
expect(fixture).toMatchSnapshot();
})
});

Просмотреть файл

@ -1,15 +0,0 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-simple',
templateUrl: 'simple.component.html',
styleUrls: ['./simple.component.css']
})
export class SimpleComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}

Просмотреть файл

Двоичные данные
example/src/assets/its_something.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 5.5 KiB

Просмотреть файл

@ -1,3 +0,0 @@
export const environment = {
production: true
};

Просмотреть файл

@ -1,8 +0,0 @@
// 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
// `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`.
export const environment = {
production: false
};

Двоичные данные
example/src/favicon.ico

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 5.3 KiB

Просмотреть файл

@ -1,14 +0,0 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Example</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root>Loading...</app-root>
</body>
</html>

Просмотреть файл

@ -1,23 +0,0 @@
const mock = () => {
let storage = {};
return {
getItem: key => key in storage ? storage[key] : null,
setItem: (key, value) => storage[key] = value || '',
removeItem: key => delete storage[key],
clear: () => storage = {},
};
};
Object.defineProperty(window, 'localStorage', {value: mock()});
Object.defineProperty(window, 'sessionStorage', {value: mock()});
Object.defineProperty(document, 'doctype', {
value: '<!DOCTYPE html>'
});
Object.defineProperty(window, 'getComputedStyle', {
value: () => {
return {
display: 'none',
appearance: ['-webkit-appearance']
};
}
});

Просмотреть файл

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

Просмотреть файл

@ -1,68 +0,0 @@
/**
* 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 is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
*/
/***************************************************************************************************
* 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';
/** 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`.

Просмотреть файл

@ -1,2 +0,0 @@
import 'jest-preset-angular';
import './jestGlobalMocks';

Просмотреть файл

@ -1 +0,0 @@
/* You can add global styles to this file, and also import other style files */

Просмотреть файл

@ -1,32 +0,0 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
declare var __karma__: any;
declare var require: any;
// Prevent Karma from running prematurely.
__karma__.loaded = function () {};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
// Finally, start Karma to run the tests.
__karma__.start();

Просмотреть файл

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

Просмотреть файл

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

5
example/src/typings.d.ts поставляемый
Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -1,116 +0,0 @@
{
"rulesDirectory": [
"node_modules/codelyzer"
],
"rules": {
"callable-types": true,
"class-name": true,
"comment-format": [
true,
"check-space"
],
"curly": true,
"eofline": true,
"forin": true,
"import-blacklist": [true, "rxjs"],
"import-spacing": true,
"indent": [
true,
"spaces"
],
"interface-over-type-literal": true,
"label-position": true,
"max-line-length": [
true,
140
],
"member-access": false,
"member-ordering": [
true,
"static-before-instance",
"variables-before-functions"
],
"no-arg": true,
"no-bitwise": true,
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-construct": true,
"no-debugger": true,
"no-duplicate-variable": true,
"no-empty": false,
"no-empty-interface": true,
"no-eval": true,
"no-inferrable-types": [true, "ignore-params"],
"no-shadowed-variable": true,
"no-string-literal": false,
"no-string-throw": true,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-var-keyword": true,
"object-literal-sort-keys": false,
"one-line": [
true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"prefer-const": true,
"quotemark": [
true,
"single"
],
"radix": true,
"semicolon": [
"always"
],
"triple-equals": [
true,
"allow-null-check"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"typeof-compare": true,
"unified-signatures": true,
"variable-name": false,
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
],
"directive-selector": [true, "attribute", "app", "camelCase"],
"component-selector": [true, "element", "app", "kebab-case"],
"use-input-property-decorator": true,
"use-output-property-decorator": true,
"use-host-property-decorator": true,
"no-input-rename": true,
"no-output-rename": true,
"use-life-cycle-interface": true,
"use-pipe-transform-interface": true,
"component-class-suffix": true,
"directive-class-suffix": true,
"no-access-missing-member": true,
"templates-use-public": true,
"invoke-injectable": true
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,14 +1,15 @@
{
"globals": {
"ts-jest": {
"tsConfigFile": "src/tsconfig.spec.json"
"tsConfigFile": "./test/tsconfig.json"
},
"__TRANSFORM_HTML__": true
},
"setupTestFrameworkScriptFile": "./test/_jest/setup.ts",
"transform": {
"^.+\\.(ts|js|html)$": "<rootDir>/node_modules/jest-preset-angular/preprocessor.js"
"^.+\\.(ts|js|html)$": "<rootDir>/node_modules/jest-preset-kendo-angular/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|js)$",
"testRegex": "/test/.*\\.test\\.ts$",
"moduleFileExtensions": [
"ts",
"js",
@ -22,7 +23,7 @@
"^assets/(.*)": "<rootDir>/src/assets/$1",
"^environments/(.*)": "<rootDir>/src/environments/$1"
},
"testEnvironment": "jest-preset-angular/testEnvironment.js",
"testEnvironment": "jest-preset-kendo-angular/testEnvironment.js",
"transformIgnorePatterns": [
"node_modules/(?!@ngrx)"
]

Просмотреть файл

@ -1,10 +1,10 @@
{
"name": "jest-preset-angular",
"version": "4.0.0",
"description": "Jest preset configuration for Angular projects",
"name": "kendo-angular-jest-preset",
"version": "1.0.0",
"description": "Jest preset configuration for Kendo UI for Angular, based on original work by Michał Pierzchała",
"main": "index.js",
"repository": "git@github.com:thymikee/jest-preset-angular.git",
"author": "Michał Pierzchała <thymikee@gmail.com>",
"repository": "git@github.com:telerik/kendo-angular-jest-preset.git",
"author": "Progress",
"license": "BSD-3",
"dependencies": {
"jest-zone-patch": "^0.0.7",

2737
yarn.lock

Разница между файлами не показана из-за своего большого размера Загрузить разницу