MOBILE-3566 tests: Prepare unit tests with jest
parent
81ce1a7d01
commit
a4126dd67b
|
@ -0,0 +1,5 @@
|
||||||
|
language: node_js
|
||||||
|
node_js: 12
|
||||||
|
cache: npm
|
||||||
|
script:
|
||||||
|
- npm run test:ci
|
44
angular.json
44
angular.json
|
@ -94,35 +94,6 @@
|
||||||
"browserTarget": "app:build"
|
"browserTarget": "app:build"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test": {
|
|
||||||
"builder": "@angular-devkit/build-angular:karma",
|
|
||||||
"options": {
|
|
||||||
"main": "src/test.ts",
|
|
||||||
"polyfills": "src/polyfills.ts",
|
|
||||||
"tsConfig": "tsconfig.spec.json",
|
|
||||||
"karmaConfig": "karma.conf.js",
|
|
||||||
"styles": [],
|
|
||||||
"scripts": [],
|
|
||||||
"assets": [
|
|
||||||
{
|
|
||||||
"glob": "favicon.ico",
|
|
||||||
"input": "src/",
|
|
||||||
"output": "/"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"glob": "**/*",
|
|
||||||
"input": "src/assets",
|
|
||||||
"output": "/assets"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"configurations": {
|
|
||||||
"ci": {
|
|
||||||
"progress": false,
|
|
||||||
"watch": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"lint": {
|
"lint": {
|
||||||
"builder": "@angular-devkit/build-angular:tslint",
|
"builder": "@angular-devkit/build-angular:tslint",
|
||||||
"options": {
|
"options": {
|
||||||
|
@ -134,21 +105,6 @@
|
||||||
"exclude": ["**/node_modules/**"]
|
"exclude": ["**/node_modules/**"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"e2e": {
|
|
||||||
"builder": "@angular-devkit/build-angular:protractor",
|
|
||||||
"options": {
|
|
||||||
"protractorConfig": "e2e/protractor.conf.js",
|
|
||||||
"devServerTarget": "app:serve"
|
|
||||||
},
|
|
||||||
"configurations": {
|
|
||||||
"production": {
|
|
||||||
"devServerTarget": "app:serve:production"
|
|
||||||
},
|
|
||||||
"ci": {
|
|
||||||
"devServerTarget": "app:serve:ci"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ionic-cordova-build": {
|
"ionic-cordova-build": {
|
||||||
"builder": "@ionic/angular-toolkit:cordova-build",
|
"builder": "@ionic/angular-toolkit:cordova-build",
|
||||||
"options": {
|
"options": {
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
const { pathsToModuleNameMapper } = require('ts-jest/utils');
|
||||||
|
const { compilerOptions } = require('./tsconfig');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
preset: 'jest-preset-angular',
|
||||||
|
setupFilesAfterEnv: ['<rootDir>/src/tests/setup.ts'],
|
||||||
|
testMatch: ['**/?(*.)test.ts'],
|
||||||
|
collectCoverageFrom: [
|
||||||
|
'src/**/*.{ts,html}',
|
||||||
|
'!src/tests/**/*',
|
||||||
|
],
|
||||||
|
transform: {
|
||||||
|
'^.+\\.(ts|html)$': 'ts-jest',
|
||||||
|
},
|
||||||
|
transformIgnorePatterns: ['node_modules/(?!@ionic-native|@ionic)'],
|
||||||
|
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/src/' }),
|
||||||
|
globals: {
|
||||||
|
'ts-jest': {
|
||||||
|
tsConfig: './tsconfig.test.json',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
File diff suppressed because it is too large
Load Diff
21
package.json
21
package.json
|
@ -21,9 +21,11 @@
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"start": "ng serve",
|
"start": "ng serve",
|
||||||
"build": "ng build",
|
"build": "ng build",
|
||||||
"test": "ng test",
|
"test": "jest --verbose",
|
||||||
"lint": "ng lint",
|
"test:ci": "jest -ci --runInBand --verbose",
|
||||||
"e2e": "ng e2e"
|
"test:watch": "jest --watch",
|
||||||
|
"test:coverage": "jest --coverage",
|
||||||
|
"lint": "ng lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/common": "~10.0.0",
|
"@angular/common": "~10.0.0",
|
||||||
|
@ -89,18 +91,11 @@
|
||||||
"@angular/compiler-cli": "~10.0.0",
|
"@angular/compiler-cli": "~10.0.0",
|
||||||
"@angular/language-service": "~10.0.0",
|
"@angular/language-service": "~10.0.0",
|
||||||
"@ionic/angular-toolkit": "^2.3.0",
|
"@ionic/angular-toolkit": "^2.3.0",
|
||||||
"@types/jasmine": "~3.5.0",
|
|
||||||
"@types/jasminewd2": "~2.0.3",
|
|
||||||
"@types/node": "^12.11.1",
|
"@types/node": "^12.11.1",
|
||||||
"codelyzer": "^6.0.0",
|
"codelyzer": "^6.0.0",
|
||||||
"jasmine-core": "~3.5.0",
|
"jest": "^26.5.0",
|
||||||
"jasmine-spec-reporter": "~5.0.0",
|
"jest-preset-angular": "^8.3.1",
|
||||||
"karma": "~5.0.0",
|
"ts-jest": "^26.4.1",
|
||||||
"karma-chrome-launcher": "~3.1.0",
|
|
||||||
"karma-coverage-istanbul-reporter": "~3.0.2",
|
|
||||||
"karma-jasmine": "~3.3.0",
|
|
||||||
"karma-jasmine-html-reporter": "^1.5.0",
|
|
||||||
"protractor": "~7.0.0",
|
|
||||||
"ts-node": "~8.3.0",
|
"ts-node": "~8.3.0",
|
||||||
"tslint": "~6.1.0",
|
"tslint": "~6.1.0",
|
||||||
"typescript": "~3.9.5"
|
"typescript": "~3.9.5"
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { createComponent, prepareComponentTest } from '@/tests/utils';
|
||||||
|
|
||||||
|
import { AppComponent } from '@app/app.component';
|
||||||
|
|
||||||
|
describe('App component', () => {
|
||||||
|
|
||||||
|
beforeEach(() => prepareComponentTest(AppComponent));
|
||||||
|
|
||||||
|
it('should render', () => {
|
||||||
|
const fixture = createComponent(AppComponent);
|
||||||
|
|
||||||
|
expect(fixture.debugElement.componentInstance).toBeTruthy();
|
||||||
|
expect(fixture.nativeElement.querySelector('ion-router-outlet')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
|
@ -0,0 +1,30 @@
|
||||||
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { createComponent, prepareComponentTest } from '@/tests/utils';
|
||||||
|
|
||||||
|
import { CoreLoginInitPage } from '@core/login/pages/init/init.page';
|
||||||
|
|
||||||
|
describe('CoreLogin Init Page', () => {
|
||||||
|
|
||||||
|
beforeEach(() => prepareComponentTest(CoreLoginInitPage));
|
||||||
|
|
||||||
|
it('should render', () => {
|
||||||
|
const fixture = createComponent(CoreLoginInitPage);
|
||||||
|
|
||||||
|
expect(fixture.debugElement.componentInstance).toBeTruthy();
|
||||||
|
expect(fixture.nativeElement.querySelector('ion-spinner')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
|
@ -0,0 +1 @@
|
||||||
|
import 'jest-preset-angular';
|
|
@ -0,0 +1,29 @@
|
||||||
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { CUSTOM_ELEMENTS_SCHEMA, Type } from '@angular/core';
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
export async function prepareComponentTest(component: any): Promise<void> {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [component],
|
||||||
|
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
||||||
|
});
|
||||||
|
|
||||||
|
await TestBed.compileComponents();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createComponent<T>(component: Type<T>): ComponentFixture<T> {
|
||||||
|
return TestBed.createComponent(component);
|
||||||
|
}
|
|
@ -25,6 +25,6 @@
|
||||||
"src/**/*.d.ts"
|
"src/**/*.d.ts"
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"src/**/*.spec.ts"
|
"src/**/*.test.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,8 @@
|
||||||
"@directives/*": ["app/directives/*"],
|
"@directives/*": ["app/directives/*"],
|
||||||
"@pipes/*": ["app/pipes/*"],
|
"@pipes/*": ["app/pipes/*"],
|
||||||
"@services/*": ["app/services/*"],
|
"@services/*": ["app/services/*"],
|
||||||
"@singletons/*": ["app/singletons/*"]
|
"@singletons/*": ["app/singletons/*"],
|
||||||
|
"@tests/*": ["tests/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
{
|
|
||||||
"extends": "./tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "./out-tsc/spec",
|
|
||||||
"types": [
|
|
||||||
"jasmine",
|
|
||||||
"node"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"src/test.ts",
|
|
||||||
"src/polyfills.ts"
|
|
||||||
],
|
|
||||||
"include": [
|
|
||||||
"src/**/*.spec.ts",
|
|
||||||
"src/**/*.d.ts"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"outDir": "./out-tsc/tests",
|
||||||
|
"types": [
|
||||||
|
"jest",
|
||||||
|
"node"
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["*"],
|
||||||
|
"@addon/*": ["app/addon/*"],
|
||||||
|
"@app/*": ["app/*"],
|
||||||
|
"@classes/*": ["app/classes/*"],
|
||||||
|
"@components/*": ["app/components/*"],
|
||||||
|
"@core/*": ["app/core/*"],
|
||||||
|
"@directives/*": ["app/directives/*"],
|
||||||
|
"@pipes/*": ["app/pipes/*"],
|
||||||
|
"@services/*": ["app/services/*"],
|
||||||
|
"@singletons/*": ["app/singletons/*"],
|
||||||
|
"@tests/*": ["tests/*"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/tests/setup.ts",
|
||||||
|
"src/polyfills.ts"
|
||||||
|
],
|
||||||
|
"include": [
|
||||||
|
"src/**/*.test.ts",
|
||||||
|
"src/**/*.d.ts",
|
||||||
|
"src/tests/**/*.ts"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue