Skip to content

Commit

Permalink
test: πŸ’ initial tests infra
Browse files Browse the repository at this point in the history
  • Loading branch information
itayod committed May 19, 2020
1 parent 463c362 commit 70dd72f
Show file tree
Hide file tree
Showing 11 changed files with 9,490 additions and 6,002 deletions.
12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
cacheDirectory: '<rootDir>/.cache',
testMatch: ['<rootDir>/projects/ngneat/reactive-forms/**/*.spec.ts'],
testPathIgnorePatterns: ['node_modules'],
transform: {
'^.+\\.ts?$': 'ts-jest'
},
collectCoverage: true,
modulePathIgnorePatterns: ['mocks.spec.ts']
};
32 changes: 0 additions & 32 deletions karma.conf.js

This file was deleted.

15,282 changes: 9,373 additions & 5,909 deletions package-lock.json

Large diffs are not rendered by default.

44 changes: 21 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"test": "jest",
"test:watch": "jest --watch",
"test:type:watch": "tsc ./projects/ngneat/reactive-forms/src/lib/type-tests/*.ts -w",
"test:lib:headless": "cross-env CI=true npm run test",
"lint": "ng lint",
"e2e": "ng e2e",
"contributors:add": "all-contributors add",
"hooks:pre-commit": "node hooks/pre-commit.js",
"commit": "git-cz",
"release:first": "npm run release -- --first-release",
"build:lib": "ng build @ngneat/reactive-forms",
"test:lib": "ng test @ngneat/reactive-forms",
"release": "cd projects/ngneat/reactive-forms && standard-version --infile ../../../CHANGELOG.md",
"test:lib:headless": "cross-env CI=true npm run test:lib"
"release": "cd projects/ngneat/reactive-forms && standard-version --infile ../../../CHANGELOG.md"
},
"private": true,
"dependencies": {
Expand All @@ -37,33 +38,30 @@
"@angular-devkit/build-ng-packagr": "~0.901.6",
"@angular/cli": "~9.1.6",
"@angular/compiler-cli": "~9.1.7",
"@commitlint/cli": "8.1.0",
"@commitlint/config-angular": "^8.1.0",
"@commitlint/config-conventional": "^8.1.0",
"@ngneat/spectator": "^4.11.1",
"@types/jest": "25.2.2",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"all-contributors-cli": "^6.8.1",
"codelyzer": "^5.1.2",
"cross-env": "^5.2.0",
"expect-type": "^0.7.4",
"git-cz": "^3.2.1",
"husky": "^3.0.1",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~3.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"jest": "26.0.1",
"jest-preset-angular": "8.2.0",
"lint-staged": "^9.2.0",
"ng-packagr": "^9.0.0",
"prettier": "^1.18.2",
"protractor": "~5.4.3",
"standard-version": "^6.0.1",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~3.8.3",
"@commitlint/cli": "8.1.0",
"@commitlint/config-angular": "^8.1.0",
"@commitlint/config-conventional": "^8.1.0",
"git-cz": "^3.2.1",
"all-contributors-cli": "^6.8.1",
"lint-staged": "^9.2.0",
"prettier": "^1.18.2",
"standard-version": "^6.0.1",
"husky": "^3.0.1",
"cross-env": "^5.2.0",
"@ngneat/spectator": "^4.11.1"
"typescript": "~3.8.3"
},
"husky": {
"hooks": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
exports.__esModule = true;
var expect_type_1 = require('expect-type');
var rxjs_1 = require('rxjs');
var formControl_1 = require('../formControl');
test('control value should be type of string', function() {
var control = new formControl_1.FormControl('a string');
expect_type_1.expectTypeOf(control.value).toBeString();
});
test('control valueChanges should be stream of strings', function() {
var control = new formControl_1.FormControl('a string');
expect_type_1.expectTypeOf(control.valueChanges$).toMatchTypeOf(new rxjs_1.Observable());
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expectTypeOf } from 'expect-type';
import { Observable } from 'rxjs';
import { FormControl } from '../formControl';

test('control value should be type of string', () => {
const control = new FormControl<string>('a string');
expectTypeOf(control.value).toBeString();
});

test('control valueChanges should be stream of strings', () => {
const control = new FormControl<string>('a string');
expectTypeOf(control.valueChanges$).toMatchTypeOf(new Observable<string>());
});
2 changes: 1 addition & 1 deletion projects/ngneat/reactive-forms/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "../../../out-tsc/spec",
"types": ["jasmine", "node"]
"types": ["node", "jest"]
},
"files": ["src/test.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
Expand Down
30 changes: 30 additions & 0 deletions setup-jest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'jest-preset-angular';

/* global mocks for jsdom */
const mock = () => {
let storage: { [key: string]: string } = {};
return {
getItem: (key: string) => (key in storage ? storage[key] : null),
setItem: (key: string, value: string) => (storage[key] = value || ''),
removeItem: (key: string) => delete storage[key],
clear: () => (storage = {})
};
};

Object.defineProperty(window, 'localStorage', { value: mock() });
Object.defineProperty(window, 'sessionStorage', { value: mock() });
Object.defineProperty(window, 'getComputedStyle', {
value: () => ['-webkit-appearance']
});

Object.defineProperty(document.body.style, 'transform', {
value: () => {
return {
enumerable: true,
configurable: true
};
}
});

/* output shorter and more meaningful Zone error stack traces */
// Error.stackTraceLimit = 2;
25 changes: 0 additions & 25 deletions src/test.ts

This file was deleted.

21 changes: 21 additions & 0 deletions test-config.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { TestBed } from '@angular/core/testing';

type CompilerOptions = Partial<{
providers: any[];
useJit: boolean;
preserveWhitespaces: boolean;
}>;
export type ConfigureFn = (testBed: typeof TestBed) => void;

export const configureTests = (configure: ConfigureFn, compilerOptions: CompilerOptions = {}) => {
const compilerConfig: CompilerOptions = {
preserveWhitespaces: false,
...compilerOptions
};

const configuredTestBed = TestBed.configureCompiler(compilerConfig);

configure(configuredTestBed);

return configuredTestBed.compileComponents().then(() => configuredTestBed);
};
18 changes: 6 additions & 12 deletions tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": [
"jasmine",
"node"
]
"types": ["jest", "node"],
"module": "commonjs",
"emitDecoratorMetadata": true,
"allowJs": true
},
"files": [
"src/test.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
"files": ["src/polyfills.ts"],
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}

0 comments on commit 70dd72f

Please sign in to comment.