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 expect = chai.expect; 24 25function getActualJSON(componentName, filaName) { 26 const filePath = path.join(__dirname,"testcase/build/pages",`${componentName}`, filaName + `.json`); 27 if(!fs.existsSync(filePath)){ 28 return {} 29 } 30 const fileContent = fs.readFileSync(filePath, "utf-8"); 31 const fileString = fileContent.toString(); 32 return JSON.parse(fileString); 33} 34 35function getExpectJSON(componentName, filaName) { 36 const filePath = path.join(__dirname, "expected", `${componentName}`, filaName + `.json`); 37 if(!fs.existsSync(filePath)){ 38 return {} 39 } 40 const expectedContent = fs.readFileSync(filePath, "utf-8"); 41 const expectedObj = JSON.parse(expectedContent.toString()); 42 return expectedObj; 43} 44 45describe('build', () => { 46 it('commonAttr', () => { 47 const page = 'commonAttr' 48 expect(getActualJSON(page, 'commonAttr')).eql(getExpectJSON(page, 'commonAttr')); 49 }); 50 it('event', () => { 51 const page = 'event' 52 expect(getActualJSON(page, 'event')).eql(getExpectJSON(page, 'event')); 53 }); 54 it('expression', () => { 55 const page = 'expression' 56 expect(getActualJSON(page, 'expression')).eql(getExpectJSON(page, 'expression')); 57 }); 58 it('exteriorStyle', () => { 59 const page = 'exteriorStyle' 60 expect(getActualJSON(page, 'exteriorStyl')).eql(getExpectJSON(page, 'exteriorStyl')); 61 }); 62 it('ifAttr', () => { 63 const page = 'ifAttr' 64 expect(getActualJSON(page, 'ifAttr')).eql(getExpectJSON(page, 'ifAttr')); 65 }); 66 it('importCSS', () => { 67 const page = 'importCSS' 68 expect(getActualJSON(page, 'importCSS')).eql(getExpectJSON(page, 'importCSS')); 69 }); 70 it('importLess', () => { 71 const page = 'importLess' 72 expect(getActualJSON(page, 'importLess')).eql(getExpectJSON(page, 'importLess')); 73 }); 74 it('inlineStyle', () => { 75 const page = 'inlineStyle' 76 expect(getActualJSON(page, 'inlineStyle')).eql(getExpectJSON(page, 'inlineStyle')); 77 }); 78 it('mediaQuery', () => { 79 const page = 'mediaQuery' 80 expect(getActualJSON(page, 'mediaQuer')).eql(getExpectJSON(page, 'mediaQuer')); 81 }); 82 it('privateAttr', () => { 83 const page = 'privateAttr' 84 expect(getActualJSON(page, 'privateAttr')).eql(getExpectJSON(page, 'privateAttr')); 85 }); 86 it('showAttr', () => { 87 const page = 'showAttr' 88 expect(getActualJSON(page, 'showAttr')).eql(getExpectJSON(page, 'showAttr')); 89 }); 90 it('withJS', () => { 91 const page = 'withJS' 92 expect(getActualJSON(page, 'withJS')).eql(getExpectJSON(page, 'withJS')); 93 }) 94});