diff --git a/compiler/test/ark_compiler_ut/ets_checker.test.ts b/compiler/test/ark_compiler_ut/ets_checker.test.ts index 522fd3f106247bb6c88e763f964fb1fd5dfd3176..fd100ef494571cddbfad5db9ebe6c595ed661383 100644 --- a/compiler/test/ark_compiler_ut/ets_checker.test.ts +++ b/compiler/test/ark_compiler_ut/ets_checker.test.ts @@ -202,116 +202,6 @@ mocha.describe('test ets_checker file api', function () { let program: ts.Program = ts.createProgram(fileNames, compilerOptions); expect(program.getEmitHost()).to.not.be.undefined; }); - - mocha.it('2-1: test resolveModuleNames parse 1.2 module declaration files', function () { - const code: string = 'import { a } from "har";\nconsole.log(a);\n'; - const moduleNames: string[] = [ - 'har', - 'har/test' - ]; - arkTSEvolutionModuleMap.set('har', { - language: '1.2', - packageName: 'har', - moduleName: 'har', - modulePath: `${PROJECT_ROOT}/${DEFAULT_PROJECT}/har`, - declgenV1OutPath: `${PROJECT_ROOT}/${DEFAULT_PROJECT}/har/build/default/intermediates/declgen/default/declgenV1`, - declgenBridgeCodePath: `${PROJECT_ROOT}/${DEFAULT_PROJECT}/har/build/default/intermediates/declgen/default/bridgecode` - }) - const filePath: string = `${PROJECT_ROOT}/${DEFAULT_PROJECT}/${DEFAULT_ENTRY}/src/main/entryability/test.ets`; - const arktsEvoIndexDeclFilePath: string = `${arkTSEvolutionModuleMap.get('har').declgenV1OutPath}/har/Index.d.ets`; - const arktsEvoTestDeclFilePath: string = `${arkTSEvolutionModuleMap.get('har').declgenV1OutPath}/har/src/main/ets/test.d.ets`; - fs.writeFileSync(filePath, code); - mkdirsSync(path.dirname(arktsEvoIndexDeclFilePath)); - mkdirsSync(path.dirname(arktsEvoTestDeclFilePath)); - fs.writeFileSync(arktsEvoIndexDeclFilePath, ''); - fs.writeFileSync(arktsEvoTestDeclFilePath, ''); - const resolvedModules = resolveModuleNamesMain(moduleNames, filePath); - expect(resolvedModules[0].resolvedFileName === arktsEvoIndexDeclFilePath).to.be.true; - expect(resolvedModules[1].resolvedFileName === arktsEvoTestDeclFilePath).to.be.true; - fs.unlinkSync(filePath); - fs.unlinkSync(arktsEvoIndexDeclFilePath); - fs.unlinkSync(arktsEvoTestDeclFilePath); - cleanUpProcessArkTSEvolutionObj(); - }); - - mocha.it('2-2: test resolveModuleNames parse the 1.2 module declaration file that the 1.1 module depends on (packageName)', function () { - const moduleNames: string[] = ['testhar']; - arkTSEvolutionModuleMap.set('har', { - language: '1.2', - packageName: 'testhar', - moduleName: 'testhar', - modulePath: `${PROJECT_ROOT}/${DEFAULT_PROJECT}/testhar`, - declgenV1OutPath: `${PROJECT_ROOT}/${DEFAULT_PROJECT}/testhar/build/default/intermediates/declgen/default/declgenV1`, - declgenBridgeCodePath: `${PROJECT_ROOT}/${DEFAULT_PROJECT}/testhar/build/default/intermediates/declgen/default/bridgecode` - }) - const filePath: string = `${PROJECT_ROOT}/${DEFAULT_PROJECT}/${DEFAULT_ENTRY}/src/main/entryability/test.ets`; - const arktsEvoIndexFilePath: string = `${PROJECT_ROOT}/${DEFAULT_PROJECT}/testhar/Index.ets`; - const arktsEvoIndexDeclFilePath: string = `${arkTSEvolutionModuleMap.get('har').declgenV1OutPath}/testhar/Index.d.ets`; - const resolveModuleNameStub = sinon.stub(ts, 'resolveModuleName').returns({ - resolvedModule: { - resolvedFileName: arktsEvoIndexFilePath, - extension: '.ets', - isExternalLibraryImport: false, - } - }); - const mockedTs = { - ...require('typescript'), - resolveModuleName: resolveModuleNameStub - }; - let resolveModuleNames; - ({ resolveModuleNames } = proxyquire('../../lib/ets_checker', { - 'typescript': mockedTs - })); - fs.writeFileSync(filePath, ''); - mkdirsSync(path.dirname(arktsEvoIndexFilePath)); - mkdirsSync(path.dirname(arktsEvoIndexDeclFilePath)); - fs.writeFileSync(arktsEvoIndexFilePath, ''); - fs.writeFileSync(arktsEvoIndexDeclFilePath, ''); - const resolvedModules = resolveModuleNames(moduleNames, filePath); - expect(resolvedModules[0].resolvedFileName === arktsEvoIndexDeclFilePath); - fs.unlinkSync(filePath); - fs.unlinkSync(arktsEvoIndexDeclFilePath); - resolveModuleNameStub.restore(); - }); - - mocha.it('2-3: test resolveModuleNames parse the 1.2 module declaration file that the 1.1 module depends on', function () { - const moduleNames: string[] = ['testhar/src/main/ets/test']; - arkTSEvolutionModuleMap.set('testharPkg', { - language: '1.2', - packageName: 'testharPkg', - moduleName: 'testhar', - modulePath: `${PROJECT_ROOT}/${DEFAULT_PROJECT}/testhar`, - declgenV1OutPath: `${PROJECT_ROOT}/${DEFAULT_PROJECT}/testhar/build/default/intermediates/declgen/default/declgenV1`, - declgenBridgeCodePath: `${PROJECT_ROOT}/${DEFAULT_PROJECT}/testhar/build/default/intermediates/declgen/default/bridgecode` - }) - const filePath: string = `${PROJECT_ROOT}/${DEFAULT_PROJECT}/${DEFAULT_ENTRY}/src/main/entryability/test.ets`; - const arktsEvoTestFilePath: string = `${PROJECT_ROOT}/${DEFAULT_PROJECT}/testhar/src/main/ets/test.ets`; - const arktsEvoTestDeclFilePath: string = `${arkTSEvolutionModuleMap.get('testharPkg').declgenV1OutPath}/testharPkg/src/main/ets/test.d.ets`; - const resolveModuleNameStub = sinon.stub(ts, 'resolveModuleName').returns({ - resolvedModule: { - resolvedFileName: arktsEvoTestFilePath, - extension: '.ets', - isExternalLibraryImport: false, - } - }); - const mockedTs = { - ...require('typescript'), - resolveModuleName: resolveModuleNameStub - }; - let resolveModuleNames; - ({ resolveModuleNames } = proxyquire('../../lib/ets_checker', { 'typescript': mockedTs })); - - fs.writeFileSync(filePath, ''); - mkdirsSync(path.dirname(arktsEvoTestFilePath)); - mkdirsSync(path.dirname(arktsEvoTestDeclFilePath)); - fs.writeFileSync(arktsEvoTestFilePath, ''); - fs.writeFileSync(arktsEvoTestDeclFilePath, ''); - const resolvedModules = resolveModuleNames(moduleNames, filePath); - expect(resolvedModules[0].resolvedFileName === arktsEvoTestDeclFilePath); - fs.unlinkSync(filePath); - fs.unlinkSync(arktsEvoTestDeclFilePath); - resolveModuleNameStub.restore(); - }); }); mocha.describe('getMaxFlowDepth', () => { diff --git a/compiler/test/ark_compiler_ut/interop/interop_manager.test.ts b/compiler/test/ark_compiler_ut/interop/interop_manager.test.ts index 179df238b6e83367ca6f1c39a4e95d448d0dc898..f731c20ebc193829fdfcfd9dd38b8b9ff4ec91bc 100644 --- a/compiler/test/ark_compiler_ut/interop/interop_manager.test.ts +++ b/compiler/test/ark_compiler_ut/interop/interop_manager.test.ts @@ -23,6 +23,8 @@ import { isBridgeCode } from '../../../lib/fast_build/ark_compiler/interop/interop_manager'; import { ARKTS_1_1, ARKTS_1_2, HYBRID } from '../../../lib/fast_build/ark_compiler/interop/type'; +import { sdkConfigs } from '../../../main'; +import { toUnixPath } from '../../../lib/utils'; export interface ArkTSEvolutionModule { language: string; @@ -241,12 +243,13 @@ mocha.describe('test interop_manager file api', function () { '/mock/ets-loader/declarations', '/mock/ets-loader/components', '/component', - '/mock/ets-loader', - '/mnt/data/z00893105/dev/developtools/api', - '/mnt/data/z00893105/dev/developtools/arkts', - '/mnt/data/z00893105/dev/developtools/kits' + '/mock/ets-loader' ]); - + sdkConfigs.forEach(({ apiPath }) => { + apiPath.forEach(path => { + expectedDynamicSDKPath.add(toUnixPath(path)); + }); + }); const expectedStaticInteropDecl = new Set([ '/ets1.2/build-tools/interop/declarations/kits', '/ets1.2/build-tools/interop/declarations/api', @@ -258,7 +261,6 @@ mocha.describe('test interop_manager file api', function () { '/ets1.2/build-tools/interop/bridge/api', '/ets1.2/build-tools/interop/bridge/arkts' ]); - expect([...result.dynamicSDKPath]).to.have.deep.members([...expectedDynamicSDKPath]); expect([...result.staticSDKInteropDecl]).to.have.deep.members([...expectedStaticInteropDecl]); expect([...result.staticSDKGlueCodePath]).to.have.deep.members([...expectedStaticGlueCode]); @@ -274,29 +276,29 @@ mocha.describe('isBridgeCode', function () { ]), }; - mocha.it('20-1: should return true when filePath is inside a declgenBridgeCodePath', function () { + mocha.it('1-1: should return true when filePath is inside a declgenBridgeCodePath', function () { const filePath = path.resolve('project/bridge/pkgA/utils/helper.ts'); expect(isBridgeCode(filePath, mockConfig)).to.be.true; }); - mocha.it('20-2: should return false when filePath is outside all bridge code paths', function () { + mocha.it('1-2: should return false when filePath is outside all bridge code paths', function () { const filePath = path.resolve('project/otherpkg/index.ts'); expect(isBridgeCode(filePath, mockConfig)).to.be.false; }); - mocha.it('20-3: should return false when mixCompile is false', function () { + mocha.it('1-3: should return false when mixCompile is false', function () { const config = { ...mockConfig, mixCompile: false }; const filePath = path.resolve('project/bridge/pkgA/utils/helper.ts'); expect(isBridgeCode(filePath, config)).to.be.false; }); - mocha.it('20-4: should return false when dependentModuleMap is empty', function () { + mocha.it('1-4: should return false when dependentModuleMap is empty', function () { const config = { mixCompile: true, dependentModuleMap: new Map() }; const filePath = path.resolve('project/bridge/pkgA/file.ts'); expect(isBridgeCode(filePath, config)).to.be.false; }); - mocha.it('20-5: should return true for multiple matches, stop at first match', function () { + mocha.it('1-5: should return true for multiple matches, stop at first match', function () { const config = { mixCompile: true, dependentModuleMap: new Map([