1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use rollupObject file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { expect } from 'chai'; 17import mocha from 'mocha'; 18 19import { 20 checkArkCompilerCacheInfo, 21 utCache 22} from '../../../lib/fast_build/ark_compiler/cache'; 23import { 24 IS_CACHE_INVALID, 25 ARK_COMPILER_META_INFO, 26 RELEASE 27} from '../../../lib/fast_build/ark_compiler/common/ark_define'; 28import RollUpPluginMock from '../mock/rollup_mock/rollup_plugin_mock'; 29import { SDK_VERSION_MOCK } from '../mock/rollup_mock/common'; 30 31mocha.describe('test cache file api', function () { 32 mocha.before(function () { 33 this.rollup = new RollUpPluginMock(); 34 }); 35 36 mocha.after(() => { 37 delete this.rollup; 38 }); 39 40 mocha.it('1-1: test checkArkCompilerCacheInfo under build debug', function () { 41 this.rollup.build(); 42 this.rollup.clearCache(); 43 checkArkCompilerCacheInfo(this.rollup); 44 expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 45 expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 46 47 this.rollup.share.projectConfig.setCompilerVersion(SDK_VERSION_MOCK); 48 checkArkCompilerCacheInfo(this.rollup); 49 expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 50 expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 51 }); 52 53 mocha.it('1-2: test checkArkCompilerCacheInfo under build release', function () { 54 this.rollup.build(RELEASE); 55 this.rollup.clearCache(); 56 checkArkCompilerCacheInfo(this.rollup); 57 expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 58 expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 59 60 this.rollup.share.projectConfig.setCompilerVersion(SDK_VERSION_MOCK); 61 checkArkCompilerCacheInfo(this.rollup); 62 expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 63 expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 64 }); 65 66 mocha.it('1-3: test checkArkCompilerCacheInfo under preview debug', function () { 67 this.rollup.preview(); 68 this.rollup.clearCache(); 69 checkArkCompilerCacheInfo(this.rollup); 70 expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 71 expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 72 73 this.rollup.share.projectConfig.setCompilerVersion(SDK_VERSION_MOCK); 74 checkArkCompilerCacheInfo(this.rollup); 75 expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 76 expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 77 78 this.rollup.mockProjectConfigMockParams(); 79 checkArkCompilerCacheInfo(this.rollup); 80 expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 81 expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 82 }); 83 84 mocha.it('1-4: test checkArkCompilerCacheInfo under hot reload debug', function () { 85 this.rollup.hotReload(); 86 this.rollup.clearCache(); 87 88 checkArkCompilerCacheInfo(this.rollup); 89 expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 90 expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 91 92 this.rollup.share.projectConfig.setCompilerVersion(SDK_VERSION_MOCK); 93 checkArkCompilerCacheInfo(this.rollup); 94 expect(this.rollup.cache.get(ARK_COMPILER_META_INFO).length > 0).to.be.true; 95 expect(this.rollup.cache.get(IS_CACHE_INVALID) === true).to.be.true; 96 }); 97 98 mocha.it('2-1: test getMetaInfo under build debug', function () { 99 this.rollup.build(); 100 const metaInfoArr = JSON.stringify(this.rollup.cache.get(ARK_COMPILER_META_INFO)); 101 const returnInfo = JSON.stringify(utCache.getMetaInfo(this.rollup.share.projectConfig)); 102 expect(metaInfoArr === returnInfo).to.be.true; 103 }); 104 105 mocha.it('2-2: test getMetaInfo under build release', function () { 106 this.rollup.build(RELEASE); 107 const metaInfoArr = JSON.stringify(this.rollup.cache.get(ARK_COMPILER_META_INFO)); 108 const returnInfo = JSON.stringify(utCache.getMetaInfo(this.rollup.share.projectConfig)); 109 expect(metaInfoArr === returnInfo).to.be.true; 110 }); 111 112 mocha.it('2-3: test getMetaInfo under preview debug', function () { 113 this.rollup.preview(); 114 const metaInfoArr = JSON.stringify(this.rollup.cache.get(ARK_COMPILER_META_INFO)); 115 const returnInfo = JSON.stringify(utCache.getMetaInfo(this.rollup.share.projectConfig)); 116 expect(metaInfoArr === returnInfo).to.be.true; 117 }); 118 119 mocha.it('2-4: test getMetaInfo under hot reload debug', function () { 120 this.rollup.hotReload(); 121 const metaInfoArr = JSON.stringify(this.rollup.cache.get(ARK_COMPILER_META_INFO)); 122 const returnInfo = JSON.stringify(utCache.getMetaInfo(this.rollup.share.projectConfig)); 123 expect(metaInfoArr === returnInfo).to.be.true; 124 }); 125});