/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const { expect } = require('chai'); const { ApiDiffPlugin } = require('../../src/index'); const path = require('path'); const fs = require('fs'); describe('diffSingleFile', function () { const testCasesDir = path.join(__dirname, '..', '/ut'); const testCasesFileNames = fs.readdirSync(testCasesDir); const expectFileDir = path.join(__dirname, '..', '/expect'); const outputFilePath = path.join(__dirname, '..', 'output'); if (!fs.existsSync(outputFilePath)) { fs.mkdirSync(outputFilePath); } testCasesFileNames.forEach(fileName => { const oldFileDir = path.join(testCasesDir, fileName, 'old'); const newFileDir = path.join(testCasesDir, fileName, 'new'); const expectFilePath = path.resolve(expectFileDir, `${fileName}.json`); it(`testDiff# ${fileName}`, function () { let argumentObject = { "old": oldFileDir, "new": newFileDir, "oldVersion": fileName, "newVersion": fileName, "output": outputFilePath }; ApiDiffPlugin.start(argumentObject); const resultFileName = `diff(${argumentObject.oldVersion}_${argumentObject.newVersion}).json` const resultFilePath = path.resolve(argumentObject.output, resultFileName); const resultFileContent = fs.readFileSync(resultFilePath, 'utf-8').replace(/\n|\r|\s/g, ''); const expectContent = fs.readFileSync(expectFilePath, 'utf-8').replace(/\n|\r|\s/g, ''); expect(resultFileContent).to.be.equal(expectContent); }); }); });