1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this 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 16'use strict'; 17 18const fs = require('fs'); 19const path =require('path'); 20 21const chai = require('chai'); 22const sinon = require('sinon'); 23const sinonChai = require('sinon-chai'); 24const expect = chai.expect; 25chai.use(sinonChai); 26 27function getActualJSON(componentName, filaName) { 28 const filePath = path.join(__dirname,"testcase/build/pages",`${componentName}`, filaName + `.json`); 29 if(!fs.existsSync(filePath)){ 30 return {} 31 } 32 const fileContent = fs.readFileSync(filePath, "utf-8"); 33 const fileString = fileContent.toString(); 34 return JSON.parse(fileString); 35} 36 37function getExpectJSON(componentName, filaName) { 38 const filePath = path.join(__dirname, "expected", `${componentName}`, filaName + `.json`); 39 if(!fs.existsSync(filePath)){ 40 return {} 41 } 42 const expectedContent = fs.readFileSync(filePath, "utf-8"); 43 const expectedObj = JSON.parse(expectedContent.toString()); 44 return expectedObj; 45} 46 47describe('build', () => { 48 it('commonAttr', () => { 49 const page = 'commonAttr' 50 expect(getActualJSON(page, 'commonAttr')).eql(getExpectJSON(page, 'commonAttr')); 51 }); 52 it('event', () => { 53 const page = 'event' 54 expect(getActualJSON(page, 'event')).eql(getExpectJSON(page, 'event')); 55 }); 56 it('expression', () => { 57 const page = 'expression' 58 expect(getActualJSON(page, 'expression')).eql(getExpectJSON(page, 'expression')); 59 }); 60 it('exteriorStyle', () => { 61 const page = 'exteriorStyle' 62 expect(getActualJSON(page, 'exteriorStyl')).eql(getExpectJSON(page, 'exteriorStyl')); 63 }); 64 it('ifAttr', () => { 65 const page = 'ifAttr' 66 expect(getActualJSON(page, 'ifAttr')).eql(getExpectJSON(page, 'ifAttr')); 67 }); 68 it('importCSS', () => { 69 const page = 'importCSS' 70 expect(getActualJSON(page, 'importCSS')).eql(getExpectJSON(page, 'importCSS')); 71 }); 72 it('importLess', () => { 73 const page = 'importLess' 74 expect(getActualJSON(page, 'importLess')).eql(getExpectJSON(page, 'importLess')); 75 }); 76 it('inlineStyle', () => { 77 const page = 'inlineStyle' 78 expect(getActualJSON(page, 'inlineStyle')).eql(getExpectJSON(page, 'inlineStyle')); 79 }); 80 it('mediaQuery', () => { 81 const page = 'mediaQuery' 82 expect(getActualJSON(page, 'mediaQuer')).eql(getExpectJSON(page, 'mediaQuer')); 83 }); 84 it('privateAttr', () => { 85 const page = 'privateAttr' 86 expect(getActualJSON(page, 'privateAttr')).eql(getExpectJSON(page, 'privateAttr')); 87 }); 88 it('showAttr', () => { 89 const page = 'showAttr' 90 expect(getActualJSON(page, 'showAttr')).eql(getExpectJSON(page, 'showAttr')); 91 }); 92 it('withJS', () => { 93 const page = 'withJS' 94 expect(getActualJSON(page, 'withJS')).eql(getExpectJSON(page, 'withJS')); 95 }) 96});