• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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
16const { expect } = require('chai');
17const path = require('path');
18const fs = require('fs');
19const { ApiCollector } = require('../../src/api_collector');
20
21describe('collectApi', function () {
22  // 传参获得
23  const sdkPath = process.argv[process.argv.length - 1];
24  const appDir = path.join(__dirname, '..', '/ut/');
25  const outputDir = path.join(__dirname, '..', '/output');
26  const expectFileDir = path.join(__dirname, '..', '/expect/');
27  const appProjectNames = fs.readdirSync(appDir);
28  appProjectNames.forEach(projectName => {
29    let appProjectPath = path.join(appDir, projectName);
30    let expectFilePath = path.join(expectFileDir, `${projectName}.json`);
31    it('testFile# ' + path.basename(appProjectPath), function () {
32      const expectFileContent = fs.readFileSync(expectFilePath, 'utf-8').replace(/\n|\r|\s/g, '');
33      const argv = {
34        app: appProjectPath,
35        sdk: sdkPath,
36        output: outputDir,
37        format: 'json',
38      };
39      const collector = new ApiCollector(argv);
40      collector.start();
41      const outputFileName = fs.readdirSync(outputDir);
42      const outputFilePath = path.join(outputDir, outputFileName[0]);
43      const outputFileContent = fs.readFileSync(outputFilePath, 'utf-8').replace(/\n|\r|\s/g, '');
44      expect(outputFileContent).to.be.equal(expectFileContent);
45    });
46  });
47});