I am using Jest to test an angular app and it is taking a really long time for simple tests to run and I can not seem to figure out why.
My Jest setup in package.json
:
"jest": {
"modulePaths": [
"<rootDir>/src",
"<rootDir>/node_modules"
],
"testPathIgnorePatterns": [
".git/.*",
"node_modules/.*"
],
"transformIgnorePatterns": [
"node_modules/.*",
".*\\.js"
],
"setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.js",
"preset": "jest-preset-angular",
"testEnvironment": "jsdom",
"testRegex": "src/app/.*\\.spec\\.ts$",
"moduleFileExtensions": [
"ts",
"js",
"json"
],
"verbose": true,
"cacheDirectory": ".jest-cache",
"coveragePathIgnorePatterns": [
".*\\.(shim\\.ngstyle|ngfactory)\\.ts"
],
"globals": {
"ts-jest": {
"tsConfigFile": "./tsconfig.json"
},
"__TRANSFORM_HTML__": true
}
}
My Jest setup file:
'use strict';
require('core-js/es6/reflect');
require('core-js/es7/reflect');
require('zone.js');
require('zone.js/dist/proxy.js');
require('zone.js/dist/sync-test');
require('zone.js/dist/async-test');
require('zone.js/dist/fake-async-test');
require('jest-zone-patch');
const getTestBed = require('@angular/core/testing').getTestBed;
const BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule;
const platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing') .platformBrowserDynamicTesting;
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
Here is my simple test:
fdescribe('RichTextEditorComponent', () => {
it('should be fast', () => {
expect(true).toBeTruthy();
});
});
Does anyone have any idea as to why this is taking 9+ seconds?
--runInBand
flag. – AntimasquesetupTestFrameworkScriptFile
, which runs before each test. You should be using thesetupFiles
setting, which is an array of strings. One of those strings should point to your file, and it will run for each spec file instead of running for each test. jestjs.io/docs/en/configuration#setupfiles-array – Synagoguepackage.json
file instead, e.g.:"test": "/usr/bin/jest",
. – Googins