diff --git a/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts b/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts index 25c657af3e537a0f1a5fa22e451239ed2d87c0c4..6559f925a639815e28db7b439e3e47ee15d6dfe7 100644 --- a/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts +++ b/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts @@ -268,3 +268,7 @@ function processCompatibleVersion(projectConfig: any, arkRootPath: string) { projectConfig.pandaMode = TS2ABC; } } +export const utProcessArkConfig = { + processCompatibleVersion, + initTerserConfig +}; 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 215b6c8f11c03a87e00f3b18f4992708d2b2b157..936336a333937cbe4eeccb8dc035eb27947f3edf 100644 --- a/compiler/test/ark_compiler_ut/common/ark_utils.test.ts +++ b/compiler/test/ark_compiler_ut/common/ark_utils.test.ts @@ -16,10 +16,24 @@ import { expect } from 'chai'; import mocha from 'mocha'; -import { getBuildModeInLowerCase, getPackageInfo } from '../../../lib/ark_utils'; -import { DEBUG, RELEASE } from '../../../lib/fast_build/ark_compiler/common/ark_define'; +import { + getBuildModeInLowerCase, + getPackageInfo, + genSourceMapFileName +} from '../../../lib/ark_utils'; +import { + DEBUG, + RELEASE, + EXTNAME_JS, + EXTNAME_TS, + EXTNAME_ETS +} 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 } from '../mock/rollup_mock/common'; +import { + BUNDLE_NAME_DEFAULT, + ENTRY_MODULE_NAME_DEFAULT, + EXTNAME_MAP +} from '../mock/rollup_mock/common'; mocha.describe('test ark_utils file api', function () { mocha.before(function () { @@ -80,6 +94,53 @@ mocha.describe('test ark_utils file api', function () { const returnInfo = getPackageInfo(this.rollup.share.projectConfig.aceModuleJsonPath); expect(returnInfo[0] === BUNDLE_NAME_DEFAULT).to.be.true; expect(returnInfo[1] === ENTRY_MODULE_NAME_DEFAULT).to.be.true; - }); + }); + + mocha.it('3-1: test genSourceMapFileName under build debug', function () { + this.rollup.build(); + for (let filePath of this.rollup.share.allFiles) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_JS)) { + const originPath = genSourceMapFileName(filePath); + const expectedPath = `${filePath}${EXTNAME_MAP}`; + expect(originPath === expectedPath).to.be.true; + } else if (filePath.endsWith(EXTNAME_ETS)) { + const originPath = genSourceMapFileName(filePath); + expect(originPath === filePath).to.be.true; + } + } + }); + + mocha.it('3-2: test genSourceMapFileName under build release', function () { + this.rollup.build(RELEASE); + for (let filePath of this.rollup.share.allFiles) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_JS)) { + const originPath = genSourceMapFileName(filePath); + const expectedPath = `${filePath}${EXTNAME_MAP}`; + expect(originPath === expectedPath).to.be.true; + } + } + }); + + mocha.it('3-3: test genSourceMapFileName under preview debug', function () { + this.rollup.preview(); + for (let filePath of this.rollup.share.allFiles) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_JS)) { + const originPath = genSourceMapFileName(filePath); + const expectedPath = `${filePath}${EXTNAME_MAP}`; + expect(originPath === expectedPath).to.be.true; + } + } + }); + + mocha.it('3-4: test genSourceMapFileName under hot reload debug', function () { + this.rollup.hotReload(); + for (let filePath of this.rollup.share.allFiles) { + if (filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_JS)) { + const originPath = genSourceMapFileName(filePath); + const expectedPath = `${filePath}${EXTNAME_MAP}`; + expect(originPath === expectedPath).to.be.true; + } + } + }); }); diff --git a/compiler/test/ark_compiler_ut/common/process_ark_config.test.ts b/compiler/test/ark_compiler_ut/common/process_ark_config.test.ts index da3f4a27f8352fe03ddabade0e8654c1202e68e0..3538efb74b3c3cbe0517b7488594ea9fcd235de8 100644 --- a/compiler/test/ark_compiler_ut/common/process_ark_config.test.ts +++ b/compiler/test/ark_compiler_ut/common/process_ark_config.test.ts @@ -16,19 +16,37 @@ import { expect } from 'chai'; import mocha from 'mocha'; +import fs from "fs"; -import { RELEASE } from '../../../lib/fast_build/ark_compiler/common/ark_define'; -import { NODE } from '../mock/rollup_mock/common'; +import { + OBFUSCATION_TOOL, + ESMODULE, + RELEASE, + TS2ABC +} from '../../../lib/fast_build/ark_compiler/common/ark_define'; +import { + NODE, + BUNDLE_NAME_DEFAULT, + ENTRY_MODULE_NAME_DEFAULT, + NODE_JS_PATH +} from '../mock/rollup_mock/common'; import { ES2ABC_PATH, TS2ABC_PATH, MERGERABC_PATH, JS2ABC_PATH, - AOTCOMPILER_PATH, - ARKROOT_PATH + AOTCOMPILER_PATH } from '../mock/rollup_mock/path_config'; import RollUpPluginMock from '../mock/rollup_mock/rollup_plugin_mock'; -import { initArkConfig } from '../../../lib/fast_build/ark_compiler/common/process_ark_config'; +import { + initArkConfig, + initArkProjectConfig, + utProcessArkConfig +} from '../../../lib/fast_build/ark_compiler/common/process_ark_config'; +import { + ObConfigResolver, + MergedConfig +} from '../../../lib/fast_build/ark_compiler/common/ob_config_resolver'; mocha.describe('test process_ark_config file api', function () { mocha.before(function () { @@ -41,20 +59,24 @@ mocha.describe('test process_ark_config file api', function () { mocha.it('1-1: test initArkConfig under build debug', function () { this.rollup.build(); + this.rollup.share.projectConfig.arkFrontendDir = this.rollup.share.projectConfig.projectTopDir; + this.rollup.share.projectConfig.nodeJs = true; + this.rollup.share.projectConfig.nodePath = NODE_JS_PATH; const arkConfig = initArkConfig(this.rollup.share.projectConfig); - expect(arkConfig.nodePath === NODE).to.be.true; + expect(arkConfig.nodePath === NODE_JS_PATH).to.be.true; expect(arkConfig.es2abcPath.indexOf(ES2ABC_PATH) > 0).to.be.true; expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; expect(arkConfig.mergeAbcPath.indexOf(MERGERABC_PATH) > 0).to.be.true; expect(arkConfig.js2abcPath.indexOf(JS2ABC_PATH) > 0).to.be.true; expect(arkConfig.aotCompilerPath.indexOf(AOTCOMPILER_PATH) > 0).to.be.true; expect(arkConfig.isDebug === true).to.be.true; - expect(arkConfig.arkRootPath.indexOf(ARKROOT_PATH) > 0).to.be.true; + expect(arkConfig.arkRootPath === this.rollup.share.projectConfig.arkFrontendDir).to.be.true; }); mocha.it('1-2: test initArkConfig under build release', function () { this.rollup.build(RELEASE); + this.rollup.share.projectConfig.arkFrontendDir = this.rollup.share.projectConfig.projectTopDir; const arkConfig = initArkConfig(this.rollup.share.projectConfig); expect(arkConfig.nodePath === NODE).to.be.true; @@ -64,11 +86,12 @@ mocha.describe('test process_ark_config file api', function () { expect(arkConfig.js2abcPath.indexOf(JS2ABC_PATH) > 0).to.be.true; expect(arkConfig.aotCompilerPath.indexOf(AOTCOMPILER_PATH) > 0).to.be.true; expect(arkConfig.isDebug === false).to.be.true; - expect(arkConfig.arkRootPath.indexOf(ARKROOT_PATH) > 0).to.be.true; + expect(arkConfig.arkRootPath === this.rollup.share.projectConfig.arkFrontendDir).to.be.true; }); mocha.it('1-3: test initArkConfig under preview debug', function () { this.rollup.preview(); + this.rollup.share.projectConfig.arkFrontendDir = this.rollup.share.projectConfig.projectTopDir; const arkConfig = initArkConfig(this.rollup.share.projectConfig); expect(arkConfig.nodePath === NODE).to.be.true; @@ -78,11 +101,12 @@ mocha.describe('test process_ark_config file api', function () { expect(arkConfig.js2abcPath.indexOf(JS2ABC_PATH) > 0).to.be.true; expect(arkConfig.aotCompilerPath.indexOf(AOTCOMPILER_PATH) > 0).to.be.true; expect(arkConfig.isDebug === true).to.be.true; - expect(arkConfig.arkRootPath.indexOf(ARKROOT_PATH) > 0).to.be.true; + expect(arkConfig.arkRootPath === this.rollup.share.projectConfig.arkFrontendDir).to.be.true; }); mocha.it('1-4: test initArkConfig under hot reload debug', function () { this.rollup.hotReload(); + this.rollup.share.projectConfig.arkFrontendDir = this.rollup.share.projectConfig.projectTopDir; const arkConfig = initArkConfig(this.rollup.share.projectConfig); expect(arkConfig.nodePath === NODE).to.be.true; @@ -92,6 +116,161 @@ mocha.describe('test process_ark_config file api', function () { expect(arkConfig.js2abcPath.indexOf(JS2ABC_PATH) > 0).to.be.true; expect(arkConfig.aotCompilerPath.indexOf(AOTCOMPILER_PATH) > 0).to.be.true; expect(arkConfig.isDebug === true).to.be.true; - expect(arkConfig.arkRootPath.indexOf(ARKROOT_PATH) > 0).to.be.true; + expect(arkConfig.arkRootPath === this.rollup.share.projectConfig.arkFrontendDir).to.be.true; + }); + + mocha.it('2-1-1: test initArkProjectConfig under build debug: moduleJsonInfo exists', function () { + this.rollup.build(); + const arkConfig = initArkProjectConfig(this.rollup.share); + const buildJsonInfo = + JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceBuildJson).toString()); + const moduleJsonInfo = + JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceModuleJsonPath).toString()); + + expect(arkConfig.nodeModulesPath === buildJsonInfo.nodeModulesPath).to.be.true; + expect(arkConfig.minPlatformVersion === moduleJsonInfo.app.minAPIVersion).to.be.true; + expect(arkConfig.processTs === false).to.be.true; + expect(arkConfig.moduleName === ENTRY_MODULE_NAME_DEFAULT).to.be.true; + expect(arkConfig.bundleName === BUNDLE_NAME_DEFAULT).to.be.true; + expect(arkConfig.compileMode === ESMODULE).to.be.true; + }); + + mocha.it('2-1-2: test initArkProjectConfig under build debug: buildJsonInfo.patchConfig is true', function () { + this.rollup.build(); + this.rollup.share.projectConfig.aceBuildJson = + `${this.rollup.share.projectConfig.aceModuleBuild}/loader_aotMode.json`; + const arkConfig = initArkProjectConfig(this.rollup.share); + const buildJsonInfo = + JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceBuildJson).toString()); + + expect(arkConfig.oldMapFilePath === buildJsonInfo.patchConfig.oldMapFilePath).to.be.true; + expect(arkConfig.pandaMode === TS2ABC).to.be.true; + expect(arkConfig.processTs === true).to.be.true; + expect(arkConfig.anBuildOutPut === buildJsonInfo.anBuildOutPut).to.be.true; + expect(arkConfig.anBuildMode === buildJsonInfo.anBuildMode).to.be.true; + expect(arkConfig.apPath === buildJsonInfo.apPath).to.be.true; + expect(arkConfig.moduleName === ENTRY_MODULE_NAME_DEFAULT).to.be.true; + expect(arkConfig.bundleName === BUNDLE_NAME_DEFAULT).to.be.true; + expect(arkConfig.compileMode === ESMODULE).to.be.true; + }); + + mocha.it('2-2: test initArkProjectConfig under build release', function () { + this.rollup.build(RELEASE); + const arkConfig = initArkProjectConfig(this.rollup.share); + const buildJsonInfo = + JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceBuildJson).toString()); + const moduleJsonInfo = + JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceModuleJsonPath).toString()); + + expect(arkConfig.nodeModulesPath === buildJsonInfo.nodeModulesPath).to.be.true; + expect(arkConfig.minPlatformVersion === moduleJsonInfo.app.minAPIVersion).to.be.true; + expect(arkConfig.processTs === false).to.be.true; + expect(arkConfig.moduleName === ENTRY_MODULE_NAME_DEFAULT).to.be.true; + expect(arkConfig.bundleName === BUNDLE_NAME_DEFAULT).to.be.true; + expect(arkConfig.compileMode === ESMODULE).to.be.true; + }); + + mocha.it('2-3: test initArkProjectConfig under preview debug', function () { + this.rollup.preview(); + const arkConfig = initArkProjectConfig(this.rollup.share); + const buildJsonInfo = + JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceBuildJson).toString()); + const moduleJsonInfo = + JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceModuleJsonPath).toString()); + + expect(arkConfig.nodeModulesPath === buildJsonInfo.nodeModulesPath).to.be.true; + expect(arkConfig.minPlatformVersion === moduleJsonInfo.app.minAPIVersion).to.be.true; + expect(arkConfig.processTs === false).to.be.true; + expect(arkConfig.moduleName === ENTRY_MODULE_NAME_DEFAULT).to.be.true; + expect(arkConfig.bundleName === BUNDLE_NAME_DEFAULT).to.be.true; + expect(arkConfig.compileMode === ESMODULE).to.be.true; + }); + + mocha.it('2-4: test initArkProjectConfig under hot reload debug', function () { + this.rollup.hotReload(); + const arkConfig = initArkProjectConfig(this.rollup.share); + const buildJsonInfo = + JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceBuildJson).toString()); + const moduleJsonInfo = + JSON.parse(fs.readFileSync(this.rollup.share.projectConfig.aceModuleJsonPath).toString()); + + expect(arkConfig.nodeModulesPath === buildJsonInfo.nodeModulesPath).to.be.true; + expect(arkConfig.minPlatformVersion === moduleJsonInfo.app.minAPIVersion).to.be.true; + expect(arkConfig.processTs === false).to.be.true; + expect(arkConfig.moduleName === ENTRY_MODULE_NAME_DEFAULT).to.be.true; + expect(arkConfig.bundleName === BUNDLE_NAME_DEFAULT).to.be.true; + expect(arkConfig.compileMode === ESMODULE).to.be.true; + }); + + mocha.it('3-1: test initTerserConfig under build debug', function () { + this.rollup.build(); + const logger: any = 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; + const minifyOptions = + utProcessArkConfig.initTerserConfig(this.rollup.share.projectConfig, logger, mergedObConfig, isHarCompiled); + + expect(minifyOptions.format.beautify === true).to.be.true; + expect(minifyOptions.format.indent_level === 2).to.be.true; + expect(minifyOptions.compress.join_vars === false).to.be.true; + expect(minifyOptions.compress.sequences === 0).to.be.true; + expect(minifyOptions.compress.directives === false).to.be.true; + expect(minifyOptions.compress.drop_console === false).to.be.true; + expect(minifyOptions.mangle.toplevel === false).to.be.true; + }); + + mocha.it('3-2: test initTerserConfig under build release', function () { + this.rollup.build(RELEASE); + const logger: any = 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; + const minifyOptions = + utProcessArkConfig.initTerserConfig(this.rollup.share.projectConfig, logger, mergedObConfig, isHarCompiled); + + expect(minifyOptions.format.beautify === true).to.be.true; + expect(minifyOptions.format.indent_level === 2).to.be.true; + expect(minifyOptions.compress.join_vars === false).to.be.true; + expect(minifyOptions.compress.sequences === 0).to.be.true; + expect(minifyOptions.compress.directives === false).to.be.true; + expect(minifyOptions.compress.drop_console === false).to.be.true; + expect(minifyOptions.mangle.toplevel === false).to.be.true; + }); + + mocha.it('3-3: test initTerserConfig under preview debug', function () { + this.rollup.preview(); + const logger: any = 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; + const minifyOptions = + utProcessArkConfig.initTerserConfig(this.rollup.share.projectConfig, logger, mergedObConfig, isHarCompiled); + + expect(minifyOptions.format.beautify === true).to.be.true; + expect(minifyOptions.format.indent_level === 2).to.be.true; + expect(minifyOptions.compress.join_vars === false).to.be.true; + expect(minifyOptions.compress.sequences === 0).to.be.true; + expect(minifyOptions.compress.directives === false).to.be.true; + expect(minifyOptions.compress.drop_console === false).to.be.true; + expect(minifyOptions.mangle.toplevel === false).to.be.true; + }); + + mocha.it('3-4: test initTerserConfig under hot reload debug', function () { + this.rollup.hotReload(); + const logger: any = 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; + const minifyOptions = + utProcessArkConfig.initTerserConfig(this.rollup.share.projectConfig, logger, mergedObConfig, isHarCompiled); + + expect(minifyOptions.format.beautify === true).to.be.true; + expect(minifyOptions.format.indent_level === 2).to.be.true; + expect(minifyOptions.compress.join_vars === false).to.be.true; + expect(minifyOptions.compress.sequences === 0).to.be.true; + expect(minifyOptions.compress.directives === false).to.be.true; + expect(minifyOptions.compress.drop_console === false).to.be.true; + expect(minifyOptions.mangle.toplevel === false).to.be.true; }); }) \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/common/utils.test.ts b/compiler/test/ark_compiler_ut/common/utils.test.ts index 1cda6494aee2d902e17ffd99ccae3340072c20ba..486c0cb78ffe622760a06fc9e6e10e8404bdea27 100644 --- a/compiler/test/ark_compiler_ut/common/utils.test.ts +++ b/compiler/test/ark_compiler_ut/common/utils.test.ts @@ -18,8 +18,16 @@ import mocha from 'mocha'; import { needAotCompiler } from '../../../lib/fast_build/ark_compiler/utils'; import RollUpPluginMock from '../mock/rollup_mock/rollup_plugin_mock'; -import { AOT_FULL, AOT_PARTIAL, AOT_TYPE } from '../../../lib/pre_define'; -import { ESMODULE, JSBUNDLE, RELEASE } from '../../../lib/fast_build/ark_compiler/common/ark_define'; +import { + AOT_FULL, + AOT_PARTIAL, + AOT_TYPE +} from '../../../lib/pre_define'; +import { + ESMODULE, + JSBUNDLE, + RELEASE +} from '../../../lib/fast_build/ark_compiler/common/ark_define'; mocha.describe('test utils file api', function () { mocha.before(function () { 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 new file mode 100644 index 0000000000000000000000000000000000000000..43a4a82503d79a13af7b60efc65396bf408fb041 --- /dev/null +++ b/compiler/test/ark_compiler_ut/mock/class_mock/module_mode_mock.ts @@ -0,0 +1,106 @@ +/* + * 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 fs from 'fs'; +import { + COMMONJS, + ESM, + EXTNAME_PROTO_BIN, + EXTNAME_JS, + EXTNAME_TS, + EXTNAME_ETS +} from '../../../../lib/fast_build/ark_compiler/common/ark_define'; +import { ModuleMode } 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) { + const fileList = Array.from(rollupObject.getModuleIds()) + this.collectModuleFileList(rollupObject, fileList); + } + + addModuleInfoItemMock(rollupObject: any, 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)) { + const moduleInfo: any = rollupObject.getModuleInfo(filePath); + const metaInfo: any = moduleInfo[META]; + this.addModuleInfoItem(filePath, isCommonJs, extName, metaInfo, this.moduleInfos); + } + } + } + + generateCompileFilesInfoMock() { + this.generateCompileFilesInfo(); + } + + generateNpmEntriesInfoMock() { + this.generateNpmEntriesInfo(); + } + + generateAbcCacheFilesInfoMock() { + this.generateAbcCacheFilesInfo(); + } + + checkGenerateCompileFilesInfo(): boolean { + let mockfilesInfo: string = ''; + const filesInfo = fs.readFileSync(this.filesInfoPath, 'utf-8'); + this.moduleInfos.forEach((info) => { + const moduleType: string = info.isCommonJs ? COMMONJS : ESM; + mockfilesInfo += + `${info.cacheFilePath};${info.recordName};${moduleType};${info.sourceFile};${info.packageName}\n`; + }); + if (filesInfo === mockfilesInfo) { + return true; + } + return false; + } + + checkGenerateNpmEntriesInfo(): boolean { + let mockentriesInfo: string = ''; + const filesInfo = fs.readFileSync(this.npmEntriesInfoPath, 'utf-8'); + for (const value of this.pkgEntryInfos.values()) { + mockentriesInfo += `${value.pkgEntryPath}:${value.pkgBuildPath}\n`; + } + if (filesInfo === mockentriesInfo) { + return true; + } + return false; + } + + checkGenerateAbcCacheFilesInfo(): boolean { + let mockabcCacheFilesInfo: string = ''; + const filesInfo = fs.readFileSync(this.cacheFilePath, 'utf-8'); + this.moduleInfos.forEach((info) => { + const abcCacheFilePath: string = changeFileExtension(info.cacheFilePath, EXTNAME_PROTO_BIN); + mockabcCacheFilesInfo += `${info.cacheFilePath};${abcCacheFilePath}\n`; + }); + + const npmEntriesCacheFilePath: string = changeFileExtension(this.npmEntriesInfoPath, EXTNAME_PROTO_BIN); + mockabcCacheFilesInfo += `${this.npmEntriesInfoPath};${npmEntriesCacheFilePath}\n`; + + if (filesInfo === mockabcCacheFilesInfo) { + return true; + } + return false; + } + + updateCachedSourceMapsMock() { + this.updateCachedSourceMaps(); + } +} + +export default ModuleModeMock; \ No newline at end of file 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 2a6ca1cc21d9d56f98d318cfd2f3c73966cba16e..3241f48f07e7b03b040dda94fb28376dfe51c6d9 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/common.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/common.ts @@ -30,4 +30,23 @@ export const PORT_DEFAULT: string = '29900'; export const CMD_DEBUG_INFO: string = '--debug-info'; export const NODE: string = 'node'; +export const EXTNAME_MAP: string = '.map'; +export const META: string = 'meta'; +export const PKG_MODULES: string = 'pkg_modules'; + +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_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_DEBUG_ENTRY: string = '/entry/src/main/ets/entryability/EntryAbility.ts'; +export const ENTRYABILITY_JS_DEBUG_ENTRY: string = '/entry/src/main/ets/entryability/EntryAbility.js'; +export const INDEX_ETS_DEBUG_ENTRY: string = '/entry/src/main/ets/pages/Index.ets'; + +export const ENTRYABILITY_TS_RELEASE_ENTRY: string = '/entry/src/main/ets/entryability/EntryAbility.ts'; +export const ENTRYABILITY_JS_RELEASE_ENTRY: string = '/entry/src/main/ets/entryability/EntryAbility.js'; +export const INDEX_ETS_RELEASE_ENTRY: string = '/entry/src/main/ets/pages/Index.ets'; 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 49ff57b1e40bbbefa874e6aecedc4f63ee1ccbc8..7e816b6cc15a197bd103d7b3f14030cc1a172a16 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 @@ -38,6 +38,12 @@ class ModuleInfo { this.meta = new Meta(entryModuleName, modulePath); this.id = id; } + setIsLocalDependency(value: boolean) { + this.meta.isLocalDependency = value + } + setIsNodeEntryFile(value: boolean) { + this.meta.isNodeEntryFile = value + } } export default ModuleInfo 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 b9a033dc1bffcecec74f5e78090e2bfe76fa6e25..25b811e275bff481ecbe0c81ad7f4554574995bb 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 @@ -29,11 +29,12 @@ export const MODULE_ID_ROLLUP_PLACEHOLDER = "\x00rollup_plugin_ignore_empty_modu // project build node_modules export const NODE_MODULES_PATH = "default/intermediates/loader_out/default/node_modules"; -export const ES2ABC_PATH: string = 'bin/ark/build/bin/es2abc'; -export const TS2ABC_PATH: string = 'bin/ark/build/src/index.js'; -export const MERGERABC_PATH: string = 'bin/ark/build/bin/merge_abc'; -export const JS2ABC_PATH: string = 'bin/ark/build/bin/js2abc'; -export const AOTCOMPILER_PATH: string = 'bin/ark/build/bin/ark_aot_compiler'; +export const ES2ABC_PATH: string = '/build/bin/es2abc'; +export const TS2ABC_PATH: string = '/build/src/index.js'; +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 EXPECT_SOURCEMAP_JSON: string = `${PROJECT_ROOT}/expect/sourceMaps.json`; 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 b8b88772f6476aa96d03797bf14c71a413238f04..8d250180710f5fd9576e9f875aeebbd5398e342f 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 @@ -26,7 +26,11 @@ import { NODE_JS_PATH, PORT_DEFAULT } from "./common"; -import { ESMODULE, OHPM, RELEASE } from "../../../../lib/fast_build/ark_compiler/common/ark_define"; +import { + ESMODULE, + OHPM, + RELEASE +} from "../../../../lib/fast_build/ark_compiler/common/ark_define"; interface IArkProjectConfig { projectRootPath: string, @@ -132,24 +136,24 @@ class ProjectConfig { private initPath(proPath: string) { // build and preview - let mode = this.isPreview ? '.preview' : 'build'; + let mode = this.isPreview ? 'preview' : 'build'; this.localPropertiesPath = `${proPath}/local.properties`; - this.aceProfilePath = `${proPath}/${this.entryModuleName}/${mode}/default/intermediates/res/default/resources/base/profile`; + this.aceProfilePath = `${proPath}/${this.entryModuleName}/${mode}/res/default/resources/base/profile`; this.etsLoaderPath = `/${this.runtimeOS}/Sdk/${this.compileSdkVersion}/ets/build-tools/app`; this.modulePath = `${proPath}/${this.entryModuleName}`; this.projectTopDir = `${proPath}`; this.apPath = ''; this.aceModuleJsonPath = `${proPath}/${this.entryModuleName}/${mode}/module.json`; - this.appResource = `${proPath}/${this.entryModuleName}/${mode}/default/intermediates/res/default/ResourceTable.txt`; + this.appResource = `${proPath}/${this.entryModuleName}/${mode}/res/default/ResourceTable.txt`; this.aceModuleRoot = `${proPath}/${this.entryModuleName}/src/main/ets`; this.aceSuperVisualPath = `${proPath}/${this.entryModuleName}/src/main/supervisual`; - this.aceBuildJson = `${proPath}/${this.entryModuleName}/${mode}/default/intermediates/loader/default/loader.json`; - this.cachePath = `${proPath}/${this.entryModuleName}/${mode}/default/cache/default/default@CompileArkTS/esmodule/${this.buildMode}`; - this.aceModuleBuild = `${proPath}/${this.entryModuleName}/${mode}/default/intermediates/loader_out/default/ets`; + 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.moduleRootPath = undefined; - this.buildPath = `${proPath}/${this.entryModuleName}/${mode}/default/intermediates/loader_out/default/ets`; - this.patchAbcPath = `${proPath}/${this.entryModuleName}/${mode}/default/intermediates/hotReload/patchAbcPath/ets`; + this.buildPath = `${proPath}/${this.entryModuleName}/${mode}/loader_out/default/ets`; + this.patchAbcPath = `${proPath}/${this.entryModuleName}/${mode}/hotReload/patchAbcPath/ets`; if (this.isPreview) { this.previewUniqueConfig(); @@ -167,7 +171,7 @@ class ProjectConfig { this.logLevel = '3'; this.stageRouterConfig = []; this.port = PORT_DEFAULT; - this.aceSoPath = `${this.projectTopDir}/entry/.preview/cache/nativeDependencies.txt`; + this.aceSoPath = `${this.projectTopDir}/entry/preview/cache/nativeDependencies.txt`; } } 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 401b54c2df26f35e9ca4155bfbee9a33341e1724..b4049c49bc9e2e1a75e5b5b976271ed535340d9d 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 @@ -15,6 +15,8 @@ import Cache from "./cache"; import Share from "./share"; +import path from "path"; +import fs from "fs"; import ModuleInfo from "./module_info"; import { SDK_VERSION, @@ -23,15 +25,19 @@ import { RUNTIME_OS_OPENHARMONY, MODULE_NAME_HASH_DEFAULT } from "./common"; -import { DEFAULT_PROJECT, MODULE_ID_ROLLUP_PLACEHOLDER, NODE_MODULES_PATH } from "./path_config"; +import { + DEFAULT_PROJECT, + MODULE_ID_ROLLUP_PLACEHOLDER, + NODE_MODULES_PATH +} from "./path_config"; import { scanFiles } from "../../utils/path_utils"; import { IArkProjectConfig } from "./project_config"; -import { ESMODULE, RELEASE, DEBUG } from "../../../../lib/fast_build/ark_compiler/common/ark_define"; import { + ESMODULE, + RELEASE, DEBUG, ARK_COMPILER_META_INFO, IS_CACHE_INVALID -} from '../../../../lib/fast_build/ark_compiler/common/ark_define'; - +} from "../../../../lib/fast_build/ark_compiler/common/ark_define"; class RollUpPluginMock { cache: Cache; meta: any = { rollupVersion: '3.10.0', watchMode: false }; @@ -96,7 +102,7 @@ class RollUpPluginMock { } private mockArkProjectConfig(): IArkProjectConfig { - const mode = this.isPreview ? '.preview' : 'build'; + const mode = this.isPreview ? 'preview' : 'build'; const projectRootDir = this.share.projectConfig.projectTopDir; const entryName = this.share.projectConfig.entryModuleName; @@ -160,7 +166,16 @@ class RollUpPluginMock { public load() { // load project files list this.share.allFiles = new Set(); - scanFiles(this.share.projectConfig.projectPath, this.share.allFiles); + if (fs.existsSync(this.share.projectConfig.projectPath)) { + scanFiles(this.share.projectConfig.projectPath, this.share.allFiles); + } else { + const tsFilePath = path.join(this.share.projectConfig.projectPath, '/entryability/EntryAbility.ts'); + const jsFilePath = path.join(this.share.projectConfig.projectPath, '/entryability/EntryAbility.js'); + const etsFilePath = path.join(this.share.projectConfig.projectPath, '/pages/Index.ets'); + this.share.allFiles.add(tsFilePath); + this.share.allFiles.add(jsFilePath); + this.share.allFiles.add(etsFilePath); + } this.share.allFiles.add(MODULE_ID_ROLLUP_PLACEHOLDER); // load all files module info 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 989b29d99ab3052caf823fb00480ea321e6e764a..539625a2e55b00e2ff1c5145e72a602d585914d1 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/share.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/share.ts @@ -13,8 +13,15 @@ * limitations under the License. */ -import { ProjectConfig, IArkProjectConfig } from "./project_config"; -import { OH_MODULES_OHPM_HYPIUM, OH_MODULES_OHOS_HYPIUM, MOCK_CONFIG_PATH } from "./path_config"; +import { + ProjectConfig, + IArkProjectConfig +} from "./project_config"; +import { + OH_MODULES_OHPM_HYPIUM, + OH_MODULES_OHOS_HYPIUM, + MOCK_CONFIG_PATH +} from "./path_config"; class Logger { private prefix: string; diff --git a/compiler/test/ark_compiler_ut/module/module_mode.test.ts b/compiler/test/ark_compiler_ut/module/module_mode.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..a62954cd3d32b23f3084d249e8cc54b12fd71d9e --- /dev/null +++ b/compiler/test/ark_compiler_ut/module/module_mode.test.ts @@ -0,0 +1,469 @@ +/* + * 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 { newSourceMaps } from '../../../lib/fast_build/ark_compiler/transform'; +import { EXPECT_SOURCEMAP_JSON } from "../mock/rollup_mock/path_config"; +import { + RELEASE, + EXTNAME_TS, + EXTNAME_JS, + EXTNAME_ETS, + OH_MODULES +} 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 { + ENTRYABILITY_TS_PATH_DEFAULT, + ENTRYABILITY_JS_PATH_DEFAULT, + INDEX_ETS_PATH_DEFAULT, + ENTRYABILITY_TS_RECORDNAME, + ENTRYABILITY_JS_RECORDNAME, + INDEX_ETS_RECORDNAME, + ENTRYABILITY_TS_DEBUG_ENTRY, + ENTRYABILITY_JS_DEBUG_ENTRY, + INDEX_ETS_DEBUG_ENTRY, + ENTRYABILITY_TS_RELEASE_ENTRY, + ENTRYABILITY_JS_RELEASE_ENTRY, + INDEX_ETS_RELEASE_ENTRY, + PKG_MODULES, + ENTRY_MODULE_NAME_DEFAULT +} from '../mock/rollup_mock/common'; + +mocha.describe('test module_mode file api', function () { + mocha.before(function () { + this.rollup = new RollUpPluginMock(); + }); + + mocha.after(() => { + delete this.rollup; + }); + + mocha.it('1-1: test collectModuleFileList under build debug', function () { + this.rollup.build(); + const moduleMode = new ModuleModeMock(this.rollup); + const fileList = this.rollup.getModuleIds(); + for (const filePath of fileList) { + if (filePath.endsWith(EXTNAME_JS) || filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS)) { + const moduleInfo = this.rollup.getModuleInfo(filePath); + moduleInfo.setIsNodeEntryFile(true); + moduleInfo.setIsLocalDependency(false); + } + } + moduleMode.projectConfig.packageDir = OH_MODULES; + moduleMode.collectModuleFileListMock(this.rollup); + moduleMode.moduleInfos.forEach(moduleInfo => { + expect(moduleInfo.filePath.indexOf(ENTRYABILITY_TS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(ENTRYABILITY_JS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(INDEX_ETS_PATH_DEFAULT) > 0).to.be.true; + + expect(moduleInfo.recordName.indexOf(ENTRYABILITY_TS_RECORDNAME) > 0 || + 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(moduleMode.pkgEntryInfos.size != 0).to.be.true; + }); + + mocha.it('1-2: test collectModuleFileList under build release', function () { + this.rollup.build(RELEASE); + const moduleMode = new ModuleModeMock(this.rollup); + const fileList = this.rollup.getModuleIds(); + for (const filePath of fileList) { + if (filePath.endsWith(EXTNAME_JS) || filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS)) { + const moduleInfo = this.rollup.getModuleInfo(filePath); + moduleInfo.setIsNodeEntryFile(true); + moduleInfo.setIsLocalDependency(false); + } + } + moduleMode.projectConfig.packageDir = OH_MODULES; + moduleMode.collectModuleFileListMock(this.rollup); + moduleMode.moduleInfos.forEach(moduleInfo => { + expect(moduleInfo.filePath.indexOf(ENTRYABILITY_TS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(ENTRYABILITY_JS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(INDEX_ETS_PATH_DEFAULT) > 0).to.be.true; + + expect(moduleInfo.recordName.indexOf(ENTRYABILITY_TS_RECORDNAME) > 0 || + 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(moduleMode.pkgEntryInfos.size != 0).to.be.true; + }); + + mocha.it('1-3: test collectModuleFileList under preview debug', function () { + this.rollup.preview(); + const moduleMode = new ModuleModeMock(this.rollup); + const fileList = this.rollup.getModuleIds(); + for (const filePath of fileList) { + if (filePath.endsWith(EXTNAME_JS) || filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS)) { + const moduleInfo = this.rollup.getModuleInfo(filePath); + moduleInfo.setIsNodeEntryFile(true); + moduleInfo.setIsLocalDependency(false); + } + } + moduleMode.projectConfig.packageDir = OH_MODULES; + moduleMode.collectModuleFileListMock(this.rollup); + moduleMode.moduleInfos.forEach(moduleInfo => { + expect(moduleInfo.filePath.indexOf(ENTRYABILITY_TS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(ENTRYABILITY_JS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(INDEX_ETS_PATH_DEFAULT) > 0).to.be.true; + + expect(moduleInfo.recordName.indexOf(ENTRYABILITY_TS_RECORDNAME) > 0 || + 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(moduleMode.pkgEntryInfos.size != 0).to.be.true; + }); + + mocha.it('1-4: test collectModuleFileList under hot reload debug', function () { + this.rollup.hotReload(); + const moduleMode = new ModuleModeMock(this.rollup); + const fileList = this.rollup.getModuleIds(); + for (const filePath of fileList) { + if (filePath.endsWith(EXTNAME_JS) || filePath.endsWith(EXTNAME_TS) || filePath.endsWith(EXTNAME_ETS)) { + const moduleInfo = this.rollup.getModuleInfo(filePath); + moduleInfo.setIsNodeEntryFile(true); + moduleInfo.setIsLocalDependency(false); + } + } + moduleMode.projectConfig.packageDir = OH_MODULES; + moduleMode.collectModuleFileListMock(this.rollup); + moduleMode.moduleInfos.forEach(moduleInfo => { + expect(moduleInfo.filePath.indexOf(ENTRYABILITY_TS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(ENTRYABILITY_JS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(INDEX_ETS_PATH_DEFAULT) > 0).to.be.true; + + expect(moduleInfo.recordName.indexOf(ENTRYABILITY_TS_RECORDNAME) > 0 || + 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(moduleMode.pkgEntryInfos.size != 0).to.be.true; + }); + + 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(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.projectConfig.packageDir = ENTRY_MODULE_NAME_DEFAULT; + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.moduleInfos.forEach(value => { + expect(value.packageName === PKG_MODULES).to.be.true; + }); + }) + mocha.it('2-1-2: test addModuleInfoItem under build debug: isPackageModulesFile`s return is false', function () { + this.rollup.build(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.moduleInfos.forEach(moduleInfo => { + expect(moduleInfo.filePath.indexOf(ENTRYABILITY_TS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(ENTRYABILITY_JS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(INDEX_ETS_PATH_DEFAULT) > 0).to.be.true; + + expect(moduleInfo.cacheFilePath.indexOf(ENTRYABILITY_TS_DEBUG_ENTRY) > 0 || + moduleInfo.cacheFilePath.indexOf(ENTRYABILITY_JS_DEBUG_ENTRY) > 0 || + moduleInfo.cacheFilePath.indexOf(INDEX_ETS_DEBUG_ENTRY) > 0).to.be.true; + + expect(moduleInfo.recordName.indexOf(ENTRYABILITY_TS_RECORDNAME) > 0 || + 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; + }) + }); + 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 + }); + }) + + mocha.it('2-2: test addModuleInfoItem under build release', function () { + this.rollup.build(RELEASE); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.moduleInfos.forEach(moduleInfo => { + expect(moduleInfo.filePath.indexOf(ENTRYABILITY_TS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(ENTRYABILITY_JS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(INDEX_ETS_PATH_DEFAULT) > 0).to.be.true; + + expect(moduleInfo.cacheFilePath.indexOf(ENTRYABILITY_TS_RELEASE_ENTRY) > 0 || + moduleInfo.cacheFilePath.indexOf(ENTRYABILITY_JS_RELEASE_ENTRY) > 0 || + moduleInfo.cacheFilePath.indexOf(INDEX_ETS_RELEASE_ENTRY) > 0).to.be.true; + + expect(moduleInfo.recordName.indexOf(ENTRYABILITY_TS_RECORDNAME) > 0 || + 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; + }) + }); + + mocha.it('2-3: test addModuleInfoItem under preview debug', function () { + this.rollup.preview(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.moduleInfos.forEach(moduleInfo => { + expect(moduleInfo.filePath.indexOf(ENTRYABILITY_TS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(ENTRYABILITY_JS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(INDEX_ETS_PATH_DEFAULT) > 0).to.be.true; + + expect(moduleInfo.cacheFilePath.indexOf(ENTRYABILITY_TS_DEBUG_ENTRY) > 0 || + moduleInfo.cacheFilePath.indexOf(ENTRYABILITY_JS_DEBUG_ENTRY) > 0 || + moduleInfo.cacheFilePath.indexOf(INDEX_ETS_DEBUG_ENTRY) > 0).to.be.true; + + expect(moduleInfo.recordName.indexOf(ENTRYABILITY_TS_RECORDNAME) > 0 || + 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; + }) + }); + + mocha.it('2-4: test addModuleInfoItem under hot reload debug', function () { + this.rollup.hotReload(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.moduleInfos.forEach(moduleInfo => { + expect(moduleInfo.filePath.indexOf(ENTRYABILITY_TS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(ENTRYABILITY_JS_PATH_DEFAULT) > 0 || + moduleInfo.filePath.indexOf(INDEX_ETS_PATH_DEFAULT) > 0).to.be.true; + + expect(moduleInfo.cacheFilePath.indexOf(ENTRYABILITY_TS_DEBUG_ENTRY) > 0 || + moduleInfo.cacheFilePath.indexOf(ENTRYABILITY_JS_DEBUG_ENTRY) > 0 || + moduleInfo.cacheFilePath.indexOf(INDEX_ETS_DEBUG_ENTRY) > 0).to.be.true; + + expect(moduleInfo.recordName.indexOf(ENTRYABILITY_TS_RECORDNAME) > 0 || + 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; + }) + }); + + mocha.it('3-1-1: test updateCachedSourceMaps under build debug: cacheSourceMapPath not exist', function () { + this.rollup.build(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.cacheSourceMapPath = ''; + newSourceMaps[ENTRYABILITY_TS_PATH_DEFAULT] = {}; + newSourceMaps[INDEX_ETS_PATH_DEFAULT] = {}; + moduleMode.updateCachedSourceMapsMock(); + for (const key in moduleMode.cacheSourceMapObject) { + expect(newSourceMaps[key] === moduleMode.cacheSourceMapObject[key]).to.be.true; + } + for (const key of Object.keys(newSourceMaps)) { + delete newSourceMaps[key]; + } + }); + + mocha.it('3-1-2: test updateCachedSourceMaps under build debug: compileFileList has not sourceFileAbsolutePath', function () { + this.rollup.build(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.cacheSourceMapPath = EXPECT_SOURCEMAP_JSON; + newSourceMaps[ENTRYABILITY_TS_PATH_DEFAULT] = { FILE: '' }; + newSourceMaps[INDEX_ETS_PATH_DEFAULT] = { FILE: '' }; + moduleMode.updateCachedSourceMapsMock(); + for (const key in moduleMode.cacheSourceMapObject) { + expect(newSourceMaps[key] === moduleMode.cacheSourceMapObject[key]).to.be.true; + } + + 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" }; + moduleMode.updateCachedSourceMapsMock(); + for (const key in moduleMode.cacheSourceMapObject) { + expect(newSourceMaps[key] === moduleMode.cacheSourceMapObject[key]).to.be.true; + } + + for (const key of Object.keys(newSourceMaps)) { + delete newSourceMaps[key]; + } + }); + + mocha.it('3-2: test updateCachedSourceMaps under build release', function () { + this.rollup.build(RELEASE); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.cacheSourceMapPath = ''; + newSourceMaps[ENTRYABILITY_TS_PATH_DEFAULT] = {}; + newSourceMaps[INDEX_ETS_PATH_DEFAULT] = {}; + moduleMode.updateCachedSourceMapsMock(); + for (const key in moduleMode.cacheSourceMapObject) { + expect(newSourceMaps[key] === moduleMode.cacheSourceMapObject[key]).to.be.true; + } + for (const key of Object.keys(newSourceMaps)) { + delete newSourceMaps[key]; + } + }); + + mocha.it('3-3: test updateCachedSourceMaps under preview debug', function () { + this.rollup.preview(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.cacheSourceMapPath = ''; + newSourceMaps[ENTRYABILITY_TS_PATH_DEFAULT] = {}; + newSourceMaps[INDEX_ETS_PATH_DEFAULT] = {}; + moduleMode.updateCachedSourceMapsMock(); + for (const key in moduleMode.cacheSourceMapObject) { + expect(newSourceMaps[key] === moduleMode.cacheSourceMapObject[key]).to.be.true; + } + for (const key of Object.keys(newSourceMaps)) { + delete newSourceMaps[key]; + } + }); + + mocha.it('3-4: test updateCachedSourceMaps under hot reload debug', function () { + this.rollup.hotReload(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.cacheSourceMapPath = ''; + newSourceMaps[ENTRYABILITY_TS_PATH_DEFAULT] = {}; + newSourceMaps[INDEX_ETS_PATH_DEFAULT] = {}; + moduleMode.updateCachedSourceMapsMock(); + for (const key in moduleMode.cacheSourceMapObject) { + expect(newSourceMaps[key] === moduleMode.cacheSourceMapObject[key]).to.be.true; + } + for (const key of Object.keys(newSourceMaps)) { + delete newSourceMaps[key]; + } + }); + + mocha.it('4-1: test generateCompileFilesInfo under build debug', function () { + this.rollup.build(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.generateCompileFilesInfoMock(); + expect(moduleMode.checkGenerateCompileFilesInfo() === true).to.be.true; + }); + + mocha.it('4-2: test generateCompileFilesInfo under build release', function () { + this.rollup.build(RELEASE); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.generateCompileFilesInfoMock(); + expect(moduleMode.checkGenerateCompileFilesInfo() === true).to.be.true; + }); + + mocha.it('4-3: test generateCompileFilesInfo under preview debug', function () { + this.rollup.preview(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.generateCompileFilesInfoMock(); + expect(moduleMode.checkGenerateCompileFilesInfo() === true).to.be.true; + }); + + mocha.it('4-4: test generateCompileFilesInfo under hot reload debug', function () { + this.rollup.hotReload(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.generateCompileFilesInfoMock(); + expect(moduleMode.checkGenerateCompileFilesInfo() === true).to.be.true; + }); + + mocha.it('5-1: test generateNpmEntriesInfo under build debug', function () { + this.rollup.build(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.generateNpmEntriesInfoMock(); + expect(moduleMode.checkGenerateNpmEntriesInfo() === true).to.be.true; + }); + + mocha.it('5-2: test generateNpmEntriesInfo under build release', function () { + this.rollup.build(RELEASE); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.generateNpmEntriesInfoMock(); + expect(moduleMode.checkGenerateNpmEntriesInfo() === true).to.be.true; + }); + + mocha.it('5-3: test generateNpmEntriesInfo under preview debug', function () { + this.rollup.preview(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.generateNpmEntriesInfoMock(); + expect(moduleMode.checkGenerateNpmEntriesInfo() === true).to.be.true; + }); + + mocha.it('5-4: test generateNpmEntriesInfo under hot reload debug', function () { + this.rollup.hotReload(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.generateNpmEntriesInfoMock(); + expect(moduleMode.checkGenerateNpmEntriesInfo() === true).to.be.true; + }); + + mocha.it('6-1: test generateAbcCacheFilesInfo under build debug', function () { + this.rollup.build(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.generateAbcCacheFilesInfoMock(); + expect(moduleMode.checkGenerateAbcCacheFilesInfo() === true).to.be.true; + }); + + mocha.it('6-2: test generateAbcCacheFilesInfo under build release', function () { + this.rollup.build(RELEASE); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.generateAbcCacheFilesInfoMock(); + expect(moduleMode.checkGenerateAbcCacheFilesInfo() === true).to.be.true; + }); + + mocha.it('6-3: test generateAbcCacheFilesInfo under preview debug', function () { + this.rollup.preview(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.generateAbcCacheFilesInfoMock(); + expect(moduleMode.checkGenerateAbcCacheFilesInfo() === true).to.be.true; + }); + + mocha.it('6-4: test generateAbcCacheFilesInfo under hot reload debug', function () { + this.rollup.hotReload(); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup, false, ''); + moduleMode.generateAbcCacheFilesInfoMock(); + expect(moduleMode.checkGenerateAbcCacheFilesInfo() === true).to.be.true; + }); +}); \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/testdata/expect/sourceMaps.json b/compiler/test/ark_compiler_ut/testdata/expect/sourceMaps.json new file mode 100644 index 0000000000000000000000000000000000000000..9eb6ad2559af4324b4dea5af027ca36f53a60508 --- /dev/null +++ b/compiler/test/ark_compiler_ut/testdata/expect/sourceMaps.json @@ -0,0 +1,4 @@ +{ + "/src/main/ets/entryability/EntryAbility.ts":{}, + "/src/main/ets/pages/Index.ets":{} +} \ 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 659e7cef969b27970eecfe74023078f1bd7777cb..1284d8ccaa515dc6e8e8e1f037e982cb3089cdc1 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 @@ -6,15 +6,13 @@ #### 文件列表 -| 文件 | 接口 | 备注 | -| -------------------------- | -------------- | --------------------------------------------------- | -| entry/.preview/module.json | getPackageInfo | 应用于preview模式,读取bundle name, module name信息 | -| entry/build/module.json | getPackageInfo | 应用于build模式,读取bundle name, module name信息 | -| | | | -| | | | -| | | | -| | | | -| | | | -| | | | -| | | | +| 文件 | 接口 | 备注 | +| --------------------------------------------- | ---------------------- | --------------------------------------------------- | +| entry/preview/module.json | getPackageInfo | 应用于preview模式,读取bundle name, module name信息 | +| entry/build/module.json | getPackageInfo | 应用于build模式,读取bundle name, module name信息 | +| entry/build/sourceMaps.json | updateCachedSourceMaps | 应用于build模式(debug),更新CacheSource文件 | +| entry/preview/sourceMaps.json | updateCachedSourceMaps | 应用于preview模式,更新CacheSource文件 | +| entry/build/loader.json | initArkProjectConfig | 应用于build模式,给参数projectConfig.aceBuildJson赋值| +| entry/build/loader_aotMode.json | initArkProjectConfig | 应用于build模式(debug),给参数aceBuildJson赋值 | +| entry/preview/loader.json | initArkProjectConfig | 应用于preview模式,给参数buildJsonInfo赋值 | diff --git a/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/loader.json b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/loader.json new file mode 100644 index 0000000000000000000000000000000000000000..86ec6a1db607ea17b971d7519b285fb1ecd1d748 --- /dev/null +++ b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/loader.json @@ -0,0 +1 @@ +{"modulePathMap":{"entry":"E:\\project\\entry"},"compileMode":"esmodule","projectRootPath":"E:\\project","nodeModulesPath":"E:\\project\\entry\\build\\default\\intermediates\\loader_out\\default\\node_modules","moduleName":"entry","harNameOhmMap":{},"packageManagerType":"ohpm"} diff --git a/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/loader_aotMode.json b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/loader_aotMode.json new file mode 100644 index 0000000000000000000000000000000000000000..f8959b74b7df01dd526d6fea7a46a961e7bb2475 --- /dev/null +++ b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/loader_aotMode.json @@ -0,0 +1 @@ +{"modulePathMap":{"entry":"E:\\project\\entry"},"compileMode":"esmodule","projectRootPath":"E:\\project","nodeModulesPath":"E:\\project\\entry\\build\\default\\intermediates\\loader_out\\default\\node_modules","moduleName":"entry","harNameOhmMap":{},"packageManagerType":"ohpm","anBuildMode":"type","patchConfig":{"oldMapFilePath":"oldMapFilePath_test"}} diff --git a/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/sourceMaps.json b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/sourceMaps.json new file mode 100644 index 0000000000000000000000000000000000000000..9e26dfeeb6e641a33dae4961196235bdb965b21b --- /dev/null +++ b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/build/sourceMaps.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/preview/loader.json b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/preview/loader.json new file mode 100644 index 0000000000000000000000000000000000000000..86ec6a1db607ea17b971d7519b285fb1ecd1d748 --- /dev/null +++ b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/preview/loader.json @@ -0,0 +1 @@ +{"modulePathMap":{"entry":"E:\\project\\entry"},"compileMode":"esmodule","projectRootPath":"E:\\project","nodeModulesPath":"E:\\project\\entry\\build\\default\\intermediates\\loader_out\\default\\node_modules","moduleName":"entry","harNameOhmMap":{},"packageManagerType":"ohpm"} diff --git a/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/.preview/module.json b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/preview/module.json similarity index 100% rename from compiler/test/ark_compiler_ut/testdata/testcase_def/entry/.preview/module.json rename to compiler/test/ark_compiler_ut/testdata/testcase_def/entry/preview/module.json diff --git a/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/preview/sourceMaps.json b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/preview/sourceMaps.json new file mode 100644 index 0000000000000000000000000000000000000000..9e26dfeeb6e641a33dae4961196235bdb965b21b --- /dev/null +++ b/compiler/test/ark_compiler_ut/testdata/testcase_def/entry/preview/sourceMaps.json @@ -0,0 +1 @@ +{} \ No newline at end of file