Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test running performance, show correct callstack #1854

Merged
merged 4 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@ const components = argv.components !== true && argv.components;
const runCoverage = typeof argv.coverage !== 'undefined';
const runFirefox = typeof argv.firefox !== 'undefined';
const runChrome = typeof argv.chrome !== 'undefined';

const testEntries = {
'Original RoosterJs': 'tools/karma.test.roosterjs.js',
UI: 'tools/karma.test.ui.js',
'Content Model': 'tools/karma.test.contentmodel.js',
All: 'tools/karma.test.all.js',
};
const currentEntry =
typeof argv.contentmodel !== 'undefined'
? 'Content Model'
: typeof argv.roosterjs !== 'undefined'
? 'Original RoosterJs'
: typeof argv.ui !== 'undefined'
? 'UI'
: 'All';
const currentFile = testEntries[currentEntry];
const allPreprocessors = Object.keys(testEntries).reduce((value, entry) => {
value[testEntries[entry]] = ['webpack', 'sourcemap'];
return value;
}, {});

const path = require('path');

module.exports = function (config) {
Expand Down Expand Up @@ -57,11 +78,9 @@ module.exports = function (config) {
clearContext: false,
},
browsers: launcher,
files: ['karma.tests.js'],
files: [currentFile],
frameworks: ['jasmine'],
preprocessors: {
'karma.tests.js': ['webpack', 'sourcemap'],
},
preprocessors: allPreprocessors,
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
Expand All @@ -76,7 +95,6 @@ module.exports = function (config) {
captureTimeout: 60000,

webpack: {
devtool: 'inline-source-map',
mode: 'development',
module: {
rules,
Expand All @@ -103,5 +121,7 @@ module.exports = function (config) {
};
}

console.log('Run ' + currentEntry + ' test cases...');

config.set(settings);
};
10 changes: 0 additions & 10 deletions karma.tests.js

This file was deleted.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"test:firefox": "node tools/build.js normalize & karma start --firefox",
"test:debug": "node tools/build.js normalize & karma start --no-single-run --chrome",
"test:coverage": "node tools/build.js normalize & karma start --coverage --firefox --chrome",
"test:cm": "node tools/build.js normalize & karma start --no-single-run --chrome --contentmodel",
"test:r": "node tools/build.js normalize & karma start --no-single-run --chrome --roosterjs",
"test:ui": "node tools/build.js normalize & karma start --no-single-run --chrome --ui",
"publish": "node tools/build.js clean normalize tslint buildcommonjs buildamd buildmjs dts pack packprod builddemo builddoc publish"
},
"devDependencies": {
Expand All @@ -51,7 +54,7 @@
"karma-firefox-launcher": "1.3.0",
"karma-jasmine": "3.1.1",
"karma-phantomjs-launcher": "1.0.4",
"karma-sourcemap-loader": "0.3.7",
"karma-sourcemap-loader": "0.4.0",
"karma-webpack": "5.0.0",
"prettier": "2.0.5",
"pretty-quick": "^2.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('ImageEdit | rotate and flip', () => {

it('rotateImage a image that was rotated', () => {
const editInfo = {
src: 'teste',
src: 'test',
widthPx: 10,
heightPx: 10,
naturalWidth: 10,
Expand All @@ -81,7 +81,7 @@ describe('ImageEdit | rotate and flip', () => {

it('flipImage | horizontal', () => {
const editInfo = {
src: 'teste',
src: 'test',
widthPx: 10,
heightPx: 10,
naturalWidth: 10,
Expand All @@ -97,7 +97,7 @@ describe('ImageEdit | rotate and flip', () => {

it('flipImage a vertical Image | horizontal', () => {
const editInfo = {
src: 'teste',
src: 'test',
widthPx: 10,
heightPx: 10,
naturalWidth: 10,
Expand All @@ -113,7 +113,7 @@ describe('ImageEdit | rotate and flip', () => {

it('unflipImage | horizontal', () => {
const editInfo = {
src: 'teste',
src: 'test',
widthPx: 10,
heightPx: 10,
naturalWidth: 10,
Expand All @@ -130,7 +130,7 @@ describe('ImageEdit | rotate and flip', () => {

it('flipImage | vertical', () => {
const editInfo = {
src: 'teste',
src: 'test',
widthPx: 10,
heightPx: 10,
naturalWidth: 10,
Expand All @@ -146,7 +146,7 @@ describe('ImageEdit | rotate and flip', () => {

it('flipImage a vertical Image | vertical', () => {
const editInfo = {
src: 'teste',
src: 'test',
widthPx: 10,
heightPx: 10,
naturalWidth: 10,
Expand All @@ -162,7 +162,7 @@ describe('ImageEdit | rotate and flip', () => {

it('unflipVertical | vertical', () => {
const editInfo = {
src: 'teste',
src: 'test',
widthPx: 10,
heightPx: 10,
naturalWidth: 10,
Expand All @@ -179,7 +179,7 @@ describe('ImageEdit | rotate and flip', () => {

it('flipVertical a flipped Image', () => {
const editInfo = {
src: 'teste',
src: 'test',
widthPx: 10,
heightPx: 10,
naturalWidth: 10,
Expand All @@ -196,7 +196,7 @@ describe('ImageEdit | rotate and flip', () => {

it('flipHorizontal a flipped Image', () => {
const editInfo = {
src: 'teste',
src: 'test',
widthPx: 10,
heightPx: 10,
naturalWidth: 10,
Expand Down
4 changes: 4 additions & 0 deletions tools/karma.test.all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var context = require.context('../packages', true, /test\/.+\.ts?$/);
var karmaTest = require('./karma.test');

module.exports = karmaTest(context);
4 changes: 4 additions & 0 deletions tools/karma.test.contentmodel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var context = require.context('../packages/roosterjs-content-model', true, /test\/.+\.ts?$/);
var karmaTest = require('./karma.test');

module.exports = karmaTest(context);
10 changes: 10 additions & 0 deletions tools/karma.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = function (context) {
if (!!__karma__.config.components) {
const filenameWithoutTest = __karma__.config.components.replace('Test', '');
const filterRegExpByFilename = new RegExp(filenameWithoutTest);
const specificFiles = context.keys().filter(path => filterRegExpByFilename.test(path));
return specificFiles.map(context);
} else {
return context.keys().map(key => context(key));
}
};
4 changes: 4 additions & 0 deletions tools/karma.test.roosterjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var context = require.context('../packages', true, /roosterjs(-editor-\w+)?\/test\/.+\.ts?$/);
var karmaTest = require('./karma.test');

module.exports = karmaTest(context);
4 changes: 4 additions & 0 deletions tools/karma.test.ui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var context = require.context('../packages-ui', true, /test\/.+\.ts?$/);
var karmaTest = require('./karma.test');

module.exports = karmaTest(context);
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2413,7 +2413,7 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9,
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz#041b05df45755e587a24942279b9d113146e1c96"
integrity sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==

graceful-fs@^4.2.4, graceful-fs@^4.2.9:
graceful-fs@^4.2.10, graceful-fs@^4.2.4, graceful-fs@^4.2.9:
version "4.2.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3"
integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==
Expand Down Expand Up @@ -3174,12 +3174,12 @@ [email protected]:
lodash "^4.0.1"
phantomjs-prebuilt "^2.1.7"

karma-sourcemap-loader@0.3.7:
version "0.3.7"
resolved "https://registry.yarnpkg.com/karma-sourcemap-loader/-/karma-sourcemap-loader-0.3.7.tgz#91322c77f8f13d46fed062b042e1009d4c4505d8"
integrity sha1-kTIsd/jxPUb+0GKwQuEAnUxFBdg=
karma-sourcemap-loader@0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/karma-sourcemap-loader/-/karma-sourcemap-loader-0.4.0.tgz#b01d73f8f688f533bcc8f5d273d43458e13b5488"
integrity sha512-xCRL3/pmhAYF3I6qOrcn0uhbQevitc2DERMPH82FMnG+4WReoGcGFZb1pURf2a5apyrOHRdvD+O6K7NljqKHyA==
dependencies:
graceful-fs "^4.1.2"
graceful-fs "^4.2.10"

[email protected]:
version "5.0.0"
Expand Down