Browse Source

test(utils): implement jest

pull/3415/head
mehmet-erim 7 years ago
parent
commit
c7399068c8
  1. 21
      npm/packs/utils/angular.json
  2. 15
      npm/packs/utils/jest.config.js
  3. 26
      npm/packs/utils/package.json
  4. 6
      npm/packs/utils/projects/utils/jest.config.js
  5. 32
      npm/packs/utils/projects/utils/karma.conf.js
  6. 3
      npm/packs/utils/projects/utils/ng-package.json
  7. 26
      npm/packs/utils/projects/utils/src/test.ts
  8. 18
      npm/packs/utils/projects/utils/tsconfig.spec.json
  9. 17
      npm/packs/utils/projects/utils/tslint.json
  10. 1
      npm/packs/utils/test-setup.ts
  11. 4143
      npm/packs/utils/yarn.lock

21
npm/packs/utils/angular.json

@ -22,29 +22,24 @@
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"builder": "@angular-builders/jest:run",
"options": {
"main": "projects/utils/src/test.ts",
"tsConfig": "projects/utils/tsconfig.spec.json",
"karmaConfig": "projects/utils/karma.conf.js"
"coverage": true,
"passWithNoTests": true
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"projects/utils/tsconfig.lib.json",
"projects/utils/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
"tsConfig": ["projects/utils/tsconfig.lib.json", "projects/utils/tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
}
}
}
}},
}
},
"cli": {
"analytics": false
},
"defaultProject": "utils"
}
}

15
npm/packs/utils/jest.config.js

@ -0,0 +1,15 @@
module.exports = {
globals: {
'ts-jest': {
allowSyntheticDefaultImports: true,
},
},
transform: {
'^.+\\.(ts|js|html)$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '<rootDir>/coverage',
coverageReporters: ['html'],
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/test-setup.ts'],
};

26
npm/packs/utils/package.json

@ -1,8 +1,8 @@
{
"name": "@abp/utils",
"version": "0.0.2",
"version": "0.0.6",
"scripts": {
"prepublish": "node prepublish.js",
"prepublish": "yarn install --ignore-scripts && node prepublish.js",
"ng": "ng",
"start": "ng serve",
"build": "ng build",
@ -23,34 +23,36 @@
"metadata": "dist/abp-utils.metadata.json",
"sideEffects": false,
"devDependencies": {
"@angular-builders/jest": "^9.0.0",
"@angular-devkit/build-ng-packagr": "~0.901.0",
"@angular/cli": "~9.1.0",
"@angular/common": "^9.1.0",
"@angular/compiler": "~9.1.0",
"@angular/compiler-cli": "~9.1.0",
"@angular/core": "~9.1.0",
"@angular/platform-browser": "^9.1.0",
"@angular/platform-browser-dynamic": "^9.1.0",
"@types/execa": "^2.0.0",
"@types/fs-extra": "^8.1.0",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"@types/jest": "^25.1.4",
"@types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"execa": "^4.0.0",
"fs-extra": "^9.0.0",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.4.1",
"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": "^25.2.4",
"jest-preset-angular": "^8.1.2",
"ng-packagr": "^9.0.0",
"protractor": "~5.4.3",
"ts-node": "~8.3.0",
"tslib": "^1.10.0",
"tslint": "~6.1.0",
"typescript": "~3.8.3"
"typescript": "~3.6.0",
"zone.js": "~0.10.2"
},
"peerDependencies": {
"tslib": "^1.10.0"
},
"dependencies": {
"just-compare": "^1.3.0"
}
}

6
npm/packs/utils/projects/utils/jest.config.js

@ -0,0 +1,6 @@
const jestConfig = require('../../jest.config');
module.exports = {
...jestConfig,
name: 'utils',
};

32
npm/packs/utils/projects/utils/karma.conf.js

@ -1,32 +0,0 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../coverage/utils'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
};

3
npm/packs/utils/projects/utils/ng-package.json

@ -4,5 +4,6 @@
"deleteDestPath": true,
"lib": {
"entryFile": "src/public-api.ts"
}
},
"whitelistedNonPeerDependencies": ["just-compare"]
}

26
npm/packs/utils/projects/utils/src/test.ts

@ -1,26 +0,0 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(path: string, deep?: boolean, filter?: RegExp): {
keys(): string[];
<T>(id: string): T;
};
};
// 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);

18
npm/packs/utils/projects/utils/tsconfig.spec.json

@ -1,17 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": [
"jasmine",
"node"
]
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
"include": ["**/*.spec.ts", "**/*.d.ts"]
}

17
npm/packs/utils/projects/utils/tslint.json

@ -0,0 +1,17 @@
{
"extends": "../../tslint.json",
"rules": {
"directive-selector": [
true,
"attribute",
"abp",
"camelCase"
],
"component-selector": [
true,
"element",
"abp",
"kebab-case"
]
}
}

1
npm/packs/utils/test-setup.ts

@ -0,0 +1 @@
import 'jest-preset-angular';

4143
npm/packs/utils/yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save