From 703b67c4a8e85cb2cd846fc594759260c42a48fe Mon Sep 17 00:00:00 2001 From: Jiuqing Song Date: Wed, 26 Jul 2023 12:54:31 -0700 Subject: [PATCH] Improve test process (#1977) * Add a build test script to detect test code issue * improve test speed * fix test --- demo/scripts/tsconfig.json | 8 +-- karma.conf.js | 31 ++++++----- package.json | 5 +- .../PastePlugin/ContentModelPastePlugin.ts | 2 +- packages-content-model/tsconfig.test.json | 24 +++++++++ packages-ui/roosterjs-react/test/emptyTest.ts | 2 + packages-ui/tsconfig.json | 2 +- packages-ui/tsconfig.test.json | 23 ++++++++ .../lib/event/PluginDomEvent.ts | 2 +- packages/tsconfig.test.json | 24 +++++++++ tools/build.js | 3 ++ tools/buildTools/buildTest.js | 43 +++++++++++++++ yarn.lock | 54 +++++++++++++++---- 13 files changed, 192 insertions(+), 31 deletions(-) create mode 100644 packages-content-model/tsconfig.test.json create mode 100644 packages-ui/roosterjs-react/test/emptyTest.ts create mode 100644 packages-ui/tsconfig.test.json create mode 100644 packages/tsconfig.test.json create mode 100644 tools/buildTools/buildTest.js diff --git a/demo/scripts/tsconfig.json b/demo/scripts/tsconfig.json index 6d91aa7f868..8fe669a06a5 100644 --- a/demo/scripts/tsconfig.json +++ b/demo/scripts/tsconfig.json @@ -26,10 +26,10 @@ "roosterjs-color-utils": ["packages/roosterjs-color-utils/lib/index"], "roosterjs-color-utils/lib/*": ["packages/roosterjs-color-utils/lib/*"], "roosterjs-content-model-types": [ - "packages-content-model/roosterjs-content-model-dom/lib/index" + "packages-content-model/roosterjs-content-model-types/lib/index" ], "roosterjs-content-model-types/lib/*": [ - "packages-content-model/roosterjs-content-model-dom/lib/*" + "packages-content-model/roosterjs-content-model-types/lib/*" ], "roosterjs-content-model-dom": [ "packages-content-model/roosterjs-content-model-dom/lib/index" @@ -38,10 +38,10 @@ "packages-content-model/roosterjs-content-model-dom/lib/*" ], "roosterjs-content-model-editor": [ - "packages-content-model/roosterjs-content-model-dom/lib/index" + "packages-content-model/roosterjs-content-model-editor/lib/index" ], "roosterjs-content-model-editor/lib/*": [ - "packages-content-model/roosterjs-content-model-dom/lib/*" + "packages-content-model/roosterjs-content-model-editor/lib/*" ], "roosterjs-react": ["packages-ui/roosterjs-react/lib/index"], "roosterjs-react/lib/*": ["packages-ui/roosterjs-react/lib/*"] diff --git a/karma.conf.js b/karma.conf.js index 2df4ed526c0..259cacc3735 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -49,6 +49,22 @@ module.exports = function (config) { launcher.push('Firefox'); } + const tsConfig = { + compilerOptions: { + rootDir: rootPath, + declaration: false, + strict: false, + paths: { + '*': [ + '*', + rootPath + '/packages/*', + rootPath + '/packages-ui/*', + rootPath + '/packages-content-model/*', + ], + }, + }, + }; + const rules = runCoverage ? [ { @@ -57,30 +73,21 @@ module.exports = function (config) { { loader: '@jsdevtools/coverage-istanbul-loader' }, { loader: 'ts-loader', - options: { - compilerOptions: { - rootDir: rootPath, - declaration: false, - }, - }, + options: tsConfig, }, ], }, { test: /test(\\|\/).*\.ts$/, loader: 'ts-loader', - options: { - compilerOptions: { rootDir: rootPath, strict: false, declaration: false }, - }, + options: tsConfig, }, ] : [ { test: /\.ts$/, loader: 'ts-loader', - options: { - compilerOptions: { rootDir: rootPath, strict: false, declaration: false }, - }, + options: tsConfig, }, ]; diff --git a/package.json b/package.json index a925481c064..8e471ec5ea2 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "builddemo": "node tools/build.js builddemo", "builddoc": "node tools/build.js builddoc", "build": "node tools/build.js clean checkdep normalize tslint buildcommonjs dts packprod builddemo", - "build:ci": "node --max-old-space-size=8192 tools/build.js --noProgressBar clean checkdep normalize tslint buildcommonjs buildamd buildmjs dts pack packprod builddemo builddoc", + "buildtest": "node tools/build.js normalize buildtest", + "build:ci": "node --max-old-space-size=8192 tools/build.js --noProgressBar clean checkdep normalize tslint buildcommonjs buildamd buildmjs buildtest dts pack packprod builddemo builddoc", "start": "node tools/start.js", "test": "node tools/build.js normalize & karma start --chrome", "test:chrome": "node tools/build.js normalize & karma start --chrome", @@ -63,7 +64,7 @@ "sass": "^1.49.8", "sass-loader": "8.0.2", "toposort": "2.0.2", - "ts-loader": "7.0.2", + "ts-loader": "9.4.4", "tslib": "^2.3.1", "tslint": "6.1.2", "tslint-eslint-rules": "5.4.0", diff --git a/packages-content-model/roosterjs-content-model-editor/lib/editor/plugins/PastePlugin/ContentModelPastePlugin.ts b/packages-content-model/roosterjs-content-model-editor/lib/editor/plugins/PastePlugin/ContentModelPastePlugin.ts index f2ecf3257a3..7360aed2410 100644 --- a/packages-content-model/roosterjs-content-model-editor/lib/editor/plugins/PastePlugin/ContentModelPastePlugin.ts +++ b/packages-content-model/roosterjs-content-model-editor/lib/editor/plugins/PastePlugin/ContentModelPastePlugin.ts @@ -27,7 +27,7 @@ const GOOGLE_SHEET_NODE_NAME = 'google-sheets-html-origin'; * 4. Content copied from Power Point * (This class is still under development, and may still be changed in the future with some breaking changes) */ -export default class ContentModelFormatPlugin implements EditorPlugin { +export default class ContentModelPastePlugin implements EditorPlugin { private editor: IContentModelEditor | null = null; /** diff --git a/packages-content-model/tsconfig.test.json b/packages-content-model/tsconfig.test.json new file mode 100644 index 00000000000..98b02b80873 --- /dev/null +++ b/packages-content-model/tsconfig.test.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "strict": false, + "target": "es5", + "module": "commonjs", + "noEmit": true, + "sourceMap": true, + "inlineSources": true, + "declaration": true, + "removeComments": false, + "noImplicitAny": true, + "preserveConstEnums": true, + "noUnusedLocals": true, + "downlevelIteration": true, + "importHelpers": true, + "baseUrl": ".", + "paths": { + "*": ["*", "../packages/*"] + }, + "rootDir": "..", + "lib": ["es6", "dom"] + }, + "include": ["./*/test/**/*.ts"] +} diff --git a/packages-ui/roosterjs-react/test/emptyTest.ts b/packages-ui/roosterjs-react/test/emptyTest.ts new file mode 100644 index 00000000000..155e460769f --- /dev/null +++ b/packages-ui/roosterjs-react/test/emptyTest.ts @@ -0,0 +1,2 @@ +// Add this empty test file for now to pass the build +describe('roosterjs-react', () => {}); diff --git a/packages-ui/tsconfig.json b/packages-ui/tsconfig.json index b243010e947..27bcb1f969a 100644 --- a/packages-ui/tsconfig.json +++ b/packages-ui/tsconfig.json @@ -19,5 +19,5 @@ "rootDir": ".", "lib": ["es6", "dom"] }, - "include": ["**/*.ts", "**/*.tsx"] + "include": ["./*/lib/**/*.ts", "./*/lib/**/*.tsx"] } diff --git a/packages-ui/tsconfig.test.json b/packages-ui/tsconfig.test.json new file mode 100644 index 00000000000..18d64d0348c --- /dev/null +++ b/packages-ui/tsconfig.test.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "strict": false, + "jsx": "react", + "target": "es5", + "module": "commonjs", + "noEmit": true, + "sourceMap": true, + "inlineSources": true, + "declaration": true, + "removeComments": false, + "noImplicitAny": true, + "preserveConstEnums": true, + "noUnusedLocals": true, + "baseUrl": ".", + "paths": { + "*": ["*", "../packages/*"] + }, + "rootDir": "..", + "lib": ["es6", "dom"] + }, + "include": ["./*/test/**/*.ts", "./*/test/**/*.tsx"] +} diff --git a/packages/roosterjs-editor-types/lib/event/PluginDomEvent.ts b/packages/roosterjs-editor-types/lib/event/PluginDomEvent.ts index 9fdd9759bad..b440d08ba56 100644 --- a/packages/roosterjs-editor-types/lib/event/PluginDomEvent.ts +++ b/packages/roosterjs-editor-types/lib/event/PluginDomEvent.ts @@ -41,7 +41,7 @@ export interface PluginKeyDownEventData { /** * Whether this event is handled by edit feature */ - handledByEditFeature: boolean; + handledByEditFeature?: boolean; } /** diff --git a/packages/tsconfig.test.json b/packages/tsconfig.test.json new file mode 100644 index 00000000000..1500bf7be24 --- /dev/null +++ b/packages/tsconfig.test.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "strict": false, + "target": "es5", + "module": "commonjs", + "noEmit": true, + "sourceMap": true, + "inlineSources": true, + "declaration": true, + "removeComments": false, + "noImplicitAny": true, + "preserveConstEnums": true, + "noUnusedLocals": true, + "downlevelIteration": true, + "importHelpers": true, + "baseUrl": ".", + "paths": { + "*": ["*"] + }, + "rootDir": "..", + "lib": ["es6", "dom"] + }, + "include": ["./*/test/**/*.ts"] +} diff --git a/tools/build.js b/tools/build.js index 86db89a25ef..3e6a78d8459 100644 --- a/tools/build.js +++ b/tools/build.js @@ -16,6 +16,7 @@ const dts = require('./buildTools/dts'); const buildDemoStep = require('./buildTools/buildDemo'); const buildDocumentStep = require('./buildTools/buildDocument'); const publishStep = require('./buildTools/publish'); +const buildTestStep = require('./buildTools/buildTest'); const allTasks = [ tslintStep, cleanStep, @@ -24,6 +25,7 @@ const allTasks = [ buildAmdStep, buildMjsStep, buildCommonJsStep, + buildTestStep, pack.commonJsDebug, pack.commonJsProduction, pack.amdDebug, @@ -56,6 +58,7 @@ const commands = [ 'buildamd', // Build in AMD mode 'buildmjs', // Build in ESM/MJS mode 'buildcommonjs', // Build in CommonJs mode + 'buildtest', // Build test code 'pack', // Run webpack to generate standalone .js files 'packprod', // Run webpack to generate standalone .js files in production mode 'dts', // Generate type definition files (.d.ts) diff --git a/tools/buildTools/buildTest.js b/tools/buildTools/buildTest.js new file mode 100644 index 00000000000..6caec39cfd7 --- /dev/null +++ b/tools/buildTools/buildTest.js @@ -0,0 +1,43 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const { + runNode, + nodeModulesPath, + packagesPath, + packagesUiPath, + packagesContentModelPath, +} = require('./common'); + +function buildTest() { + const typescriptPath = path.join(nodeModulesPath, 'typescript/lib/tsc.js'); + + runNode( + typescriptPath + + ` -p ${path.join( + packagesPath, + 'tsconfig.test.json' + )} -t es5 --moduleResolution node -m commonjs` + ); + runNode( + typescriptPath + + ` -p ${path.join( + packagesUiPath, + 'tsconfig.test.json' + )} -t es5 --moduleResolution node -m commonjs` + ); + runNode( + typescriptPath + + ` -p ${path.join( + packagesContentModelPath, + 'tsconfig.test.json' + )} -t es5 --moduleResolution node -m commonjs` + ); +} + +module.exports = { + message: 'Building test code.', + callback: buildTest, + enabled: options => options.buildtest, +}; diff --git a/yarn.lock b/yarn.lock index 6f6cca71764..7512d3bcd30 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1160,6 +1160,14 @@ chalk@^4.0.0: ansi-styles "^4.1.0" supports-color "^7.1.0" +chalk@^4.1.0: + version "4.1.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" + integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + "chokidar@>=3.0.0 <4.0.0", chokidar@^3.5.1: version "3.5.3" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" @@ -1786,7 +1794,7 @@ engine.io@~6.1.0: engine.io-parser "~5.0.0" ws "~8.2.3" -enhanced-resolve@4.1.0, enhanced-resolve@^4.0.0: +enhanced-resolve@4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.1.0.tgz#41c7e0bfdfe74ac1ffe1e57ad6a5c6c9f3742a7f" integrity sha512-F/7vkyTtyc/llOIn8oWclcB25KdRaiPBpZYDgJHgh/UHtpgT2p2eldQgtQnLtUvfMKPKxbRaQM/hHkvLHt1Vng== @@ -1795,6 +1803,14 @@ enhanced-resolve@4.1.0, enhanced-resolve@^4.0.0: memory-fs "^0.4.0" tapable "^1.0.0" +enhanced-resolve@^5.0.0: + version "5.15.0" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz#1af946c7d93603eb88e9896cee4904dc012e9c35" + integrity sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg== + dependencies: + graceful-fs "^4.2.4" + tapable "^2.2.0" + enhanced-resolve@^5.14.1: version "5.14.1" resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.14.1.tgz#de684b6803724477a4af5d74ccae5de52c25f6b3" @@ -3278,7 +3294,7 @@ loader-runner@^4.2.0: resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-4.3.0.tgz#c1b4a163b99f614830353b16755e7149ac2314e1" integrity sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg== -loader-utils@1.2.3, loader-utils@^1.0.2, loader-utils@^1.2.3: +loader-utils@1.2.3, loader-utils@^1.2.3: version "1.2.3" resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.2.3.tgz#1ff5dc6911c9f0a062531a4c04b609406108c2c7" integrity sha512-fkpz8ejdnEMG3s37wGL07iSBDg99O9D5yflE9RGNH3hRdx9SOwYfnGYdZOUIZitN8E+E2vkq3MUMYMvPYl5ZZA== @@ -3348,6 +3364,13 @@ lru-cache@^5.1.1: dependencies: yallist "^3.0.2" +lru-cache@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" + integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA== + dependencies: + yallist "^4.0.0" + lunr@^2.3.9: version "2.3.9" resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.9.tgz#18b123142832337dd6e964df1a5a7707b25d35e1" @@ -4628,6 +4651,13 @@ semver@^6.0.0, semver@^6.3.0: resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== +semver@^7.3.4: + version "7.5.4" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e" + integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA== + dependencies: + lru-cache "^6.0.0" + send@0.18.0: version "0.18.0" resolved "https://registry.yarnpkg.com/send/-/send-0.18.0.tgz#670167cc654b05f5aa4a767f9113bb371bc706be" @@ -5201,16 +5231,15 @@ tough-cookie@~2.4.3: psl "^1.1.24" punycode "^1.4.1" -ts-loader@7.0.2: - version "7.0.2" - resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-7.0.2.tgz#465bc904aea4c331e9550e7c7d75dd17a0b7c24c" - integrity sha512-DwpZFB67RoILQHx42dMjSgv2STpacsQu5X+GD/H9ocd8IhU0m8p3b/ZrIln2KmcucC6xep2PdEMEblpWT71euA== +ts-loader@9.4.4: + version "9.4.4" + resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-9.4.4.tgz#6ceaf4d58dcc6979f84125335904920884b7cee4" + integrity sha512-MLukxDHBl8OJ5Dk3y69IsKVFRA/6MwzEqBgh+OXMPB/OD01KQuWPFd1WAQP8a5PeSCAxfnkhiuWqfmFJzJQt9w== dependencies: - chalk "^2.3.0" - enhanced-resolve "^4.0.0" - loader-utils "^1.0.2" + chalk "^4.1.0" + enhanced-resolve "^5.0.0" micromatch "^4.0.0" - semver "^6.0.0" + semver "^7.3.4" tslib@1.9.0: version "1.9.0" @@ -5735,6 +5764,11 @@ yallist@^3.0.0, yallist@^3.0.2, yallist@^3.1.1: resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd" integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g== +yallist@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" + integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== + yaml@^1.7.2: version "1.9.2" resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.9.2.tgz#f0cfa865f003ab707663e4f04b3956957ea564ed"