diff --git a/karma.conf.js b/karma.conf.js index 96e6e5dd4fb..8b22d68bdc1 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -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) { @@ -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, @@ -76,7 +95,6 @@ module.exports = function (config) { captureTimeout: 60000, webpack: { - devtool: 'inline-source-map', mode: 'development', module: { rules, @@ -103,5 +121,7 @@ module.exports = function (config) { }; } + console.log('Run ' + currentEntry + ' test cases...'); + config.set(settings); }; diff --git a/karma.tests.js b/karma.tests.js deleted file mode 100644 index a1b28c3091b..00000000000 --- a/karma.tests.js +++ /dev/null @@ -1,10 +0,0 @@ -var context = require.context('./packages', true, /test\/.+\.ts?$/); - -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)); - module.exports = specificFiles.map(context); -} else { - module.exports = context.keys().map(key => context(key)); -} diff --git a/package.json b/package.json index cd68c705d85..ac46c479d6c 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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", diff --git a/packages/roosterjs-editor-plugins/test/imageEdit/imageEditTest.ts b/packages/roosterjs-editor-plugins/test/imageEdit/imageEditTest.ts index bea7e8b5a7c..1baef7da348 100644 --- a/packages/roosterjs-editor-plugins/test/imageEdit/imageEditTest.ts +++ b/packages/roosterjs-editor-plugins/test/imageEdit/imageEditTest.ts @@ -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, @@ -81,7 +81,7 @@ describe('ImageEdit | rotate and flip', () => { it('flipImage | horizontal', () => { const editInfo = { - src: 'teste', + src: 'test', widthPx: 10, heightPx: 10, naturalWidth: 10, @@ -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, @@ -113,7 +113,7 @@ describe('ImageEdit | rotate and flip', () => { it('unflipImage | horizontal', () => { const editInfo = { - src: 'teste', + src: 'test', widthPx: 10, heightPx: 10, naturalWidth: 10, @@ -130,7 +130,7 @@ describe('ImageEdit | rotate and flip', () => { it('flipImage | vertical', () => { const editInfo = { - src: 'teste', + src: 'test', widthPx: 10, heightPx: 10, naturalWidth: 10, @@ -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, @@ -162,7 +162,7 @@ describe('ImageEdit | rotate and flip', () => { it('unflipVertical | vertical', () => { const editInfo = { - src: 'teste', + src: 'test', widthPx: 10, heightPx: 10, naturalWidth: 10, @@ -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, @@ -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, diff --git a/tools/karma.test.all.js b/tools/karma.test.all.js new file mode 100644 index 00000000000..236036d9ba0 --- /dev/null +++ b/tools/karma.test.all.js @@ -0,0 +1,4 @@ +var context = require.context('../packages', true, /test\/.+\.ts?$/); +var karmaTest = require('./karma.test'); + +module.exports = karmaTest(context); diff --git a/tools/karma.test.contentmodel.js b/tools/karma.test.contentmodel.js new file mode 100644 index 00000000000..45f21fb5655 --- /dev/null +++ b/tools/karma.test.contentmodel.js @@ -0,0 +1,4 @@ +var context = require.context('../packages/roosterjs-content-model', true, /test\/.+\.ts?$/); +var karmaTest = require('./karma.test'); + +module.exports = karmaTest(context); diff --git a/tools/karma.test.js b/tools/karma.test.js new file mode 100644 index 00000000000..abec3064e37 --- /dev/null +++ b/tools/karma.test.js @@ -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)); + } +}; diff --git a/tools/karma.test.roosterjs.js b/tools/karma.test.roosterjs.js new file mode 100644 index 00000000000..cebf2698b8b --- /dev/null +++ b/tools/karma.test.roosterjs.js @@ -0,0 +1,4 @@ +var context = require.context('../packages', true, /roosterjs(-editor-\w+)?\/test\/.+\.ts?$/); +var karmaTest = require('./karma.test'); + +module.exports = karmaTest(context); diff --git a/tools/karma.test.ui.js b/tools/karma.test.ui.js new file mode 100644 index 00000000000..0a1a16c4d06 --- /dev/null +++ b/tools/karma.test.ui.js @@ -0,0 +1,4 @@ +var context = require.context('../packages-ui', true, /test\/.+\.ts?$/); +var karmaTest = require('./karma.test'); + +module.exports = karmaTest(context); diff --git a/yarn.lock b/yarn.lock index e7f47e72dcd..184c234512c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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== @@ -3174,12 +3174,12 @@ karma-phantomjs-launcher@1.0.4: 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" karma-webpack@5.0.0: version "5.0.0"