Skip to content
Snippets Groups Projects
Commit 52e5bcb2 authored by Clayton, Brandon Scott's avatar Clayton, Brandon Scott
Browse files

setup jest

parent 9b614d76
No related branches found
No related tags found
1 merge request!23Updates
......@@ -41,6 +41,7 @@ npm-debug.log
yarn-error.log
testem.log
/typings
junit.xml
# System Files
.DS_Store
......
import type {Config} from '@jest/types';
const config: Config.InitialOptions = {
coverageDirectory: '<rootDir>/coverage/example',
coverageReporters: ['text-summary', 'html'],
globalSetup: 'jest-preset-angular/global-setup',
preset: 'jest-preset-angular',
reporters: ['default', 'jest-junit'],
roots: ['<rootDir>/src/'],
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
transformIgnorePatterns: [
'node_modules/(?!.*\\.mjs$|d3|d3-*|delaunator|robust-predicates|internmap)',
],
};
export default config;
// 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/example'),
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,
});
};
This diff is collapsed.
......@@ -8,7 +8,7 @@
"lint": "ng lint",
"ng": "ng",
"start": "ng serve",
"test": "ng test"
"test": "jest --config ./jest.config.ts --coverage"
},
"private": true,
"dependencies": {
......@@ -37,12 +37,10 @@
"@angular/cli": "~13.2.6",
"@angular/compiler-cli": "~13.2.6",
"@types/geojson": "^7946.0.7",
"@types/jasmine": "~3.6.0",
"@types/jasminewd2": "~2.0.3",
"@types/jest": "^29.0.0",
"@types/node": "^12.11.1",
"@typescript-eslint/eslint-plugin": "5.27.1",
"@typescript-eslint/parser": "5.27.1",
"codelyzer": "^6.0.0",
"eslint": "^8.17.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
......@@ -51,14 +49,9 @@
"eslint-plugin-typescript-sort-keys": "^2.1.0",
"eslint-plugin-unused-imports": "^2.0.0",
"gts": "^3.1.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~6.3.17",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"jest": "^28.1.3",
"jest-junit": "^14.0.1",
"jest-preset-angular": "^12.2.2",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.5.5"
......
import 'jest-preset-angular';
import 'jest-preset-angular/setup-jest';
Object.defineProperty(window, 'CSS', {value: null});
Object.defineProperty(window.URL, 'createObjectURL', {value: function () {}});
Object.defineProperty(window, 'getComputedStyle', {
value: () => {
return {
appearance: ['-webkit-appearance'],
display: 'none',
};
},
});
Object.defineProperty(document, 'doctype', {
value: '<!DOCTYPE html>',
});
Object.defineProperty(document.body.style, 'transform', {
value: () => {
return {
configurable: true,
enumerable: true,
};
},
});
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/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(),
{
teardown: {destroyAfterEach: false},
}
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"compileOnSave": false,
"compilerOptions": {
......@@ -8,12 +7,14 @@
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"importHelpers": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"target": "es2015",
"module": "es2020",
"lib": ["es2018", "dom"]
"lib": ["es2018", "dom"],
"types": ["node", "jest"]
}
}
......@@ -3,7 +3,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": ["jasmine"]
"types": ["jest"]
},
"files": ["src/test.ts", "src/polyfills.ts"],
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment