From 57b9bd14d8431abd0b90551ec01eca4dbb90ac4c Mon Sep 17 00:00:00 2001 From: liujia178 Date: Mon, 11 Dec 2023 15:09:06 +0800 Subject: [PATCH] upload test cases for 15 interfaces Signed-off-by: liujia178 --- .../ark_compiler_ut/common/ark_utils.test.ts | 202 ++++- .../common/check_import_modules.test.ts | 4 +- .../test/ark_compiler_ut/common/utils.test.ts | 713 +++++++++++++++++- .../class_mock/module_hotfix_mode_mock.ts | 24 - .../mock/class_mock/module_mode_mock.ts | 13 +- .../class_mock/module_source_files_mock.ts | 10 +- .../mock/rollup_mock/common.ts | 22 +- .../mock/rollup_mock/module_info.ts | 6 +- .../mock/rollup_mock/path_config.ts | 38 +- .../mock/rollup_mock/project_config.ts | 34 +- .../mock/rollup_mock/rollup_plugin_mock.ts | 17 +- .../ark_compiler_ut/mock/rollup_mock/share.ts | 9 +- .../module/module_hotfix_mode.test.ts | 82 ++ .../module/module_hotreload_mode.test.ts | 19 + .../module/module_mode.test.ts | 269 ++++++- .../module/module_source_file.test.ts | 29 +- .../testdata/expect/expectToJS.json | 4 + .../expect/terser_processed_expected_code.txt | 28 + .../testdata/testcase_def/README_zh.md | 1 + .../entry/src/entryability/EntryAbility.js | 49 ++ .../entry/build/hotReload/sourceMaps.map | 8 +- .../entry/src/entryability/EntryAbility.js | 49 ++ .../ets => }/entryability/EntryAbility.ts | 0 .../entry/src/{main/ets => }/pages/Index.ets | 0 .../utils/processProjectConfig.ts | 1 + compiler/test/ark_compiler_ut/utils/sleep.ts | 21 - .../utils/{path_utils.ts => utils.ts} | 10 +- 27 files changed, 1486 insertions(+), 176 deletions(-) delete mode 100644 compiler/test/ark_compiler_ut/mock/class_mock/module_hotfix_mode_mock.ts create mode 100644 compiler/test/ark_compiler_ut/module/module_hotfix_mode.test.ts create mode 100644 compiler/test/ark_compiler_ut/testdata/expect/expectToJS.json create mode 100644 compiler/test/ark_compiler_ut/testdata/expect/terser_processed_expected_code.txt create mode 100644 compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/entry/src/entryability/EntryAbility.js create mode 100644 compiler/test/ark_compiler_ut/testdata/testcase_def/entry/src/entryability/EntryAbility.js rename compiler/test/ark_compiler_ut/testdata/testcase_def/entry/src/{main/ets => }/entryability/EntryAbility.ts (100%) rename compiler/test/ark_compiler_ut/testdata/testcase_def/entry/src/{main/ets => }/pages/Index.ets (100%) delete mode 100644 compiler/test/ark_compiler_ut/utils/sleep.ts rename compiler/test/ark_compiler_ut/utils/{path_utils.ts => utils.ts} (87%) diff --git a/compiler/test/ark_compiler_ut/common/ark_utils.test.ts b/compiler/test/ark_compiler_ut/common/ark_utils.test.ts index 06c1b3568..5252ab989 100644 --- a/compiler/test/ark_compiler_ut/common/ark_utils.test.ts +++ b/compiler/test/ark_compiler_ut/common/ark_utils.test.ts @@ -16,34 +16,54 @@ import { expect } from 'chai'; import mocha from 'mocha'; import fs from "fs"; -import { ArkObfuscator } from "arkguard"; +import path from "path"; +import MagicString from 'magic-string'; import { getBuildModeInLowerCase, getPackageInfo, genSourceMapFileName, - writeArkguardObfuscatedSourceCode + isOhModules, + isEs2Abc, + writeTerserObfuscatedSourceCode } from '../../../lib/ark_utils'; import { DEBUG, RELEASE, - EXTNAME_JS, + OH_MODULES, EXTNAME_TS, - EXTNAME_ETS + EXTNAME_JS, + EXTNAME_ETS, + OBFUSCATION_TOOL } from '../../../lib/fast_build/ark_compiler/common/ark_define'; import RollUpPluginMock from '../mock/rollup_mock/rollup_plugin_mock'; import { BUNDLE_NAME_DEFAULT, ENTRY_MODULE_NAME_DEFAULT, EXTNAME_MAP, - JSONSTRING + ENTRYABILITY_JS } from '../mock/rollup_mock/common'; +import projectConfig from '../utils/processProjectConfig'; +import { + ES2ABC, + TS2ABC +} from '../../../lib/pre_define'; import { changeFileExtension } from '../../../lib/fast_build/ark_compiler/utils'; import ModuleSourceFileMock from '../mock/class_mock/module_source_files_mock'; import { genTemporaryPath, toUnixPath } from '../../../lib/utils'; +import { + ObConfigResolver, + MergedConfig +} from '../../../lib/fast_build/ark_compiler/common/ob_config_resolver'; +import { + utProcessArkConfig +} from '../../../lib/fast_build/ark_compiler/common/process_ark_config'; +import { ModuleSourceFile } from '../../../lib/fast_build/ark_compiler/module/module_source_file'; +import { newSourceMaps } from '../../../lib/fast_build/ark_compiler/transform'; +import { TERSER_PROCESSED_EXPECTED_CODE } from '../mock/rollup_mock/path_config'; mocha.describe('test ark_utils file api', function () { mocha.before(function () { @@ -153,12 +173,135 @@ mocha.describe('test ark_utils file api', function () { } }); - mocha.it('4-1: test writeArkguardObfuscatedSourceCode under build release', async function () { + mocha.it('4-1: test isOhModules under build debug', function () { + this.rollup.build(); + const returnInfo = isOhModules(this.rollup.share.projectConfig); + expect(returnInfo === false).to.be.true; + this.rollup.share.projectConfig.packageDir = OH_MODULES; + const returnInfoOh = isOhModules(this.rollup.share.projectConfig); + expect(returnInfoOh).to.be.true; + }); + + mocha.it('4-2: test isOhModules under build release', function () { + this.rollup.build(RELEASE); + const returnInfo = isOhModules(this.rollup.share.projectConfig); + expect(returnInfo === false).to.be.true; + this.rollup.share.projectConfig.packageDir = OH_MODULES; + const returnInfoOh = isOhModules(this.rollup.share.projectConfig); + expect(returnInfoOh).to.be.true; + }); + + mocha.it('4-3: test isOhModules under preview debug', function () { + this.rollup.preview(); + const returnInfo = isOhModules(this.rollup.share.projectConfig); + expect(returnInfo === false).to.be.true; + this.rollup.share.projectConfig.packageDir = OH_MODULES; + const returnInfoOh = isOhModules(this.rollup.share.projectConfig); + expect(returnInfoOh).to.be.true; + }); + + mocha.it('4-4: test isOhModules under hot reload debug', function () { + this.rollup.hotReload(); + const returnInfo = isOhModules(this.rollup.share.projectConfig); + expect(returnInfo === false).to.be.true; + this.rollup.share.projectConfig.packageDir = OH_MODULES; + const returnInfoOh = isOhModules(this.rollup.share.projectConfig); + expect(returnInfoOh).to.be.true; + }); + + mocha.it('4-5: test isOhModules under hot fix debug', function () { + projectConfig.buildMode = DEBUG; + const returnInfo = isOhModules(projectConfig); + expect(returnInfo).to.be.true; + }); + + mocha.it('4-6: test isOhModules under hot fix release', function () { + projectConfig.buildMode = RELEASE; + const returnInfo = isOhModules(projectConfig); + expect(returnInfo).to.be.true; + }); + + mocha.it('5-1: test isEs2Abc under build debug', function () { + this.rollup.build(); + this.rollup.share.projectConfig.pandaMode = ES2ABC; + const returnInfo = isEs2Abc(this.rollup.share.projectConfig); + expect(returnInfo).to.be.true; + + this.rollup.share.projectConfig.pandaMode = TS2ABC; + const returnInfoTS2ABC = isEs2Abc(this.rollup.share.projectConfig); + expect(returnInfoTS2ABC === false).to.be.true; + + this.rollup.share.projectConfig.pandaMode = "undefined"; + const returnInfoUndef = isEs2Abc(this.rollup.share.projectConfig); + expect(returnInfoUndef).to.be.true; + + this.rollup.share.projectConfig.pandaMode = undefined; + const returnInfoUndefined = isEs2Abc(this.rollup.share.projectConfig); + expect(returnInfoUndefined).to.be.true; + }); + + mocha.it('5-2: test isEs2Abc under build release', function () { + this.rollup.build(RELEASE); + this.rollup.share.projectConfig.pandaMode = ES2ABC; + const returnInfo = isEs2Abc(this.rollup.share.projectConfig); + expect(returnInfo).to.be.true; + + this.rollup.share.projectConfig.pandaMode = TS2ABC; + const returnInfoTS2ABC = isEs2Abc(this.rollup.share.projectConfig); + expect(returnInfoTS2ABC).to.be.false; + }); + + mocha.it('5-3: test isEs2Abc under preview debug', function () { + this.rollup.preview(); + this.rollup.share.projectConfig.pandaMode = ES2ABC; + const returnInfo = isEs2Abc(this.rollup.share.projectConfig); + expect(returnInfo).to.be.true; + + this.rollup.share.projectConfig.pandaMode = TS2ABC; + const returnInfoTS2ABC = isEs2Abc(this.rollup.share.projectConfig); + expect(returnInfoTS2ABC).to.be.false; + }); + + mocha.it('5-4: test isEs2Abc under hot reload debug', function () { + this.rollup.hotReload(); + this.rollup.share.projectConfig.pandaMode = ES2ABC; + const returnInfo = isEs2Abc(this.rollup.share.projectConfig); + expect(returnInfo).to.be.true; + + this.rollup.share.projectConfig.pandaMode = TS2ABC; + const returnInfoTS2ABC = isEs2Abc(this.rollup.share.projectConfig); + expect(returnInfoTS2ABC).to.be.false; + }); + + mocha.it('5-5: test isEs2Abc under hot fix debug', function () { + projectConfig.buildMode = DEBUG; + projectConfig.pandaMode = ES2ABC; + const returnInfo = isEs2Abc(projectConfig); + expect(returnInfo).to.be.true; + + projectConfig.pandaMode = TS2ABC; + const returnInfoTS2ABC = isEs2Abc(projectConfig); + expect(returnInfoTS2ABC).to.be.false; + }); + + mocha.it('5-6: test isEs2Abc under hot fix release', function () { + projectConfig.buildMode = RELEASE; + projectConfig.pandaMode = ES2ABC; + const returnInfo = isEs2Abc(projectConfig); + expect(returnInfo).to.be.true; + + projectConfig.pandaMode = TS2ABC; + const returnInfoTS2ABC = isEs2Abc(projectConfig); + expect(returnInfoTS2ABC).to.be.false; + }); + + mocha.it('6-1: test writeTerserObfuscatedSourceCode under build release', async function () { this.rollup.build(RELEASE); const mockFileList: object = this.rollup.getModuleIds(); for (const moduleId of mockFileList) { if (moduleId.endsWith(EXTNAME_TS)) { - const code: string = fs.readFileSync(moduleId, 'utf-8'); + const code: string = + fs.readFileSync(`${this.rollup.share.projectConfig.projectTopDir}/${ENTRYABILITY_JS}`, 'utf-8'); const moduleSource = new ModuleSourceFileMock(moduleId, code); moduleSource.initPluginEnvMock(this.rollup); const filePath = @@ -167,23 +310,34 @@ mocha.describe('test ark_utils file api', function () { const newFilePath = changeFileExtension(filePath, EXTNAME_JS); const relativeSourceFilePath: string = toUnixPath(moduleSource.moduleId).replace(toUnixPath(moduleSource.projectConfig.projectRootPath) + '/', ''); - moduleSource.projectConfig.arkObfuscator = new ArkObfuscator(); - const jsonString: string = JSONSTRING; - const arkguardConfig = JSON.parse(jsonString); - moduleSource.projectConfig.arkObfuscator.init(arkguardConfig); - await writeArkguardObfuscatedSourceCode(moduleSource.source, newFilePath, moduleSource.logger, - moduleSource.projectConfig, relativeSourceFilePath); - const readfilecontent = fs.readFileSync(newFilePath, 'utf-8'); - let mixedInfo: { content: string, sourceMap?: any, nameCache?: any }; - try { - mixedInfo = - await moduleSource.projectConfig.arkObfuscator.obfuscate(moduleSource.source, filePath, undefined, undefined); - } catch { - const red: string = '\u001b[31m'; - moduleSource.logger.error(red, `ArkTS:ERROR Failed to obfuscate file: ${relativeSourceFilePath}`); - } - expect(readfilecontent === mixedInfo.content).to.be.true; + const logger: object = this.rollup.share.getLogger(OBFUSCATION_TOOL); + const obConfig: ObConfigResolver = new ObConfigResolver(this.rollup.share.projectConfig, logger, true); + const mergedObConfig: MergedConfig = obConfig.resolveObfuscationConfigs(); + const isHarCompiled: boolean = this.rollup.share.projectConfig.compileHar; + moduleSource.projectConfig.terserConfig = + utProcessArkConfig.initTerserConfig(this.rollup.share.projectConfig, logger, mergedObConfig, isHarCompiled); + const Code: string = fs.readFileSync(moduleId, 'utf-8'); + const ModuleSource = new ModuleSourceFile(relativeSourceFilePath, Code); + const codeString: MagicString = new MagicString(ModuleSource.source); + const sourceMap: object = codeString.generateMap({ + source: relativeSourceFilePath, + file: `${path.basename(ModuleSource.moduleId)}`, + includeContent: false, + hires: true + }); + newSourceMaps[relativeSourceFilePath] = sourceMap; + delete newSourceMaps[relativeSourceFilePath].sourcesContent; + + await writeTerserObfuscatedSourceCode(moduleSource.source, newFilePath, moduleSource.logger, + moduleSource.projectConfig.terserConfig, relativeSourceFilePath, newSourceMaps); + const readFilecontent = fs.readFileSync(newFilePath, 'utf-8'); + const expectResult = fs.readFileSync(TERSER_PROCESSED_EXPECTED_CODE, 'utf-8'); + expect(readFilecontent === expectResult).to.be.true; } } + + for (const key of Object.keys(newSourceMaps)) { + delete newSourceMaps[key]; + } }); -}); +}); \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/common/check_import_modules.test.ts b/compiler/test/ark_compiler_ut/common/check_import_modules.test.ts index c2bab7554..fd9452ad5 100644 --- a/compiler/test/ark_compiler_ut/common/check_import_modules.test.ts +++ b/compiler/test/ark_compiler_ut/common/check_import_modules.test.ts @@ -27,7 +27,7 @@ import { EXTNAME_JS, EXTNAME_ETS } from '../../../lib/fast_build/ark_compiler/common/ark_define'; -import { ENTRYABILITY_JS_PATH_DEFAULT } from '../mock/rollup_mock/common' +import { ENTRYABILITY_JS_PATH_DEFAULT } from '../mock/rollup_mock/common'; mocha.describe('test check_import_module file api', function () { mocha.before(function () { @@ -44,7 +44,7 @@ mocha.describe('test check_import_module file api', function () { const mockFileList: object = this.rollup.getModuleIds(); this.rollup.moduleInfos.forEach((moduleInfo) => { if (moduleInfo.id.endsWith(EXTNAME_ETS)) { - path_ets = moduleInfo.id + path_ets = moduleInfo.id; } }) for (const moduleId of mockFileList) { diff --git a/compiler/test/ark_compiler_ut/common/utils.test.ts b/compiler/test/ark_compiler_ut/common/utils.test.ts index e20fe87d6..c1d21be17 100644 --- a/compiler/test/ark_compiler_ut/common/utils.test.ts +++ b/compiler/test/ark_compiler_ut/common/utils.test.ts @@ -23,6 +23,14 @@ import { needAotCompiler, shouldETSOrTSFileTransformToJS, changeFileExtension, + isAotMode, + isDebug, + isCommonJsPluginVirtualFile, + isCurrentProjectFiles, + isSpecifiedExt, + isTsOrEtsSourceFile, + isJsSourceFile, + isJsonSourceFile, utUtils, updateSourceMap } from '../../../lib/fast_build/ark_compiler/utils'; @@ -35,28 +43,38 @@ import { import { ESMODULE, JSBUNDLE, - RELEASE, EXTNAME_JS, EXTNAME_TS, - EXTNAME_ETS + EXTNAME_ETS, + EXTNAME_JSON, + RELEASE, + DEBUG } from '../../../lib/fast_build/ark_compiler/common/ark_define'; import ModuleSourceFileMock from '../mock/class_mock/module_source_files_mock'; import { genTemporaryPath, toUnixPath } from '../../../lib/utils'; -import { ModuleSourceFile } from '../../../lib/fast_build/ark_compiler/module/module_source_file'; +import projectConfig from '../utils/processProjectConfig'; +import { + TEST_TS, + TEST_JS, + TEST_ETS, + TEST_JSON +} from '../mock/rollup_mock/path_config'; +import { scanFiles } from "../utils/utils"; import { newSourceMaps } from '../../../lib/fast_build/ark_compiler/transform'; +import { ModuleSourceFile } from '../../../lib/fast_build/ark_compiler/module/module_source_file'; +import { + hasTsNoCheckOrTsIgnoreFiles, + compilingEtsOrTsFiles +} from '../../../lib/process_ui_syntax'; import { FILE, SOURCE, DYNAMICIMPORT_ETS, UPDATESOURCEMAP } from '../mock/rollup_mock/common'; -import { - hasTsNoCheckOrTsIgnoreFiles, - compilingEtsOrTsFiles -} from '../../../lib/process_ui_syntax'; mocha.describe('test utils file api', function () { mocha.before(function () { @@ -70,7 +88,7 @@ mocha.describe('test utils file api', function () { mocha.it('1-1: test needAotCompiler under build debug', function () { this.rollup.build(); const returnInfo = needAotCompiler(this.rollup.share.projectConfig); - expect(returnInfo === false).to.be.true; + expect(returnInfo).to.be.false; }); mocha.it('1-2: test needAotCompiler under build debug and anBuildMode is AOT_PARTIAL', function () { @@ -78,7 +96,7 @@ mocha.describe('test utils file api', function () { this.rollup.share.projectConfig.compileMode = ESMODULE; this.rollup.share.projectConfig.anBuildMode = AOT_PARTIAL; const returnInfo = needAotCompiler(this.rollup.share.projectConfig); - expect(returnInfo === true).to.be.true; + expect(returnInfo).to.be.true; }); mocha.it('1-3: test needAotCompiler under build release', function () { @@ -86,7 +104,7 @@ mocha.describe('test utils file api', function () { this.rollup.share.projectConfig.compileMode = ESMODULE; this.rollup.share.projectConfig.anBuildMode = AOT_FULL; const returnInfo = needAotCompiler(this.rollup.share.projectConfig); - expect(returnInfo === true).to.be.true; + expect(returnInfo).to.be.true; }); mocha.it('1-4: test needAotCompiler under build release and compileMode is JSBUNDLE', function () { @@ -94,7 +112,7 @@ mocha.describe('test utils file api', function () { this.rollup.share.projectConfig.compileMode = JSBUNDLE; this.rollup.share.projectConfig.anBuildMode = AOT_FULL; const returnInfo = needAotCompiler(this.rollup.share.projectConfig); - expect(returnInfo === false).to.be.true; + expect(returnInfo).to.be.false; }); mocha.it('1-5: test needAotCompiler under preview debug', function () { @@ -282,7 +300,7 @@ mocha.describe('test utils file api', function () { mocha.it('4-1-2: test updateSourceMap under build debug: newMap is null', async function () { this.rollup.build(); - const dynamicImportpath = this.rollup.share.projectConfig.DynamicImportpath + const dynamicImportpath = this.rollup.share.projectConfig.DynamicImportpath; const relativeSourceFilePath = toUnixPath(dynamicImportpath.replace(this.rollup.share.projectConfig.projectTopDir + path.sep, '')); const code: string = fs.readFileSync(dynamicImportpath, 'utf-8'); @@ -298,6 +316,7 @@ mocha.describe('test utils file api', function () { updatedMap[SOURCE] = [relativeSourceFilePath]; updatedMap[FILE] = path.basename(relativeSourceFilePath); newSourceMaps[relativeSourceFilePath] = await updateSourceMap(updatedMap); + expect(newSourceMaps[relativeSourceFilePath] === updatedMap).to.be.true; for (const key of Object.keys(newSourceMaps)) { delete newSourceMaps[key]; @@ -306,7 +325,7 @@ mocha.describe('test utils file api', function () { mocha.it('4-1-3: test updateSourceMap under build debug: originMap and newMap is not null', async function () { this.rollup.build(); - const dynamicImportpath = this.rollup.share.projectConfig.DynamicImportpath + const dynamicImportpath = this.rollup.share.projectConfig.DynamicImportpath; const relativeSourceFilePath = toUnixPath(dynamicImportpath.replace(this.rollup.share.projectConfig.projectTopDir + path.sep, '')); const code: string = fs.readFileSync(dynamicImportpath, 'utf-8'); @@ -318,7 +337,7 @@ mocha.describe('test utils file api', function () { includeContent: false, hires: true }); - const arraylist = Array.from(this.rollup.share.allFiles) + const arraylist = Array.from(this.rollup.share.allFiles); const syncCode: string = fs.readFileSync(arraylist[2].toString(), 'utf-8'); const dynamicModuleSource = new ModuleSourceFile(dynamicImportpath, syncCode); const codeString: MagicString = new MagicString(dynamicModuleSource.source); @@ -329,12 +348,14 @@ mocha.describe('test utils file api', function () { hires: true }); - newSourceMaps[relativeSourceFilePath] = sourceMap + newSourceMaps[relativeSourceFilePath] = sourceMap; delete newSourceMaps[relativeSourceFilePath].sourcesContent; updatedMap[SOURCE] = [relativeSourceFilePath]; updatedMap[FILE] = path.basename(relativeSourceFilePath); - newSourceMaps[relativeSourceFilePath] = await updateSourceMap(newSourceMaps[relativeSourceFilePath], updatedMap); - const readSourceMap = JSON.parse(fs.readFileSync(`${this.rollup.share.projectConfig.projectTopDir}/${UPDATESOURCEMAP}`, 'utf-8')) + newSourceMaps[relativeSourceFilePath] = + await updateSourceMap(newSourceMaps[relativeSourceFilePath], updatedMap); + const readSourceMap = + JSON.parse(fs.readFileSync(`${this.rollup.share.projectConfig.projectTopDir}/${UPDATESOURCEMAP}`, 'utf-8')); expect(newSourceMaps[relativeSourceFilePath].file === DYNAMICIMPORT_ETS).to.be.true; expect(newSourceMaps[relativeSourceFilePath].mappings === readSourceMap.mappings).to.be.true; for (const key of Object.keys(newSourceMaps)) { @@ -344,7 +365,7 @@ mocha.describe('test utils file api', function () { mocha.it('4-2: test updateSourceMap under build release', async function () { this.rollup.build(RELEASE); - const dynamicImportpath = this.rollup.share.projectConfig.DynamicImportpath + const dynamicImportpath = this.rollup.share.projectConfig.DynamicImportpath; const relativeSourceFilePath = toUnixPath(dynamicImportpath.replace(this.rollup.share.projectConfig.projectTopDir + path.sep, '')); const code: string = fs.readFileSync(dynamicImportpath, 'utf-8'); @@ -369,7 +390,7 @@ mocha.describe('test utils file api', function () { mocha.it('4-3: test updateSourceMap under preview debug', async function () { this.rollup.preview(); - const dynamicImportpath = this.rollup.share.projectConfig.DynamicImportpath + const dynamicImportpath = this.rollup.share.projectConfig.DynamicImportpath; const relativeSourceFilePath = toUnixPath(dynamicImportpath.replace(this.rollup.share.projectConfig.projectTopDir + path.sep, '')); const code: string = fs.readFileSync(dynamicImportpath, 'utf-8'); @@ -394,7 +415,7 @@ mocha.describe('test utils file api', function () { mocha.it('4-4: test updateSourceMap under hot reload debug', async function () { this.rollup.hotReload(); - const dynamicImportpath = this.rollup.share.projectConfig.DynamicImportpath + const dynamicImportpath = this.rollup.share.projectConfig.DynamicImportpath; const relativeSourceFilePath = toUnixPath(dynamicImportpath.replace(this.rollup.share.projectConfig.projectTopDir + path.sep, '')); const code: string = fs.readFileSync(dynamicImportpath, 'utf-8'); @@ -416,4 +437,656 @@ mocha.describe('test utils file api', function () { delete newSourceMaps[key]; } }); + + mocha.it('5-1: test isAotMode under build debug', function () { + this.rollup.build(); + const returnInfo = isAotMode(this.rollup.share.projectConfig); + expect(returnInfo).to.be.false; + }); + + mocha.it('5-2: test isAotMode under build release', function () { + this.rollup.build(RELEASE); + this.rollup.share.projectConfig.compileMode = ESMODULE; + this.rollup.share.projectConfig.anBuildMode = AOT_FULL; + const returnInfo = isAotMode(this.rollup.share.projectConfig); + expect(returnInfo).to.be.true; + }); + + mocha.it('5-3: test isAotMode under preview debug', function () { + this.rollup.preview(); + this.rollup.share.projectConfig.compileMode = JSBUNDLE; + this.rollup.share.projectConfig.anBuildMode = AOT_PARTIAL; + const buildModeIsAotType = isAotMode(this.rollup.share.projectConfig); + expect(buildModeIsAotType).to.be.false; + }); + + mocha.it('5-4: test isAotMode under hot reload debug', function () { + this.rollup.hotReload(); + this.rollup.share.projectConfig.compileMode = ESMODULE; + this.rollup.share.projectConfig.anBuildMode = AOT_TYPE; + const buildModeIsAotType = isAotMode(this.rollup.share.projectConfig); + expect(buildModeIsAotType).to.be.true; + }); + + mocha.it('5-5: test isAotMode under hot fix debug', function () { + projectConfig.buildMode = DEBUG; + projectConfig.compileMode = JSBUNDLE; + projectConfig.anBuildMode = AOT_TYPE; + const buildModeIsAotType = isAotMode(projectConfig); + expect(buildModeIsAotType).to.be.false; + }); + + mocha.it('5-6: test isAotMode under hot fix release', function () { + projectConfig.buildMode = RELEASE; + projectConfig.compileMode = ESMODULE; + projectConfig.anBuildMode = AOT_PARTIAL; + const buildModeIsAotType = isAotMode(projectConfig); + expect(buildModeIsAotType).to.be.true; + }); + + mocha.it('6-1: test isDebug under build debug', function () { + this.rollup.build(); + const returnInfo = isDebug(this.rollup.share.projectConfig); + expect(returnInfo).to.be.true; + }); + + mocha.it('6-2: test isDebug under build release', function () { + this.rollup.build(RELEASE); + const returnInfo = isDebug(this.rollup.share.projectConfig); + expect(returnInfo).to.be.false; + }); + + mocha.it('6-3: test isDebug under preview debug', function () { + this.rollup.preview(); + const returnInfo = isDebug(this.rollup.share.projectConfig); + expect(returnInfo).to.be.true; + }); + + mocha.it('6-4: test isDebug under hot reload debug', function () { + this.rollup.hotReload(); + const returnInfo = isDebug(this.rollup.share.projectConfig); + expect(returnInfo).to.be.true; + }); + + mocha.it('6-5: test isDebug under hot fix debug', function () { + projectConfig.buildMode = DEBUG; + const returnInfo = isDebug(projectConfig); + expect(returnInfo).to.be.true; + }); + + mocha.it('6-6: test isDebug under hot fix release', function () { + projectConfig.buildMode = RELEASE; + const returnInfo = isDebug(projectConfig); + expect(returnInfo).to.be.false; + }); + + mocha.it('7-1: test changeFileExtension under build debug', function () { + this.rollup.build(); + const targetExt = EXTNAME_TS; + const originExt = ''; + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS) || file.endsWith(EXTNAME_JS)) { + const currentExt = originExt.length === 0 ? path.extname(file) : originExt; + const fileWithoutExt = file.substring(0, file.lastIndexOf(currentExt)); + const returnInfo = changeFileExtension(file, targetExt, originExt); + expect(returnInfo === fileWithoutExt + targetExt).to.be.true; + } + } + }); + + mocha.it('7-2: test changeFileExtension under build release', function () { + this.rollup.build(RELEASE); + const targetExt = EXTNAME_TS; + const originExt = ''; + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS) || file.endsWith(EXTNAME_JS)) { + const currentExt = originExt.length === 0 ? path.extname(file) : originExt; + const fileWithoutExt = file.substring(0, file.lastIndexOf(currentExt)); + const returnInfo = changeFileExtension(file, targetExt, originExt); + expect(returnInfo === fileWithoutExt + targetExt).to.be.true; + } + } + }); + + mocha.it('7-3: test changeFileExtension under preview debug', function () { + this.rollup.preview(); + const targetExt = EXTNAME_TS; + const originExt = ''; + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS) || file.endsWith(EXTNAME_JS)) { + const currentExt = originExt.length === 0 ? path.extname(file) : originExt; + const fileWithoutExt = file.substring(0, file.lastIndexOf(currentExt)); + const returnInfo = changeFileExtension(file, targetExt, originExt); + expect(returnInfo === fileWithoutExt + targetExt).to.be.true; + } + } + }); + + mocha.it('7-4: test changeFileExtension under hot reload debug', function () { + this.rollup.hotReload(); + const targetExt = EXTNAME_TS; + const originExt = ''; + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS) || file.endsWith(EXTNAME_JS)) { + const currentExt = originExt.length === 0 ? path.extname(file) : originExt; + const fileWithoutExt = file.substring(0, file.lastIndexOf(currentExt)); + const returnInfo = changeFileExtension(file, targetExt, originExt); + expect(returnInfo === fileWithoutExt + targetExt).to.be.true; + } + } + }); + + mocha.it('7-5: test changeFileExtension under hot fix debug', function () { + projectConfig.buildMode = DEBUG; + const file = TEST_TS; + const targetExt = EXTNAME_TS; + const originExt = ''; + const currentExt = originExt.length === 0 ? path.extname(file) : originExt; + const fileWithoutExt = file.substring(0, file.lastIndexOf(currentExt)); + const returnInfo = changeFileExtension(file, targetExt, originExt); + expect(returnInfo === fileWithoutExt + targetExt).to.be.true; + }); + + mocha.it('7-6: test changeFileExtension under hot fix release', function () { + projectConfig.buildMode = RELEASE; + const file = TEST_TS; + const targetExt = EXTNAME_TS; + const originExt = ''; + const currentExt = originExt.length === 0 ? path.extname(file) : originExt; + const fileWithoutExt = file.substring(0, file.lastIndexOf(currentExt)); + const returnInfo = changeFileExtension(file, targetExt, originExt); + expect(returnInfo === fileWithoutExt + targetExt).to.be.true; + }); + + mocha.it('8-1: test isCommonJsPluginVirtualFile under build debug', function () { + this.rollup.build(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + const returnInfo = isCommonJsPluginVirtualFile(filePath); + expect(returnInfo).to.be.false; + } + } + }); + + mocha.it('8-2: test isCommonJsPluginVirtualFile under build release', function () { + this.rollup.build(RELEASE); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + const returnInfo = isCommonJsPluginVirtualFile(filePath); + expect(returnInfo).to.be.false; + } + } + }); + + mocha.it('8-3: test isCommonJsPluginVirtualFile under preview debug', function () { + this.rollup.preview(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + const returnInfo = isCommonJsPluginVirtualFile(filePath); + expect(returnInfo).to.be.false; + } + } + }); + + mocha.it('8-4: test isCommonJsPluginVirtualFile under hot reload debug', function () { + this.rollup.hotReload(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + const returnInfo = isCommonJsPluginVirtualFile(filePath); + expect(returnInfo).to.be.false; + } + } + }); + + mocha.it('8-5: test isCommonJsPluginVirtualFile under hot fix debug', function () { + projectConfig.buildMode = DEBUG; + const filePath = TEST_TS; + const returnInfo = isCommonJsPluginVirtualFile(filePath); + expect(returnInfo).to.be.false; + }); + + mocha.it('8-6: test isCommonJsPluginVirtualFile under hot fix release', function () { + projectConfig.buildMode = RELEASE; + const filePath = TEST_TS; + const returnInfo = isCommonJsPluginVirtualFile(filePath); + expect(returnInfo).to.be.false; + }); + + mocha.it('9-1: test isCurrentProjectFiles under build debug', function () { + this.rollup.build(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + const returnInfo = isCurrentProjectFiles(filePath, this.rollup.share.projectConfig); + expect(returnInfo).to.be.true; + } + } + }); + + mocha.it('9-2: test isCurrentProjectFiles under build release', function () { + this.rollup.build(RELEASE); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + const returnInfo = isCurrentProjectFiles(filePath, this.rollup.share.projectConfig); + expect(returnInfo).to.be.true; + } + } + }); + + mocha.it('9-3: test isCurrentProjectFiles under preview debug', function () { + this.rollup.preview(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + const returnInfo = isCurrentProjectFiles(filePath, this.rollup.share.projectConfig); + expect(returnInfo).to.be.true; + } + } + }); + + mocha.it('9-4: test isCurrentProjectFiles under hot reload debug', function () { + this.rollup.hotReload(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + const returnInfo = isCurrentProjectFiles(filePath, this.rollup.share.projectConfig); + expect(returnInfo).to.be.true; + } + } + }); + + mocha.it('9-5: test isCurrentProjectFiles under hot fix debug', function () { + projectConfig.buildMode = DEBUG; + const filePath = TEST_TS; + const returnInfo = isCurrentProjectFiles(filePath, projectConfig); + expect(returnInfo).to.be.false; + }); + + mocha.it('9-6: test isCurrentProjectFiles under hot fix release', function () { + projectConfig.buildMode = RELEASE; + const filePath = TEST_TS; + const returnInfo = isCurrentProjectFiles(filePath, projectConfig); + expect(returnInfo).to.be.false; + }); + + mocha.it('10-1: test isSpecifiedExt under build debug', function () { + this.rollup.build(); + const fileExtendName = EXTNAME_ETS; + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + if (filePath.endsWith(EXTNAME_ETS)) { + expect(isSpecifiedExt(filePath, fileExtendName)).to.be.true; + } else { + expect(isSpecifiedExt(filePath, fileExtendName)).to.be.false; + } + } + } + }); + + mocha.it('10-2: test isSpecifiedExt under build release', function () { + this.rollup.build(RELEASE); + const fileExtendName = EXTNAME_JS; + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + if (filePath.endsWith(EXTNAME_JS)) { + expect(isSpecifiedExt(filePath, fileExtendName)).to.be.true; + } else { + expect(isSpecifiedExt(filePath, fileExtendName)).to.be.false; + } + } + } + }); + + mocha.it('10-3: test isSpecifiedExt under preview debug', function () { + this.rollup.preview(); + const fileExtendName = EXTNAME_TS; + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + if (filePath.endsWith(EXTNAME_TS)) { + expect(isSpecifiedExt(filePath, fileExtendName)).to.be.true; + } else { + expect(isSpecifiedExt(filePath, fileExtendName)).to.be.false; + } + } + } + }); + + mocha.it('10-4: test isSpecifiedExt under hot reload debug', function () { + this.rollup.hotReload(); + const fileExtendName = EXTNAME_JS; + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + if (filePath.endsWith(EXTNAME_JS)) { + expect(isSpecifiedExt(filePath, fileExtendName)).to.be.true; + } else { + expect(isSpecifiedExt(filePath, fileExtendName)).to.be.false; + } + } + } + }); + + mocha.it('10-5: test isSpecifiedExt under hot fix debug', function () { + projectConfig.buildMode = DEBUG; + const fileExtendName = EXTNAME_JS; + const filePath = TEST_JS; + const returnInfo = isSpecifiedExt(filePath, fileExtendName); + expect(returnInfo).to.be.true; + }); + + mocha.it('10-6: test isSpecifiedExt under hot fix release', function () { + projectConfig.buildMode = RELEASE; + const fileExtendName = EXTNAME_JS; + const filePath = TEST_TS; + const returnInfo = isSpecifiedExt(filePath, fileExtendName); + expect(returnInfo).to.be.false; + }); + + mocha.it('11-1: test isTsOrEtsSourceFile under build debug', function () { + this.rollup.build(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS)) { + const returnInfo = isTsOrEtsSourceFile(file); + expect(returnInfo).to.be.true; + } + if (file.endsWith(EXTNAME_JS)) { + const returnInfoJs = isTsOrEtsSourceFile(file); + expect(returnInfoJs).to.be.false; + } + } + }); + + mocha.it('11-2: test isTsOrEtsSourceFile under build release', function () { + this.rollup.build(RELEASE); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS)) { + const returnInfo = isTsOrEtsSourceFile(file); + expect(returnInfo).to.be.true; + } + if (file.endsWith(EXTNAME_JS)) { + const returnInfoJs = isTsOrEtsSourceFile(file); + expect(returnInfoJs).to.be.false; + } + } + }); + + mocha.it('11-3: test isTsOrEtsSourceFile under preview debug', function () { + this.rollup.preview(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS)) { + const returnInfo = isTsOrEtsSourceFile(file); + expect(returnInfo).to.be.true; + } + if (file.endsWith(EXTNAME_JS)) { + const returnInfoJs = isTsOrEtsSourceFile(file); + expect(returnInfoJs).to.be.false; + } + } + }); + + mocha.it('11-4: test isTsOrEtsSourceFile under hot reload debug', function () { + this.rollup.hotReload(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS)) { + const returnInfo = isTsOrEtsSourceFile(file); + expect(returnInfo).to.be.true; + } + if (file.endsWith(EXTNAME_JS)) { + const returnInfoJs = isTsOrEtsSourceFile(file); + expect(returnInfoJs).to.be.false; + } + } + }); + + mocha.it('11-5: test isTsOrEtsSourceFile under hot fix debug', function () { + projectConfig.buildMode = DEBUG; + const file = TEST_TS; + const returnInfo = isTsOrEtsSourceFile(file); + expect(returnInfo).to.be.true; + const fileEts = TEST_ETS; + const returnInfoEts = isTsOrEtsSourceFile(fileEts); + expect(returnInfoEts).to.be.true; + + }); + + mocha.it('11-6: test isTsOrEtsSourceFile under hot fix release', function () { + projectConfig.buildMode = RELEASE; + const file = TEST_TS; + const returnInfo = isTsOrEtsSourceFile(file); + expect(returnInfo).to.be.true; + const fileJs = TEST_JS; + const returnInfoJs = isTsOrEtsSourceFile(fileJs); + expect(returnInfoJs).to.be.false; + }); + + mocha.it('12-1: test isJsSourceFile under build debug', function () { + this.rollup.build(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS)) { + const returnInfo = isJsSourceFile(file); + expect(returnInfo).to.be.false; + } + if (file.endsWith(EXTNAME_JS)) { + const returnInfoJs = isJsSourceFile(file); + expect(returnInfoJs).to.be.true; + } + } + }); + + mocha.it('12-2: test isJsSourceFile under build release', function () { + this.rollup.build(RELEASE); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS)) { + const returnInfo = isJsSourceFile(file); + expect(returnInfo).to.be.false; + } + if (file.endsWith(EXTNAME_JS)) { + const returnInfoJs = isJsSourceFile(file); + expect(returnInfoJs).to.be.true; + } + } + }); + + mocha.it('12-3: test isJsSourceFile under preview debug', function () { + this.rollup.preview(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS)) { + const returnInfo = isJsSourceFile(file); + expect(returnInfo).to.be.false; + } + if (file.endsWith(EXTNAME_JS)) { + const returnInfoJs = isJsSourceFile(file); + expect(returnInfoJs).to.be.true; + } + } + }); + + mocha.it('12-4: test isJsSourceFile under hot reload debug', function () { + this.rollup.hotReload(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS)) { + const returnInfo = isJsSourceFile(file); + expect(returnInfo).to.be.false; + } + if (file.endsWith(EXTNAME_JS)) { + const returnInfoJs = isJsSourceFile(file); + expect(returnInfoJs).to.be.true; + } + } + }); + + mocha.it('12-5: test isJsSourceFile under hot fix debug', function () { + projectConfig.buildMode = DEBUG; + const file = TEST_JS; + const returnInfo = isJsSourceFile(file); + expect(returnInfo).to.be.true; + const fileTs = TEST_TS; + const returnInfoTs = isJsSourceFile(fileTs); + expect(returnInfoTs).to.be.false; + }); + + mocha.it('12-6: test isJsSourceFile under hot fix release', function () { + projectConfig.buildMode = RELEASE; + const file = TEST_JS; + const returnInfo = isJsSourceFile(file); + expect(returnInfo).to.be.true; + const fileTs = TEST_TS; + const returnInfoTs = isJsSourceFile(fileTs); + expect(returnInfoTs).to.be.false; + }); + + mocha.it('13-1: test isJsonSourceFile under build debug', function () { + this.rollup.build(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS) || file.endsWith(EXTNAME_JS)) { + const returnInfo = isJsonSourceFile(file); + expect(returnInfo).to.be.false; + } + if (file.endsWith(EXTNAME_JSON)) { + const returnInfoJson = isJsonSourceFile(file); + expect(returnInfoJson).to.be.true; + } + } + }); + + mocha.it('13-2: test isJsonSourceFile under build release', function () { + this.rollup.build(RELEASE); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS) || file.endsWith(EXTNAME_JS)) { + const returnInfo = isJsonSourceFile(file); + expect(returnInfo).to.be.false; + } + if (file.endsWith(EXTNAME_JSON)) { + const returnInfoJson = isJsonSourceFile(file); + expect(returnInfoJson).to.be.true; + } + } + }); + + mocha.it('13-3: test isJsonSourceFile under preview debug', function () { + this.rollup.preview(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS) || file.endsWith(EXTNAME_JS)) { + const returnInfo = isJsonSourceFile(file); + expect(returnInfo).to.be.false; + } + if (file.endsWith(EXTNAME_JSON)) { + const returnInfoJson = isJsonSourceFile(file); + expect(returnInfoJson).to.be.true; + } + } + }); + + mocha.it('13-4: test isJsonSourceFile under hot reload debug', function () { + this.rollup.hotReload(); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const file of this.mockfileList) { + if (file.endsWith(EXTNAME_TS) || file.endsWith(EXTNAME_ETS) || file.endsWith(EXTNAME_JS)) { + const returnInfo = isJsonSourceFile(file); + expect(returnInfo).to.be.false; + } + if (file.endsWith(EXTNAME_JSON)) { + const returnInfoJson = isJsonSourceFile(file); + expect(returnInfoJson).to.be.true; + } + } + }); + + mocha.it('13-5: test isJsonSourceFile under hot fix debug', function () { + projectConfig.buildMode = DEBUG; + const file = TEST_TS; + const returnInfo = isJsonSourceFile(file); + expect(returnInfo).to.be.false; + const fileJson = TEST_JSON; + const returnInfoJson = isJsonSourceFile(fileJson); + expect(returnInfoJson).to.be.true; + }); + + mocha.it('13-6: test isJsonSourceFile under hot fix release', function () { + projectConfig.buildMode = RELEASE; + const file = TEST_TS; + const returnInfo = isJsonSourceFile(file); + expect(returnInfo).to.be.false; + const fileJson = TEST_JS; + const returnInfoJson = isJsonSourceFile(fileJson); + expect(returnInfoJson).to.be.false; + }); }); \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/mock/class_mock/module_hotfix_mode_mock.ts b/compiler/test/ark_compiler_ut/mock/class_mock/module_hotfix_mode_mock.ts deleted file mode 100644 index 3f2855296..000000000 --- a/compiler/test/ark_compiler_ut/mock/class_mock/module_hotfix_mode_mock.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use rollupObject file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { ModuleHotfixMode } from '../../../../lib/fast_build/ark_compiler/module/module_hotfix_mode'; - -class ModuleHotfixModeMock extends ModuleHotfixMode { - generateEs2AbcCmdForHotfixMock() { - this.generateEs2AbcCmdForHotfix(); - } -} - -export default ModuleHotfixModeMock; diff --git a/compiler/test/ark_compiler_ut/mock/class_mock/module_mode_mock.ts b/compiler/test/ark_compiler_ut/mock/class_mock/module_mode_mock.ts index 3b605d3c2..fe1a3dc0c 100644 --- a/compiler/test/ark_compiler_ut/mock/class_mock/module_mode_mock.ts +++ b/compiler/test/ark_compiler_ut/mock/class_mock/module_mode_mock.ts @@ -28,14 +28,13 @@ import { } from '../../../../lib/fast_build/ark_compiler/module/module_mode'; import { changeFileExtension } from '../../../../lib/fast_build/ark_compiler/utils'; import { META } from '../rollup_mock/common'; - class ModuleModeMock extends ModuleMode { - collectModuleFileListMock(rollupObject: any) { + collectModuleFileListMock(rollupObject: object) { const fileList = Array.from(rollupObject.getModuleIds()); this.collectModuleFileList(rollupObject, fileList); } - addModuleInfoItemMock(rollupObject: any, isCommonJs: boolean, extName: string) { + addModuleInfoItemMock(rollupObject: object, isCommonJs: boolean, extName: string) { const mockFileList = rollupObject.getModuleIds(); for (const filePath of mockFileList) { if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { @@ -101,10 +100,10 @@ class ModuleModeMock extends ModuleMode { return false; } - checkGetPackageEntryInfo(rollup: any) { - this.pkgEntryInfos = new Map() - const mockfileList = rollup.getModuleIds() - for (const filePath of mockfileList) { + checkGetPackageEntryInfo(rollup: object) { + this.pkgEntryInfos = new Map(); + const mockFileList = rollup.getModuleIds(); + for (const filePath of mockFileList) { if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { const moduleInfos = rollup.getModuleInfo(filePath); moduleInfos.setIsLocalDependency(false); diff --git a/compiler/test/ark_compiler_ut/mock/class_mock/module_source_files_mock.ts b/compiler/test/ark_compiler_ut/mock/class_mock/module_source_files_mock.ts index 95a33f385..4d7eff3ef 100644 --- a/compiler/test/ark_compiler_ut/mock/class_mock/module_source_files_mock.ts +++ b/compiler/test/ark_compiler_ut/mock/class_mock/module_source_files_mock.ts @@ -17,19 +17,19 @@ import { ModuleSourceFile } from '../../../../lib/fast_build/ark_compiler/module import { GEN_ABC_PLUGIN_NAME } from '../../../../lib/fast_build/ark_compiler/common/ark_define'; class ModuleSourceFileMock extends ModuleSourceFile { - projectConfig: any; - logger: any; + projectConfig: object; + logger: object; - initPluginEnvMock(rollup: any) { + initPluginEnvMock(rollup: object) { this.projectConfig = Object.assign(rollup.share.arkProjectConfig, rollup.share.projectConfig); this.logger = rollup.share.getLogger(GEN_ABC_PLUGIN_NAME); } - testProcessJsModuleRequest(rollup: any) { + testProcessJsModuleRequest(rollup: object) { this.processJsModuleRequest(rollup); } - testProcessTransformedJsModuleRequest(rollup: any) { + testProcessTransformedJsModuleRequest(rollup: object) { this.processTransformedJsModuleRequest(rollup); } } diff --git a/compiler/test/ark_compiler_ut/mock/rollup_mock/common.ts b/compiler/test/ark_compiler_ut/mock/rollup_mock/common.ts index 85a292057..02847dc89 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/common.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/common.ts @@ -32,13 +32,14 @@ export const CMD_DEBUG_INFO: string = '--debug-info'; export const NODE: string = 'node'; export const META: string = 'meta'; -export const ENTRYABILITY_TS_PATH_DEFAULT: string = '/src/main/ets/entryability/EntryAbility.ts'; -export const ENTRYABILITY_JS_PATH_DEFAULT: string = '/src/main/ets/entryability/EntryAbility.js'; -export const INDEX_ETS_PATH_DEFAULT: string = '/src/main/ets/pages/Index.ets'; +export const ENTRYABILITY_TS_PATH_DEFAULT: string = '/src/entryability/EntryAbility.ts'; +export const ENTRYABILITY_JS_PATH_DEFAULT: string = '/src/entryability/EntryAbility.js'; +export const INDEX_ETS_PATH_DEFAULT: string = '/src/pages/Index.ets'; +export const INDEX_JS_PATH_DEFAULT: string = '/src/pages/Index.js'; -export const ENTRYABILITY_TS_RECORDNAME: string = '/entry/ets/entryability/EntryAbility'; -export const ENTRYABILITY_JS_RECORDNAME: string = '/entry/ets/entryability/EntryAbility'; -export const INDEX_ETS_RECORDNAME: string = '/entry/ets/pages/Index'; +export const ENTRYABILITY_TS_RECORDNAME: string = '/entry/src/entryability/EntryAbility'; +export const ENTRYABILITY_JS_RECORDNAME: string = '/entry/src/entryability/EntryAbility'; +export const INDEX_ETS_RECORDNAME: string = '/entry/src/pages/Index'; export const EXTNAME_MAP: string = '.map'; export const ENTRYABILITY_TS_PATH: string = '/entryability/EntryAbility.ts'; @@ -47,8 +48,8 @@ export const ENTRYABILITY_TS: string = 'EntryAbility.ts'; export const INDEX_ETS: string = 'Index.ets'; export const OH_UIABILITY: string = '@ohos:app.ability.UIAbility'; export const OH_HILOG: string = '@ohos:hilog'; -export const OHURL_RES: string = '@bundle:com.example.app/entry/ets/pages/Index'; -export const OHURL_SHAREDLIBRARY: string = "@bundle:UtTestApplication/sharedLibrary/ets/index" +export const OHURL_RES: string = '@bundle:com.example.app/entry/src/pages/Index'; +export const OHURL_SHAREDLIBRARY: string = "@bundle:UtTestApplication/sharedLibrary/ets/index"; export const FILE: string = 'file'; export const SOURCE: string = 'sources'; @@ -61,5 +62,6 @@ export const JSONSTRING: string = `{"mCompact":false,"mDisableHilog":false,"mDis export const MODULES: string = 'oh-modules'; export const LOADER_AOTMODE: string = 'loader_aotMode.json'; export const UPDATESOURCEMAP: string = 'updateSourceMap.json'; -export const ETS: string = "\"/**\\n * Copyright (c)'@ohos:app.ability.UIAbility'\\n * Licensed under t'@ohos:hilog'ense, Version 2.0 (the \\\"License\\\");\\n * you may not use this file except in compliance with the License.\\n * You may obtain a copy of the License at\\n *\\n * http://www.apache.org/licenses/LICENSE-2.0\\n *\\n * Unless required by applicable law or agreed to in writing, software\\n * distributed under the License is distributed on an \\\"AS IS\\\" BASIS,\\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\\n * See the License for the specific language governing permissions and\\n * limitations under the License.\\n */\\n@Entry\\n@Component\\nstruct Index {\\n @State message: string = 'Hello World'\\n\\n build() {\\n Row() {\\n Column() {\\n Text(this.message)\\n .fontSize(50)\\n .fontWeight(FontWeight.Bold)\\n }\\n .width('100%')\\n }\\n .height('100%')\\n }\\n}\""; -export const TS: string = "\"/**\\r\\n * Copyright ('@ohos:app.ability.UIAbility'd.\\r\\n * Licensed und'@ohos:hilog' License, Version 2.0 (the \\\"License\\\");\\r\\n * you may not use this file except in compliance with the License.\\r\\n * You may obtain a copy of the License at\\r\\n *\\r\\n * http://www.apache.org/licenses/LICENSE-2.0\\r\\n *\\r\\n * Unless required by applicable law or agreed to in writing, software\\r\\n * distributed under the License is distributed on an \\\"AS IS\\\" BASIS,\\r\\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\\r\\n * See the License for the specific language governing permissions and\\r\\n * limitations under the License.\\r\\n */\\r\\nimport UIAbility from '@ohos.app.ability.UIAbility';\\r\\nimport hilog from '@ohos.hilog';\\r\\nimport window from '@ohos.window';\\r\\n\\r\\nexport default class EntryAbility extends UIAbility {\\r\\n onCreate(want, launchParam) {\\r\\n hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');\\r\\n }\\r\\n\\r\\n onDestroy() {\\r\\n hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');\\r\\n }\\r\\n\\r\\n onWindowStageCreate(windowStage: window.WindowStage) {\\r\\n // Main window is created, set main page for this ability\\r\\n hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');\\r\\n\\r\\n windowStage.loadContent('pages/Index', (err, data) => {\\r\\n if (err.code) {\\r\\n hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');\\r\\n return;\\r\\n }\\r\\n hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');\\r\\n });\\r\\n }\\r\\n\\r\\n onWindowStageDestroy() {\\r\\n // Main window is destroyed, release UI related resources\\r\\n hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');\\r\\n }\\r\\n\\r\\n onForeground() {\\r\\n // Ability has brought to foreground\\r\\n hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');\\r\\n }\\r\\n\\r\\n onBackground() {\\r\\n // Ability has back to background\\r\\n hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');\\r\\n }\\r\\n}\\r\\n\""; \ No newline at end of file +export const ENTRYABILITY_JS: string = 'entry/src/entryability/EntryAbility.js'; +export const TEST: string = 'test'; +export const NEWFILE: string = 'newFile'; \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/mock/rollup_mock/module_info.ts b/compiler/test/ark_compiler_ut/mock/rollup_mock/module_info.ts index e62f208c2..24ef5c920 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/module_info.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/module_info.ts @@ -16,7 +16,7 @@ import { MODULE_ID_ROLLUP_PLACEHOLDER } from '../rollup_mock/path_config'; class Meta { - hostModulesInfo: Array; + hostModulesInfo: Array; moduleName: string; isLocalDependency: boolean; isNodeEntryFile: boolean; @@ -43,10 +43,10 @@ export class ModuleInfo { } setIsLocalDependency(value: boolean) { - this.meta.isLocalDependency = value + this.meta.isLocalDependency = value; } setIsNodeEntryFile(value: boolean) { - this.meta.isNodeEntryFile = value + this.meta.isNodeEntryFile = value; } setImportedIdMaps(path?: string) { diff --git a/compiler/test/ark_compiler_ut/mock/rollup_mock/path_config.ts b/compiler/test/ark_compiler_ut/mock/rollup_mock/path_config.ts index d22475b26..b244772c9 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/path_config.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/path_config.ts @@ -35,12 +35,40 @@ export const MERGERABC_PATH: string = '/build/bin/merge_abc'; export const JS2ABC_PATH: string = '/build/bin/js2abc'; export const AOTCOMPILER_PATH: string = '/build/bin/ark_aot_compiler'; export const ARKROOT_PATH: string = 'bin/ark'; +export const MODULE_TEST_PATH: string = `${PROJECT_ROOT}/testTsModuleRequest/src/main/ets/`; +export const TEST_TS: string = 'src/main/ets/pages/test.ts'; +export const TEST_ETS: string = 'src/main/ets/pages/test.ets'; +export const TEST_JS: string = 'src/main/ets/pages/test.js'; +export const TEST_JSON: string = 'src/main/ets/pages/test.json'; +export const SYMBOLMAP_MAP: string = 'entry/build/loader_out/ets/symbolMap.map'; +export const DEFAULT_ETS: string = 'entry/build/loader_out/ets'; +export const BUILD_INFO: string ='entry/build/filesInfo.txt'; +export const BUILD_NPM: string ='entry/build/npmEntries.txt'; +export const MODULES_ABC: string ='entry/build/modules.abc'; +export const PREVIEW_DEBUG_INFO: string ='entry/preview/filesInfo.txt'; +export const PREVIEW_DEBUG_NPM: string ='entry/preview/npmEntries.txt'; +export const PREVIEW_MODULES_ABC: string ='entry/preview/modules.abc'; +export const BUILD_CACHE: string ='entry/build/modules.cache'; +export const BUILD_RELEASE_CACHE: string ='entry/build/modules.cache'; +export const PREVIEW_DEBUG_CACHE: string ='entry/preview/modules.cache'; +export const DEBUG_INFO: string ="--debug-info"; +export const ENTRY_LIST: string ="--npm-module-entry-list"; +export const OUTPUT: string ="--output"; +export const FILE_THREADS: string ="--file-threads"; +export const MERGE_ABC: string ="--merge-abc"; +export const CACHE_FILE: string ="--cache-file"; +export const SIMBOL_TABLE: string ="--dump-symbol-table"; +export const TARGET_API_VERSION: string = "--target-api-version="; +export const TYPE_EXTRACTOR: string = "--type-extractor"; export const ARKCONFIG_TS2ABC_PATH: string = 'bin/ark/build/legacy_api8/src/index.js'; -export const EXPECT_SOURCEMAP_JSON: string = `${PROJECT_ROOT}/expect/sourceMaps.json`; -export const MOCK_CONFIG_PATH: string = "openharmony/mockconfig"; -export const PKG_MODULES_OHPM_HYPIUM: string = 'pkg_modules/.ohpm/@ohos+hypium@1.0.6/pkg_modules/@ohos/hypium'; - export const EXPECT_ENTRY_TS: string = `${PROJECT_ROOT}/expect/expect_EntryAbility.ts`; export const EXPECT_INDEX_ETS: string = `${PROJECT_ROOT}/expect/expect_Index.ets`; -export const MODULE_TEST_PATH: string = `${PROJECT_ROOT}/testTsModuleRequest/src/main/ets/`; \ No newline at end of file +export const EXPECT_SOURCEMAP_JSON: string = `${PROJECT_ROOT}/expect/sourceMaps.json`; +export const EXPECT_TO_JS: string = `${PROJECT_ROOT}/expect/expectToJS.json`; +export const TERSER_PROCESSED_EXPECTED_CODE: string = `${PROJECT_ROOT}/expect/terser_processed_expected_code.txt`; + +export const PKG_MODULES_OHPM_HYPIUM: string = 'pkg_modules/.ohpm/@ohos+hypium@1.0.6/pkg_modules/@ohos/hypium'; +export const PKG_MODULES_ENTRY: string = 'pkg_modules@entry'; +export const PKG_MODULES_OHPM_HYPIUM_SHORT: string = 'pkg_modules/@ohos/hypium'; +export const MOCK_CONFIG_PATH: string = "openharmony/mockconfig"; diff --git a/compiler/test/ark_compiler_ut/mock/rollup_mock/project_config.ts b/compiler/test/ark_compiler_ut/mock/rollup_mock/project_config.ts index 455778e68..b7ee8eceb 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/project_config.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/project_config.ts @@ -34,22 +34,22 @@ import { interface IArkProjectConfig { projectRootPath: string, - modulePathMap: any, - isOhosTest: any, - oldMapFilePath?: any, + modulePathMap: object, + isOhosTest: object, + oldMapFilePath?: object, processTs: boolean, pandaMode: string, - anBuildOutPut?: any, - anBuildMode?: any, - apPath?: any, - nodeModulesPath?: any, - harNameOhmMap: any, + anBuildOutPut?: object, + anBuildMode?: object, + apPath?: object, + nodeModulesPath?: object, + harNameOhmMap: object, minPlatformVersion: number, moduleName: string, bundleName: string, - hotReload: any, - patchAbcPath: any, - changedFileList: any, + hotReload: object, + patchAbcPath: object, + changedFileList: object, compileMode: string } @@ -91,7 +91,7 @@ class ProjectConfig { resolveModulePaths: Array; compileHar: boolean; compileShared: boolean; - moduleRootPath: any; + moduleRootPath: object; buildPath: string; deviceType?: string; @@ -102,10 +102,11 @@ class ProjectConfig { img2bin?: string; projectProfilePath?: string; logLevel?: string; - stageRouterConfig?: Array; + stageRouterConfig?: Array; port?: string; aceSoPath?: string; mockParams?: object; + projectRootPath: string; constructor(buildMode: string) { this.watchMode = 'false'; @@ -146,16 +147,17 @@ class ProjectConfig { this.apPath = ''; this.aceModuleJsonPath = `${proPath}/${this.entryModuleName}/${mode}/module.json`; this.appResource = `${proPath}/${this.entryModuleName}/${mode}/res/default/ResourceTable.txt`; - this.aceModuleRoot = `${proPath}/${this.entryModuleName}/src/main/ets`; + this.aceModuleRoot = `${proPath}/${this.entryModuleName}/src`; this.aceSuperVisualPath = `${proPath}/${this.entryModuleName}/src/main/supervisual`; this.aceBuildJson = `${proPath}/${this.entryModuleName}/${mode}/loader.json`; this.cachePath = `${proPath}/${this.entryModuleName}/${mode}`; this.aceModuleBuild = `${proPath}/${this.entryModuleName}/${mode}`; - this.projectPath = `${proPath}/${this.entryModuleName}/src/main/ets`; + this.projectPath = `${proPath}/${this.entryModuleName}/src`; this.moduleRootPath = undefined; this.buildPath = `${proPath}/${this.entryModuleName}/${mode}`; this.patchAbcPath = `${proPath}/${this.entryModuleName}/${mode}/hotReload`; - this.DynamicImportpath = `${this.modulePath}/DynamicImport.ets` + this.DynamicImportpath = `${this.modulePath}/DynamicImport.ets`; + this.projectRootPath = `${proPath}`; if (this.isPreview) { this.previewUniqueConfig(); diff --git a/compiler/test/ark_compiler_ut/mock/rollup_mock/rollup_plugin_mock.ts b/compiler/test/ark_compiler_ut/mock/rollup_mock/rollup_plugin_mock.ts index d9490a21b..958ebbe7d 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/rollup_plugin_mock.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/rollup_plugin_mock.ts @@ -30,7 +30,7 @@ import { MODULE_ID_ROLLUP_PLACEHOLDER, NODE_MODULES_PATH } from "./path_config"; -import { scanFiles } from "../../utils/path_utils"; +import { scanFiles } from "../../utils/utils"; import { IArkProjectConfig } from "./project_config"; import { ESMODULE, @@ -42,7 +42,7 @@ import { class RollUpPluginMock { cache: Cache; meta: object = { rollupVersion: '3.10.0', watchMode: false }; - moduleIds: any; + moduleIds: object; share: Share; moduleInfos: Array; @@ -127,9 +127,16 @@ class RollUpPluginMock { private mockCheckArkCompilerCacheInfo(): void { const metaInfos = [ - SDK_VERSION, SDK_VERSION, RUNTIME_OS_OPENHARMONY, `/OpenHarmony/Sdk/${SDK_VERSION}/ets/build-tools/app`, - ETS_LOADER_VERSION, RELEASE, BUNDLE_NAME_DEFAULT, - MODULE_NAME_HASH_DEFAULT, 'null_aotCompileMode', 'null_apPath' + SDK_VERSION, + SDK_VERSION, + RUNTIME_OS_OPENHARMONY, + `/OpenHarmony/Sdk/${SDK_VERSION}/ets/build-tools/app`, + ETS_LOADER_VERSION, + RELEASE, + BUNDLE_NAME_DEFAULT, + MODULE_NAME_HASH_DEFAULT, + 'null_aotCompileMode', + 'null_apPath' ] const metaInfo = metaInfos.join(':'); this.cache.set(IS_CACHE_INVALID, true); diff --git a/compiler/test/ark_compiler_ut/mock/rollup_mock/share.ts b/compiler/test/ark_compiler_ut/mock/rollup_mock/share.ts index 267e96514..2d5c7d8ee 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/share.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/share.ts @@ -37,7 +37,6 @@ class Logger { } public error(color: string, errormsg: string, reset: string) { - console.error(`${color}${this.prefix}: ${JSON.stringify(errormsg)}${reset}`); this.messsage = color.toString(); } @@ -46,7 +45,7 @@ class Logger { } - public static getLogger(prefix): any { + public static getLogger(prefix): object { for (const instance of Logger.instances) { if (instance.getPrefix() == prefix) { return instance; @@ -55,7 +54,7 @@ class Logger { } public static createLogger(prefix) { const logger = new Logger(prefix); - Logger.instances.push(logger) + Logger.instances.push(logger); return logger; } } @@ -73,7 +72,7 @@ class Share { this.projectConfig = new ProjectConfig(buildMode); } - public throwArkTsCompilerError(error: any) { + public throwArkTsCompilerError(error: object) { console.error(JSON.stringify(error)); } @@ -87,7 +86,7 @@ class Share { public scan(testcase: string) { if (!testcase) { - return + return; } this.projectConfig.scan(testcase); this.symlinkMap[`${this.projectConfig.projectTopDir}/${OH_MODULES_OHPM_HYPIUM}`] = [ diff --git a/compiler/test/ark_compiler_ut/module/module_hotfix_mode.test.ts b/compiler/test/ark_compiler_ut/module/module_hotfix_mode.test.ts new file mode 100644 index 000000000..8d85d1f18 --- /dev/null +++ b/compiler/test/ark_compiler_ut/module/module_hotfix_mode.test.ts @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use rollupObject file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +import { expect } from 'chai'; +import mocha from 'mocha'; + +import RollUpPluginMock from '../mock/rollup_mock/rollup_plugin_mock'; +import { ModuleHotfixMode } from '../../../lib/fast_build/ark_compiler/module/module_hotfix_mode'; +import { RELEASE } from '../../../lib/fast_build/ark_compiler/common/ark_define'; +import { + ES2ABC_PATH, + DEBUG_INFO, + BUILD_INFO, + BUILD_NPM, + MODULES_ABC, + ENTRY_LIST, + OUTPUT, + FILE_THREADS, + MERGE_ABC, + TARGET_API_VERSION +} from '../mock/rollup_mock/path_config'; +import { cpus } from '../utils/utils'; + +function checkCmdArgs(cmdArgs: Array, compatibleSdkVersion: string) : void { + const fileThreads: number = cpus(); + + expect(cmdArgs[0].indexOf(BUILD_INFO) > 0).to.be.true; + expect(cmdArgs[1] === ENTRY_LIST).to.be.true; + expect(cmdArgs[2].indexOf(BUILD_NPM) > 0).to.be.true; + expect(cmdArgs[3] === OUTPUT).to.be.true; + expect(cmdArgs[4].indexOf(MODULES_ABC) > 0).to.be.true; + expect(cmdArgs[5] === FILE_THREADS).to.be.true; + expect(cmdArgs[6] === `\"${fileThreads}\"`).to.be.true; + expect(cmdArgs[7].indexOf(compatibleSdkVersion) > 0).to.be.true; + expect(cmdArgs[8] === MERGE_ABC).to.be.true; +} + +mocha.describe('test module_hotfix_mode file api', function () { + mocha.beforeEach(function () { + this.rollup = new RollUpPluginMock(); + }); + + mocha.afterEach(() => { + delete this.rollup; + }); + + mocha.it('1-1: test generateEs2AbcCmdForHotfix under hot fix debug', function () { + this.rollup.build(); + const moduleMode = new ModuleHotfixMode(this.rollup); + moduleMode.generateEs2AbcCmdForHotfix(); + const compatibleSdkVersion = `${TARGET_API_VERSION}${this.rollup.share.projectConfig.compatibleSdkVersion}`; + expect(moduleMode.cmdArgs[0].indexOf(ES2ABC_PATH) > 0).to.be.true; + moduleMode.cmdArgs.shift(); + expect(moduleMode.cmdArgs[0] === DEBUG_INFO).to.be.true; + moduleMode.cmdArgs.shift(); + checkCmdArgs(moduleMode.cmdArgs,compatibleSdkVersion); + }); + + mocha.it('1-2: test generateEs2AbcCmdForHotfix under hot fix release', function () { + this.rollup.build(RELEASE); + const moduleMode = new ModuleHotfixMode(this.rollup); + moduleMode.generateEs2AbcCmdForHotfix(); + const compatibleSdkVersion = `${TARGET_API_VERSION}${this.rollup.share.projectConfig.compatibleSdkVersion}`; + expect(moduleMode.cmdArgs[0].indexOf(ES2ABC_PATH) > 0).to.be.true; + moduleMode.cmdArgs.shift(); + expect(moduleMode.cmdArgs[0] === DEBUG_INFO).to.be.false; + checkCmdArgs(moduleMode.cmdArgs,compatibleSdkVersion); + }); +}); \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/module/module_hotreload_mode.test.ts b/compiler/test/ark_compiler_ut/module/module_hotreload_mode.test.ts index 7131166bc..e48209bbe 100644 --- a/compiler/test/ark_compiler_ut/module/module_hotreload_mode.test.ts +++ b/compiler/test/ark_compiler_ut/module/module_hotreload_mode.test.ts @@ -33,6 +33,13 @@ import { EXTNAME_TS, EXTNAME_ETS } from '../../../lib/fast_build/ark_compiler/common/ark_define'; +import { + ES2ABC_PATH, + SYMBOLMAP_MAP, + DEFAULT_ETS, + DEBUG_INFO, + SIMBOL_TABLE +} from '../mock/rollup_mock/path_config'; import { ENTRYABILITY_TS_PATH, INDEX_ETS_PATH, @@ -51,6 +58,7 @@ mocha.describe('test module_hotreload_mode file api', function () { mocha.it('1-1: test updateSourceMapFromFileList under hot reload debug', function () { this.rollup.hotReload(); + this.rollup.share.projectConfig.oldMapFilePath = DEFAULT_ETS; const moduleMode = new ModuleHotreloadMode(this.rollup); const fileList = this.rollup.getModuleIds(); for (const filePath of fileList) { @@ -77,4 +85,15 @@ mocha.describe('test module_hotreload_mode file api', function () { delete newSourceMaps[key]; } }); + + mocha.it('2-1: test addHotReloadArgs under hot reload debug', function () { + this.rollup.hotReload(); + this.rollup.share.projectConfig.oldMapFilePath = DEFAULT_ETS; + const moduleMode = new ModuleHotreloadMode(this.rollup); + moduleMode.addHotReloadArgs(); + expect(moduleMode.cmdArgs[0].indexOf(ES2ABC_PATH) > 0).to.be.true; + expect(moduleMode.cmdArgs[1] === DEBUG_INFO).to.be.true; + expect(moduleMode.cmdArgs[2] === SIMBOL_TABLE).to.be.true; + expect(moduleMode.cmdArgs[3].indexOf(SYMBOLMAP_MAP) > 0).to.be.true; + }); }); \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/module/module_mode.test.ts b/compiler/test/ark_compiler_ut/module/module_mode.test.ts index 2ce3a6a60..21e378927 100644 --- a/compiler/test/ark_compiler_ut/module/module_mode.test.ts +++ b/compiler/test/ark_compiler_ut/module/module_mode.test.ts @@ -16,14 +16,14 @@ import { expect } from 'chai'; import mocha from 'mocha'; +import path from 'path'; +import { toUnixPath } from '../../../lib/utils'; import { newSourceMaps } from '../../../lib/fast_build/ark_compiler/transform'; -import { - EXPECT_SOURCEMAP_JSON, - PKG_MODULES_OHPM_HYPIUM -} from "../mock/rollup_mock/path_config"; import { RELEASE, + DEBUG, + MODULES_ABC, EXTNAME_TS, EXTNAME_JS, EXTNAME_ETS, @@ -31,17 +31,61 @@ import { } from '../../../lib/fast_build/ark_compiler/common/ark_define'; import RollUpPluginMock from '../mock/rollup_mock/rollup_plugin_mock'; import ModuleModeMock from '../mock/class_mock/module_mode_mock'; +import { ModuleHotreloadMode } from '../../../lib/fast_build/ark_compiler/module/module_hotreload_mode'; import { ENTRYABILITY_TS_PATH_DEFAULT, ENTRYABILITY_JS_PATH_DEFAULT, INDEX_ETS_PATH_DEFAULT, + INDEX_JS_PATH_DEFAULT, ENTRYABILITY_TS_RECORDNAME, ENTRYABILITY_JS_RECORDNAME, INDEX_ETS_RECORDNAME, PKG_MODULES, - ENTRY_MODULE_NAME_DEFAULT + ENTRY_MODULE_NAME_DEFAULT, + TEST, + NEWFILE } from '../mock/rollup_mock/common'; -import sleep from '../utils/sleep'; +import projectConfig from '../utils/processProjectConfig'; +import { + EXPECT_SOURCEMAP_JSON, + PKG_MODULES_OHPM_HYPIUM, + ES2ABC_PATH, + DEBUG_INFO, + BUILD_NPM, + BUILD_INFO, + PREVIEW_DEBUG_INFO, + PREVIEW_DEBUG_NPM, + DEFAULT_ETS, + PREVIEW_MODULES_ABC, + BUILD_CACHE, + PREVIEW_DEBUG_CACHE, + TEST_TS, + ENTRY_LIST, + OUTPUT, + FILE_THREADS, + MERGE_ABC, + CACHE_FILE, + TARGET_API_VERSION, + TYPE_EXTRACTOR +} from '../mock/rollup_mock/path_config'; +import { + scanFiles, + sleep, + cpus +} from "../utils/utils"; +import { AOT_FULL } from '../../../lib/pre_define'; + +function checkGenerateEs2AbcCmdExpect(cmdArgs: Array, compatibleSdkVersion: string): void { + const fileThreads: number = cpus(); + + expect(cmdArgs[0].indexOf(ES2ABC_PATH) > 0).to.be.true; + expect(cmdArgs[1] === ENTRY_LIST).to.be.true; + expect(cmdArgs[2] === OUTPUT).to.be.true; + expect(cmdArgs[3] === FILE_THREADS).to.be.true; + expect(cmdArgs[4] === `\"${fileThreads}\"`).to.be.true; + expect(cmdArgs[5] === MERGE_ABC).to.be.true; + expect(cmdArgs[6].indexOf(compatibleSdkVersion) > 0).to.be.true; +} mocha.describe('test module_mode file api', function () { mocha.before(function () { @@ -103,9 +147,8 @@ mocha.describe('test module_mode file api', function () { moduleInfo.recordName.indexOf(ENTRYABILITY_JS_RECORDNAME) > 0 || moduleInfo.recordName.indexOf(INDEX_ETS_RECORDNAME) > 0).to.be.true; - expect(moduleInfo.sourceFile.indexOf(ENTRYABILITY_TS_PATH_DEFAULT) > 0 || - moduleInfo.sourceFile.indexOf(ENTRYABILITY_JS_PATH_DEFAULT) > 0 || - moduleInfo.sourceFile.indexOf(INDEX_ETS_PATH_DEFAULT) > 0).to.be.true; + expect(moduleInfo.sourceFile.indexOf(ENTRYABILITY_JS_PATH_DEFAULT) > 0 || + moduleInfo.sourceFile.indexOf(INDEX_JS_PATH_DEFAULT) > 0).to.be.true; }); expect(moduleMode.pkgEntryInfos.size != 0).to.be.true; }); @@ -169,8 +212,8 @@ mocha.describe('test module_mode file api', function () { }); mocha.it('2-1-1: test addModuleInfoItem under build debug: isPackageModulesFile`s return is true', function () { - this.rollup.share.projectConfig.modulePath = this.rollup.share.projectConfig.projectPath; this.rollup.build(); + this.rollup.share.projectConfig.modulePath = this.rollup.share.projectConfig.projectPath; const moduleMode = new ModuleModeMock(this.rollup); moduleMode.projectConfig.packageDir = ENTRY_MODULE_NAME_DEFAULT; moduleMode.addModuleInfoItemMock(this.rollup, false, ''); @@ -202,12 +245,12 @@ mocha.describe('test module_mode file api', function () { }); }); - mocha.it('2-1-3: test addModuleInfoItem under build debug: extName is not null ', function () { + mocha.it('2-1-3: test addModuleInfoItem under build debug: extName is not null', function () { this.rollup.build(); const moduleMode = new ModuleModeMock(this.rollup); moduleMode.addModuleInfoItemMock(this.rollup, false, EXTNAME_TS); moduleMode.moduleInfos.forEach(value => { - expect(value.cacheFilePath.endsWith(EXTNAME_TS)).to.be.true + expect(value.cacheFilePath.endsWith(EXTNAME_TS)).to.be.true; }); }); @@ -306,13 +349,13 @@ mocha.describe('test module_mode file api', function () { expect(newSourceMaps[key] === moduleMode.cacheSourceMapObject[key]).to.be.true; } - newSourceMaps[ENTRYABILITY_TS_PATH_DEFAULT] = { "file": 'test' }; + newSourceMaps[ENTRYABILITY_TS_PATH_DEFAULT] = { FILE: TEST }; moduleMode.updateCachedSourceMapsMock(); for (const key in moduleMode.cacheSourceMapObject) { expect(newSourceMaps[key] === moduleMode.cacheSourceMapObject[key]).to.be.true; } - newSourceMaps[ENTRYABILITY_TS_PATH_DEFAULT] = { "file": 'test', "newFile": "newTest" }; + newSourceMaps[ENTRYABILITY_TS_PATH_DEFAULT] = { FILE: TEST, NEWFILE: NEWFILE }; moduleMode.updateCachedSourceMapsMock(); for (const key in moduleMode.cacheSourceMapObject) { expect(newSourceMaps[key] === moduleMode.cacheSourceMapObject[key]).to.be.true; @@ -493,7 +536,7 @@ mocha.describe('test module_mode file api', function () { this.rollup.share.projectConfig.packageDir = OH_MODULES; const moduleMode = new ModuleModeMock(this.rollup); moduleMode.checkGetPackageEntryInfo(this.rollup); - expect(moduleMode.pkgEntryInfos.size !== 0).to.be.true + expect(moduleMode.pkgEntryInfos.size !== 0).to.be.true; }); mocha.it('8-1: test buildModuleSourceMapInfo under build debug', async function () { @@ -571,4 +614,200 @@ mocha.describe('test module_mode file api', function () { expect(pkgname === PKG_MODULES_OHPM_HYPIUM).to.be.true; } }); + + mocha.it('10-1: test generateEs2AbcCmd under build debug', function () { + this.rollup.build(); + this.rollup.share.projectConfig.oldMapFilePath = DEFAULT_ETS; + const moduleMode = new ModuleHotreloadMode(this.rollup); + const compatibleSdkVersion = `${TARGET_API_VERSION}${this.rollup.share.projectConfig.compatibleSdkVersion}`; + moduleMode.projectConfig.anBuildMode = AOT_FULL; + moduleMode.generateEs2AbcCmd(); + + expect(moduleMode.cmdArgs[1] === DEBUG_INFO).to.be.true; + moduleMode.cmdArgs.splice(1, 1); + expect(moduleMode.cmdArgs[1].indexOf(BUILD_INFO) > 0).to.be.true; + moduleMode.cmdArgs.splice(1, 1); + expect(moduleMode.cmdArgs[2].indexOf(BUILD_NPM) > 0).to.be.true; + moduleMode.cmdArgs.splice(2, 1); + expect(moduleMode.cmdArgs[3].indexOf(MODULES_ABC) > 0).to.be.true; + moduleMode.cmdArgs.splice(3, 1); + expect(moduleMode.cmdArgs[7] === TYPE_EXTRACTOR).to.be.true; + moduleMode.cmdArgs.splice(7, 1); + checkGenerateEs2AbcCmdExpect(moduleMode.cmdArgs, compatibleSdkVersion); + }); + + mocha.it('10-2: test generateEs2AbcCmd under build release', function () { + this.rollup.build(RELEASE); + this.rollup.share.projectConfig.oldMapFilePath = DEFAULT_ETS; + const moduleMode = new ModuleHotreloadMode(this.rollup); + const compatibleSdkVersion = `${TARGET_API_VERSION}${this.rollup.share.projectConfig.compatibleSdkVersion}`; + moduleMode.generateEs2AbcCmd(); + + expect(moduleMode.cmdArgs[1] === DEBUG_INFO).to.be.false; + expect(moduleMode.cmdArgs[1].indexOf(BUILD_INFO) > 0).to.be.true; + moduleMode.cmdArgs.splice(1, 1); + expect(moduleMode.cmdArgs[2].indexOf(BUILD_NPM) > 0).to.be.true; + moduleMode.cmdArgs.splice(2, 1); + expect(moduleMode.cmdArgs[3].indexOf(MODULES_ABC) > 0).to.be.true; + moduleMode.cmdArgs.splice(3, 1); + checkGenerateEs2AbcCmdExpect(moduleMode.cmdArgs, compatibleSdkVersion); + }); + + mocha.it('10-3: test generateEs2AbcCmd under preview debug', function () { + this.rollup.preview(); + this.rollup.share.projectConfig.oldMapFilePath = DEFAULT_ETS; + const moduleMode = new ModuleHotreloadMode(this.rollup); + const compatibleSdkVersion = `${TARGET_API_VERSION}${this.rollup.share.projectConfig.compatibleSdkVersion}`; + moduleMode.generateEs2AbcCmd(); + + expect(moduleMode.cmdArgs[1] === DEBUG_INFO).to.be.true; + moduleMode.cmdArgs.splice(1, 1); + expect(moduleMode.cmdArgs[1].indexOf(PREVIEW_DEBUG_INFO) > 0).to.be.true; + moduleMode.cmdArgs.splice(1, 1); + expect(moduleMode.cmdArgs[2].indexOf(PREVIEW_DEBUG_NPM) > 0).to.be.true; + moduleMode.cmdArgs.splice(2, 1); + expect(moduleMode.cmdArgs[3].indexOf(PREVIEW_MODULES_ABC) > 0).to.be.true; + moduleMode.cmdArgs.splice(3, 1); + checkGenerateEs2AbcCmdExpect(moduleMode.cmdArgs, compatibleSdkVersion); + }); + + mocha.it('11-1: test addCacheFileArgs under build debug', function () { + this.rollup.build(); + this.rollup.share.projectConfig.oldMapFilePath = DEFAULT_ETS; + const moduleMode = new ModuleHotreloadMode(this.rollup); + moduleMode.addCacheFileArgs(); + + expect(moduleMode.cmdArgs[0].indexOf(ES2ABC_PATH) > 0).to.be.true; + expect(moduleMode.cmdArgs[1] === DEBUG_INFO).to.be.true; + expect(moduleMode.cmdArgs[2] === CACHE_FILE).to.be.true; + expect(moduleMode.cmdArgs[3].indexOf(BUILD_CACHE) > 0).to.be.true; + }); + + mocha.it('11-2: test addCacheFileArgs under build release', function () { + this.rollup.build(RELEASE); + this.rollup.share.projectConfig.oldMapFilePath = DEFAULT_ETS; + const moduleMode = new ModuleHotreloadMode(this.rollup); + moduleMode.addCacheFileArgs(); + + expect(moduleMode.cmdArgs[0].indexOf(ES2ABC_PATH) > 0).to.be.true; + expect(moduleMode.cmdArgs[1] === DEBUG_INFO).to.be.false; + expect(moduleMode.cmdArgs[1] === CACHE_FILE).to.be.true; + expect(moduleMode.cmdArgs[2].indexOf(BUILD_CACHE) > 0).to.be.true; + }); + + mocha.it('11-3: test addCacheFileArgs under preview debug', function () { + this.rollup.preview(); + this.rollup.share.projectConfig.oldMapFilePath = DEFAULT_ETS; + const moduleMode = new ModuleHotreloadMode(this.rollup); + moduleMode.addCacheFileArgs(); + + expect(moduleMode.cmdArgs[0].indexOf(ES2ABC_PATH) > 0).to.be.true; + expect(moduleMode.cmdArgs[1] === DEBUG_INFO).to.be.true; + expect(moduleMode.cmdArgs[2] === CACHE_FILE).to.be.true; + expect(moduleMode.cmdArgs[3].indexOf(PREVIEW_DEBUG_CACHE) > 0).to.be.true; + }); + + mocha.it('11-4: test addCacheFileArgs under hot reload debug', function () { + this.rollup.hotReload(); + this.rollup.share.projectConfig.oldMapFilePath = DEFAULT_ETS; + const moduleMode = new ModuleHotreloadMode(this.rollup); + moduleMode.addCacheFileArgs(); + + expect(moduleMode.cmdArgs[0].indexOf(ES2ABC_PATH) > 0).to.be.true; + expect(moduleMode.cmdArgs[1] === DEBUG_INFO).to.be.true; + expect(moduleMode.cmdArgs[2] === CACHE_FILE).to.be.true; + expect(moduleMode.cmdArgs[3].indexOf(BUILD_CACHE) > 0).to.be.true; + }); + + mocha.it('12-1: test genFileCachePath under build debug', function () { + this.rollup.build(); + const moduleMode = new ModuleModeMock(this.rollup); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + const sufStr = + toUnixPath(filePath).replace(toUnixPath(this.rollup.share.projectConfig.projectRootPath), ''); + const returnInfo = + moduleMode.genFileCachePath(filePath, this.rollup.share.projectConfig.projectRootPath, + this.rollup.share.projectConfig.cachePath); + expect(returnInfo === path.join(this.rollup.share.projectConfig.cachePath, sufStr)).to.be.true; + } + } + }); + + mocha.it('12-2: test genFileCachePath under build release', function () { + this.rollup.build(RELEASE); + const moduleMode = new ModuleModeMock(this.rollup); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + const sufStr = + toUnixPath(filePath).replace(toUnixPath(this.rollup.share.projectConfig.projectRootPath), ''); + const returnInfo = + moduleMode.genFileCachePath(filePath, this.rollup.share.projectConfig.projectRootPath, + this.rollup.share.projectConfig.cachePath); + expect(returnInfo === path.join(this.rollup.share.projectConfig.cachePath, sufStr)).to.be.true; + } + } + }); + + mocha.it('12-3: test genFileCachePath under preview debug', function () { + this.rollup.preview(); + const moduleMode = new ModuleModeMock(this.rollup); + const allFiles = new Set(); + scanFiles(this.rollup.share.projectConfig.modulePath, allFiles); + this.mockfileList = allFiles.values(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + const sufStr = + toUnixPath(filePath).replace(toUnixPath(this.rollup.share.projectConfig.projectRootPath), ''); + const returnInfo = + moduleMode.genFileCachePath(filePath, this.rollup.share.projectConfig.projectRootPath, + this.rollup.share.projectConfig.cachePath); + expect(returnInfo === path.join(this.rollup.share.projectConfig.cachePath, sufStr)).to.be.true; + } + } + }); + + mocha.it('12-4: test genFileCachePath under hot reload debug', function () { + this.rollup.hotReload(); + const moduleMode = new ModuleModeMock(this.rollup); + this.mockfileList = this.rollup.getModuleIds(); + for (const filePath of this.mockfileList) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS) || filePath.endsWith(EXTNAME_JS)) { + const sufStr = + toUnixPath(filePath).replace(toUnixPath(this.rollup.share.projectConfig.projectRootPath), ''); + const returnInfo = + moduleMode.genFileCachePath(filePath, this.rollup.share.projectConfig.projectRootPath, + this.rollup.share.projectConfig.cachePath); + expect(returnInfo === path.join(this.rollup.share.projectConfig.cachePath, sufStr)).to.be.true; + } + } + }); + + mocha.it('12-5: test genFileCachePath under hot fix debug', function () { + this.rollup.build(); + this.rollup.share.projectConfig.oldMapFilePath = DEFAULT_ETS; + const cachePath = projectConfig.cachePath + DEBUG; + const moduleMode = new ModuleModeMock(this.rollup); + const filePath = `${projectConfig.projectRootPath}/${TEST_TS}`; + const sufStr = toUnixPath(filePath).replace(toUnixPath(projectConfig.projectRootPath), ''); + const returnInfo = moduleMode.genFileCachePath(filePath, projectConfig.projectRootPath, cachePath); + expect(returnInfo === path.join(cachePath, sufStr)).to.be.true; + }); + + mocha.it('12-6: test genFileCachePath under hot fix release', function () { + this.rollup.build(RELEASE); + this.rollup.share.projectConfig.oldMapFilePath = DEFAULT_ETS; + const cachePath = projectConfig.cachePath + RELEASE; + const moduleMode = new ModuleModeMock(this.rollup); + const filePath = `${projectConfig.projectRootPath}/${TEST_TS}`; + const sufStr = toUnixPath(filePath).replace(toUnixPath(projectConfig.projectRootPath), ''); + const returnInfo = moduleMode.genFileCachePath(filePath, projectConfig.projectRootPath, cachePath); + expect(returnInfo === path.join(cachePath, sufStr)).to.be.true; + }); }); \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/module/module_source_file.test.ts b/compiler/test/ark_compiler_ut/module/module_source_file.test.ts index db8d48a53..7015baa3c 100644 --- a/compiler/test/ark_compiler_ut/module/module_source_file.test.ts +++ b/compiler/test/ark_compiler_ut/module/module_source_file.test.ts @@ -26,7 +26,8 @@ import ModuleModeMock from '../mock/class_mock/module_mode_mock'; import { EXPECT_ENTRY_TS, EXPECT_INDEX_ETS, - MODULE_TEST_PATH + MODULE_TEST_PATH, + EXPECT_TO_JS } from '../mock/rollup_mock/path_config'; import { RELEASE, @@ -43,13 +44,11 @@ import { INDEX_ETS, OHURL_SHAREDLIBRARY, OH_UIABILITY, - OH_HILOG, - ETS, - TS + OH_HILOG } from '../mock/rollup_mock/common'; import projectConfig from '../utils/processProjectConfig'; import { ModuleInfo as ModuleInfoMock } from '../mock/rollup_mock/module_info'; -import { scanFiles } from "../utils/path_utils"; +import { scanFiles } from "../utils/utils"; import { newSourceMaps } from '../../../lib/fast_build/ark_compiler/transform'; const ROLLUP_IMPORT_NODE: string = 'ImportDeclaration'; @@ -418,7 +417,10 @@ mocha.describe('test module_source_file file api', function () { moduleInfo.setImportedIdMaps(); moduleInfo.setNodeImportDeclaration(); moduleSource.processTransformedJsModuleRequest(this.rollup); - expect(moduleSource.source === ETS || moduleSource.source === TS).to.be.true; + const json = fs.readFileSync(EXPECT_TO_JS, 'utf-8'); + const etsToJs = JSON.parse(json).expect_index_ets_to_js; + const tsToJs = JSON.parse(json).expect_entryability_ts_to_js; + expect(moduleSource.source === etsToJs || moduleSource.source === tsToJs).to.be.true; } } }); @@ -469,7 +471,10 @@ mocha.describe('test module_source_file file api', function () { moduleInfo.setImportedIdMaps(); moduleInfo.setNodeImportDeclaration(); moduleSource.processTransformedJsModuleRequest(this.rollup); - expect(moduleSource.source === ETS || moduleSource.source === TS).to.be.true; + const json = fs.readFileSync(EXPECT_TO_JS, 'utf-8'); + const etsToJs = JSON.parse(json).expect_index_ets_to_js; + const tsToJs = JSON.parse(json).expect_entryability_ts_to_js; + expect(moduleSource.source === etsToJs || moduleSource.source === tsToJs).to.be.true; } } }); @@ -489,7 +494,10 @@ mocha.describe('test module_source_file file api', function () { moduleInfo.setImportedIdMaps(); moduleInfo.setNodeImportDeclaration(); moduleSource.processTransformedJsModuleRequest(this.rollup); - expect(moduleSource.source === ETS || moduleSource.source === TS).to.be.true; + const json = fs.readFileSync(EXPECT_TO_JS, 'utf-8'); + const etsToJs = JSON.parse(json).expect_index_ets_to_js; + const tsToJs = JSON.parse(json).expect_entryability_ts_to_js; + expect(moduleSource.source === etsToJs || moduleSource.source === tsToJs).to.be.true; } } }); @@ -509,7 +517,10 @@ mocha.describe('test module_source_file file api', function () { moduleInfo.setImportedIdMaps(); moduleInfo.setNodeImportDeclaration(); moduleSource.processTransformedJsModuleRequest(this.rollup); - expect(moduleSource.source === ETS || moduleSource.source === TS).to.be.true; + const json = fs.readFileSync(EXPECT_TO_JS, 'utf-8'); + const etsToJs = JSON.parse(json).expect_index_ets_to_js; + const tsToJs = JSON.parse(json).expect_entryability_ts_to_js; + expect(moduleSource.source === etsToJs || moduleSource.source === tsToJs).to.be.true; } } }); diff --git a/compiler/test/ark_compiler_ut/testdata/expect/expectToJS.json b/compiler/test/ark_compiler_ut/testdata/expect/expectToJS.json new file mode 100644 index 000000000..43e17b4b4 --- /dev/null +++ b/compiler/test/ark_compiler_ut/testdata/expect/expectToJS.json @@ -0,0 +1,4 @@ +{ + "expect_index_ets_to_js": "\"/**\\n * Copyright (c)'@ohos:app.ability.UIAbility'\\n * Licensed under t'@ohos:hilog'ense, Version 2.0 (the \\\"License\\\");\\n * you may not use this file except in compliance with the License.\\n * You may obtain a copy of the License at\\n *\\n * http://www.apache.org/licenses/LICENSE-2.0\\n *\\n * Unless required by applicable law or agreed to in writing, software\\n * distributed under the License is distributed on an \\\"AS IS\\\" BASIS,\\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\\n * See the License for the specific language governing permissions and\\n * limitations under the License.\\n */\\n@Entry\\n@Component\\nstruct Index {\\n @State message: string = 'Hello World'\\n\\n build() {\\n Row() {\\n Column() {\\n Text(this.message)\\n .fontSize(50)\\n .fontWeight(FontWeight.Bold)\\n }\\n .width('100%')\\n }\\n .height('100%')\\n }\\n}\"", + "expect_entryability_ts_to_js": "\"/**\\r\\n * Copyright ('@ohos:app.ability.UIAbility'd.\\r\\n * Licensed und'@ohos:hilog' License, Version 2.0 (the \\\"License\\\");\\r\\n * you may not use this file except in compliance with the License.\\r\\n * You may obtain a copy of the License at\\r\\n *\\r\\n * http://www.apache.org/licenses/LICENSE-2.0\\r\\n *\\r\\n * Unless required by applicable law or agreed to in writing, software\\r\\n * distributed under the License is distributed on an \\\"AS IS\\\" BASIS,\\r\\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\\r\\n * See the License for the specific language governing permissions and\\r\\n * limitations under the License.\\r\\n */\\r\\nimport UIAbility from '@ohos.app.ability.UIAbility';\\r\\nimport hilog from '@ohos.hilog';\\r\\nimport window from '@ohos.window';\\r\\n\\r\\nexport default class EntryAbility extends UIAbility {\\r\\n onCreate(want, launchParam) {\\r\\n hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');\\r\\n }\\r\\n\\r\\n onDestroy() {\\r\\n hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');\\r\\n }\\r\\n\\r\\n onWindowStageCreate(windowStage: window.WindowStage) {\\r\\n // Main window is created, set main page for this ability\\r\\n hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');\\r\\n\\r\\n windowStage.loadContent('pages/Index', (err, data) => {\\r\\n if (err.code) {\\r\\n hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');\\r\\n return;\\r\\n }\\r\\n hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');\\r\\n });\\r\\n }\\r\\n\\r\\n onWindowStageDestroy() {\\r\\n // Main window is destroyed, release UI related resources\\r\\n hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');\\r\\n }\\r\\n\\r\\n onForeground() {\\r\\n // Ability has brought to foreground\\r\\n hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');\\r\\n }\\r\\n\\r\\n onBackground() {\\r\\n // Ability has back to background\\r\\n hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');\\r\\n }\\r\\n}\\r\\n\"" +} \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/testdata/expect/terser_processed_expected_code.txt b/compiler/test/ark_compiler_ut/testdata/expect/terser_processed_expected_code.txt new file mode 100644 index 000000000..927e7a0ca --- /dev/null +++ b/compiler/test/ark_compiler_ut/testdata/expect/terser_processed_expected_code.txt @@ -0,0 +1,28 @@ +import UIAbility from "@ohos:app.ability.UIAbility"; + +import hilog from "@ohos:hilog"; + +export default class EntryAbility extends UIAbility { + onCreate(o, i) { + hilog.info(0, "testTag", "%{public}s", "Ability onCreate"); + } + onDestroy() { + hilog.info(0, "testTag", "%{public}s", "Ability onDestroy"); + } + onWindowStageCreate(o) { + hilog.info(0, "testTag", "%{public}s", "Ability onWindowStageCreate"); + o.loadContent("pages/Index", ((o, i) => { + var t, e; + o.code ? hilog.error(0, "testTag", "Failed to load the content. Cause: %{public}s", null !== (t = JSON.stringify(o)) && void 0 !== t ? t : "") : hilog.info(0, "testTag", "Succeeded in loading the content. Data: %{public}s", null !== (e = JSON.stringify(i)) && void 0 !== e ? e : ""); + })); + } + onWindowStageDestroy() { + hilog.info(0, "testTag", "%{public}s", "Ability onWindowStageDestroy"); + } + onForeground() { + hilog.info(0, "testTag", "%{public}s", "Ability onForeground"); + } + onBackground() { + hilog.info(0, "testTag", "%{public}s", "Ability onBackground"); + } +} \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/testdata/testcase_def/README_zh.md b/compiler/test/ark_compiler_ut/testdata/testcase_def/README_zh.md index 98f26fbc3..ecaa771ab 100644 --- a/compiler/test/ark_compiler_ut/testdata/testcase_def/README_zh.md +++ b/compiler/test/ark_compiler_ut/testdata/testcase_def/README_zh.md @@ -16,3 +16,4 @@ | entry/build/loader_aotMode.json | initArkProjectConfig | 应用于build模式(debug),给参数aceBuildJson赋值 | | entry/preview/loader.json | initArkProjectConfig | 应用于preview模式,给参数buildJsonInfo赋值 | | entry/build/hotReload/sourceMaps.map | updateSourceMapFromFileList | 应用于hotReload模式,读取SourceMap信息 | +| updateSourceMap.json | updateSourceMap | 应用于build模式,读取SourceMap信息 | \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/entry/src/entryability/EntryAbility.js b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/entry/src/entryability/EntryAbility.js new file mode 100644 index 000000000..84ef690e4 --- /dev/null +++ b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/entry/src/entryability/EntryAbility.js @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import UIAbility from '@ohos:app.ability.UIAbility'; +import hilog from '@ohos:hilog'; +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + windowStage.loadContent('pages/Index', (err, data) => { + var _a, _b; + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', (_a = JSON.stringify(err)) !== null && _a !== void 0 ? _a : ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', (_b = JSON.stringify(data)) !== null && _b !== void 0 ? _b : ''); + }); + } + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} +//# sourceMappingURL=EntryAbility.js.map \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/hotReload/sourceMaps.map b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/hotReload/sourceMaps.map index 4038d9ed9..d478c7cf4 100644 --- a/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/hotReload/sourceMaps.map +++ b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/hotReload/sourceMaps.map @@ -1,14 +1,14 @@ { - "entry/src/main/ets/entryability/EntryAbility.ts": { + "entry/src/entryability/EntryAbility.ts": { "file": "EntryAbility.ts", "sources": [ - "entry/src/main/ets/entryability/EntryAbility.ts" + "entry/src/entryability/EntryAbility.ts" ] }, - "entry/src/main/ets/pages/Index.ets": { + "entry/src/pages/Index.ets": { "file": "Index.ets", "sources": [ - "entry/src/main/ets/pages/Index.ets" + "entry/src/pages/Index.ets" ] } } \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/src/entryability/EntryAbility.js b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/src/entryability/EntryAbility.js new file mode 100644 index 000000000..84ef690e4 --- /dev/null +++ b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/src/entryability/EntryAbility.js @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import UIAbility from '@ohos:app.ability.UIAbility'; +import hilog from '@ohos:hilog'; +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + windowStage.loadContent('pages/Index', (err, data) => { + var _a, _b; + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', (_a = JSON.stringify(err)) !== null && _a !== void 0 ? _a : ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', (_b = JSON.stringify(data)) !== null && _b !== void 0 ? _b : ''); + }); + } + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} +//# sourceMappingURL=EntryAbility.js.map \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/src/main/ets/entryability/EntryAbility.ts b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/src/entryability/EntryAbility.ts similarity index 100% rename from compiler/test/ark_compiler_ut/testdata/testcase_def/entry/src/main/ets/entryability/EntryAbility.ts rename to compiler/test/ark_compiler_ut/testdata/testcase_def/entry/src/entryability/EntryAbility.ts diff --git a/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/src/main/ets/pages/Index.ets b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/src/pages/Index.ets similarity index 100% rename from compiler/test/ark_compiler_ut/testdata/testcase_def/entry/src/main/ets/pages/Index.ets rename to compiler/test/ark_compiler_ut/testdata/testcase_def/entry/src/pages/Index.ets diff --git a/compiler/test/ark_compiler_ut/utils/processProjectConfig.ts b/compiler/test/ark_compiler_ut/utils/processProjectConfig.ts index cc6a5fd0c..b99260d74 100644 --- a/compiler/test/ark_compiler_ut/utils/processProjectConfig.ts +++ b/compiler/test/ark_compiler_ut/utils/processProjectConfig.ts @@ -29,5 +29,6 @@ projectConfig.packageDir = 'oh_modules'; projectConfig.harNameOhmMap = { "@ohos/sharedLibrary": "@bundle:UtTestApplication/sharedLibrary/ets/index" }; +projectConfig.cachePath = '../../test/ark_compiler_ut/cache/'; export default projectConfig; \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/utils/sleep.ts b/compiler/test/ark_compiler_ut/utils/sleep.ts deleted file mode 100644 index c19ed281d..000000000 --- a/compiler/test/ark_compiler_ut/utils/sleep.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -function sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); -} - -export default sleep \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/utils/path_utils.ts b/compiler/test/ark_compiler_ut/utils/utils.ts similarity index 87% rename from compiler/test/ark_compiler_ut/utils/path_utils.ts rename to compiler/test/ark_compiler_ut/utils/utils.ts index d807d6479..c61151643 100644 --- a/compiler/test/ark_compiler_ut/utils/path_utils.ts +++ b/compiler/test/ark_compiler_ut/utils/utils.ts @@ -13,11 +13,16 @@ * limitations under the License. */ +import os from 'os'; import fs from "fs"; import path from "path"; import { PROJECT_ROOT } from "../mock/rollup_mock/path_config"; import { DEFAULT_PROJECT } from "../mock/rollup_mock/path_config"; +export function cpus() { + return os.cpus().length < 16 ? os.cpus().length : 16; +} + export function getProjectPath(name?: string) { return name ? `${PROJECT_ROOT}/${name}` : `${PROJECT_ROOT}/${DEFAULT_PROJECT}`; } @@ -36,4 +41,7 @@ export function scanFiles(filepath: string, fileList: Set) { fileList.add(child); } }); -} \ No newline at end of file +} +export function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} -- Gitee