107ac75b1Sopenharmony_ci/* 207ac75b1Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 307ac75b1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 407ac75b1Sopenharmony_ci * you may not use rollupObject file except in compliance with the License. 507ac75b1Sopenharmony_ci * You may obtain a copy of the License at 607ac75b1Sopenharmony_ci * 707ac75b1Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 807ac75b1Sopenharmony_ci * 907ac75b1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1007ac75b1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1107ac75b1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1207ac75b1Sopenharmony_ci * See the License for the specific language governing permissions and 1307ac75b1Sopenharmony_ci * limitations under the License. 1407ac75b1Sopenharmony_ci */ 1507ac75b1Sopenharmony_ci 1607ac75b1Sopenharmony_ciimport { expect } from 'chai'; 1707ac75b1Sopenharmony_ciimport mocha from 'mocha'; 1807ac75b1Sopenharmony_ci 1907ac75b1Sopenharmony_ciimport { 2007ac75b1Sopenharmony_ci checkArkCompilerCacheInfo, 2107ac75b1Sopenharmony_ci utCache 2207ac75b1Sopenharmony_ci} from '../../../lib/fast_build/ark_compiler/cache'; 2307ac75b1Sopenharmony_ciimport { 2407ac75b1Sopenharmony_ci IS_CACHE_INVALID, 2507ac75b1Sopenharmony_ci ARK_COMPILER_META_INFO, 2607ac75b1Sopenharmony_ci RELEASE 2707ac75b1Sopenharmony_ci} from '../../../lib/fast_build/ark_compiler/common/ark_define'; 2807ac75b1Sopenharmony_ciimport RollUpPluginMock from '../mock/rollup_mock/rollup_plugin_mock'; 2907ac75b1Sopenharmony_ciimport { SDK_VERSION_MOCK } from '../mock/rollup_mock/common'; 3007ac75b1Sopenharmony_ci 3107ac75b1Sopenharmony_cimocha.describe('test cache file api', function () { 3207ac75b1Sopenharmony_ci mocha.before(function () { 3307ac75b1Sopenharmony_ci this.rollup = new RollUpPluginMock(); 3407ac75b1Sopenharmony_ci }); 3507ac75b1Sopenharmony_ci 3607ac75b1Sopenharmony_ci mocha.after(() => { 3707ac75b1Sopenharmony_ci delete this.rollup; 3807ac75b1Sopenharmony_ci }); 3907ac75b1Sopenharmony_ci 4007ac75b1Sopenharmony_ci mocha.it('1-1: test checkArkCompilerCacheInfo under build debug', function () { 4107ac75b1Sopenharmony_ci this.rollup.build(); 4207ac75b1Sopenharmony_ci this.rollup.clearCache(); 4307ac75b1Sopenharmony_ci checkArkCompilerCacheInfo(this.rollup); 4407ac75b1Sopenharmony_ci expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 4507ac75b1Sopenharmony_ci expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 4607ac75b1Sopenharmony_ci 4707ac75b1Sopenharmony_ci this.rollup.share.projectConfig.setCompilerVersion(SDK_VERSION_MOCK); 4807ac75b1Sopenharmony_ci checkArkCompilerCacheInfo(this.rollup); 4907ac75b1Sopenharmony_ci expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 5007ac75b1Sopenharmony_ci expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 5107ac75b1Sopenharmony_ci }); 5207ac75b1Sopenharmony_ci 5307ac75b1Sopenharmony_ci mocha.it('1-2: test checkArkCompilerCacheInfo under build release', function () { 5407ac75b1Sopenharmony_ci this.rollup.build(RELEASE); 5507ac75b1Sopenharmony_ci this.rollup.clearCache(); 5607ac75b1Sopenharmony_ci checkArkCompilerCacheInfo(this.rollup); 5707ac75b1Sopenharmony_ci expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 5807ac75b1Sopenharmony_ci expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 5907ac75b1Sopenharmony_ci 6007ac75b1Sopenharmony_ci this.rollup.share.projectConfig.setCompilerVersion(SDK_VERSION_MOCK); 6107ac75b1Sopenharmony_ci checkArkCompilerCacheInfo(this.rollup); 6207ac75b1Sopenharmony_ci expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 6307ac75b1Sopenharmony_ci expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 6407ac75b1Sopenharmony_ci }); 6507ac75b1Sopenharmony_ci 6607ac75b1Sopenharmony_ci mocha.it('1-3: test checkArkCompilerCacheInfo under preview debug', function () { 6707ac75b1Sopenharmony_ci this.rollup.preview(); 6807ac75b1Sopenharmony_ci this.rollup.clearCache(); 6907ac75b1Sopenharmony_ci checkArkCompilerCacheInfo(this.rollup); 7007ac75b1Sopenharmony_ci expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 7107ac75b1Sopenharmony_ci expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 7207ac75b1Sopenharmony_ci 7307ac75b1Sopenharmony_ci this.rollup.share.projectConfig.setCompilerVersion(SDK_VERSION_MOCK); 7407ac75b1Sopenharmony_ci checkArkCompilerCacheInfo(this.rollup); 7507ac75b1Sopenharmony_ci expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 7607ac75b1Sopenharmony_ci expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 7707ac75b1Sopenharmony_ci 7807ac75b1Sopenharmony_ci this.rollup.mockProjectConfigMockParams(); 7907ac75b1Sopenharmony_ci checkArkCompilerCacheInfo(this.rollup); 8007ac75b1Sopenharmony_ci expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 8107ac75b1Sopenharmony_ci expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 8207ac75b1Sopenharmony_ci }); 8307ac75b1Sopenharmony_ci 8407ac75b1Sopenharmony_ci mocha.it('1-4: test checkArkCompilerCacheInfo under hot reload debug', function () { 8507ac75b1Sopenharmony_ci this.rollup.hotReload(); 8607ac75b1Sopenharmony_ci this.rollup.clearCache(); 8707ac75b1Sopenharmony_ci 8807ac75b1Sopenharmony_ci checkArkCompilerCacheInfo(this.rollup); 8907ac75b1Sopenharmony_ci expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 9007ac75b1Sopenharmony_ci expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 9107ac75b1Sopenharmony_ci 9207ac75b1Sopenharmony_ci this.rollup.share.projectConfig.setCompilerVersion(SDK_VERSION_MOCK); 9307ac75b1Sopenharmony_ci checkArkCompilerCacheInfo(this.rollup); 9407ac75b1Sopenharmony_ci expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 9507ac75b1Sopenharmony_ci expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 9607ac75b1Sopenharmony_ci }); 9707ac75b1Sopenharmony_ci 9807ac75b1Sopenharmony_ci mocha.it('2-1: test getMetaInfo under build debug', function () { 9907ac75b1Sopenharmony_ci this.rollup.build(); 10007ac75b1Sopenharmony_ci const metaInfoArr = JSON.stringify(this.rollup.cache.get(ARK_COMPILER_META_INFO)); 10107ac75b1Sopenharmony_ci const returnInfo = JSON.stringify(utCache.getMetaInfo(this.rollup.share.projectConfig)); 10207ac75b1Sopenharmony_ci expect(metaInfoArr === returnInfo).to.be.true; 10307ac75b1Sopenharmony_ci }); 10407ac75b1Sopenharmony_ci 10507ac75b1Sopenharmony_ci mocha.it('2-2: test getMetaInfo under build release', function () { 10607ac75b1Sopenharmony_ci this.rollup.build(RELEASE); 10707ac75b1Sopenharmony_ci const metaInfoArr = JSON.stringify(this.rollup.cache.get(ARK_COMPILER_META_INFO)); 10807ac75b1Sopenharmony_ci const returnInfo = JSON.stringify(utCache.getMetaInfo(this.rollup.share.projectConfig)); 10907ac75b1Sopenharmony_ci expect(metaInfoArr === returnInfo).to.be.true; 11007ac75b1Sopenharmony_ci }); 11107ac75b1Sopenharmony_ci 11207ac75b1Sopenharmony_ci mocha.it('2-3: test getMetaInfo under preview debug', function () { 11307ac75b1Sopenharmony_ci this.rollup.preview(); 11407ac75b1Sopenharmony_ci const metaInfoArr = JSON.stringify(this.rollup.cache.get(ARK_COMPILER_META_INFO)); 11507ac75b1Sopenharmony_ci const returnInfo = JSON.stringify(utCache.getMetaInfo(this.rollup.share.projectConfig)); 11607ac75b1Sopenharmony_ci expect(metaInfoArr === returnInfo).to.be.true; 11707ac75b1Sopenharmony_ci }); 11807ac75b1Sopenharmony_ci 11907ac75b1Sopenharmony_ci mocha.it('2-4: test getMetaInfo under hot reload debug', function () { 12007ac75b1Sopenharmony_ci this.rollup.hotReload(); 12107ac75b1Sopenharmony_ci const metaInfoArr = JSON.stringify(this.rollup.cache.get(ARK_COMPILER_META_INFO)); 12207ac75b1Sopenharmony_ci const returnInfo = JSON.stringify(utCache.getMetaInfo(this.rollup.share.projectConfig)); 12307ac75b1Sopenharmony_ci expect(metaInfoArr === returnInfo).to.be.true; 12407ac75b1Sopenharmony_ci }); 12507ac75b1Sopenharmony_ci});