• 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
16namespace ts {
17  const fs: typeof import('fs') = require('fs');
18  const path: typeof import('path') = require('path');
19  const childProcess: typeof import('child_process') = require('child_process');
20
21  const rootPath = path.resolve(__dirname);
22
23  async function tscEtsCompile() {
24    const tsconfigPath = path.join(rootPath, '../../tests/dets/tsconfig.json');
25    const tscpath = path.join(rootPath, '../../lib/tsc.js');
26
27    const cmd = 'node ' + tscpath + ' -p ' + tsconfigPath;
28
29    await childProcess.exec(cmd, {
30      maxBuffer: 1 * 1024 * 1024,
31      cwd: undefined
32    }, (error, stdout, stderr) => {
33      if (error) {
34        console.log(cmd);
35        console.log('==> error ' + JSON.stringify(error));
36        console.log('==> stdout ' + String(stdout));
37        console.log('==> stderr ' + String(stderr));
38        console.log('\r\n');
39        return;
40      }
41    });
42  }
43
44  function getActualAndExpect(caseName: string) {
45    const actualDeclarationPath = path.join(rootPath, '../../tests/dets/baselines/local', caseName);
46    const expectedDeclarationPath = path.join(rootPath, '../../tests/dets/baselines/reference', caseName);
47
48    const actualDeclaration = fs.readFileSync(actualDeclarationPath, 'utf-8');
49    const expectedDeclaration = fs.readFileSync(expectedDeclarationPath, 'utf-8');
50    return { actualDeclaration, expectedDeclaration };
51  }
52  describe('unittests:: tsc:: run ets tests::', () => {
53    tscEtsCompile();
54
55    it("arkuiGrammarChecker.ets", () => {
56      const {actualDeclaration, expectedDeclaration} = getActualAndExpect("arkuiGrammarChecker.d.ets");
57      expect(expectedDeclaration).to.be.equal(actualDeclaration);
58    });
59
60    it('componentParameterIsObject.ets', () => {
61      const {actualDeclaration, expectedDeclaration} = getActualAndExpect('componentParameterIsObject.d.ets');
62      expect(expectedDeclaration).to.be.equal(actualDeclaration);
63    });
64
65    it('customDecorator.ets', () => {
66      const {actualDeclaration, expectedDeclaration} = getActualAndExpect('customDecorator.d.ets');
67      expect(expectedDeclaration).to.be.equal(actualDeclaration);
68    });
69
70    it('decoratorWithParameters.ets', () => {
71      const {actualDeclaration, expectedDeclaration} = getActualAndExpect('decoratorWithParameters.d.ets');
72      expect(expectedDeclaration).to.be.equal(actualDeclaration);
73    });
74
75    it('dynamicallyBuildUIElements.ets', () => {
76      const {actualDeclaration, expectedDeclaration} = getActualAndExpect('dynamicallyBuildUIElements.d.ets');
77      expect(expectedDeclaration).to.be.equal(actualDeclaration);
78    });
79
80    it('functionAndClassWithDecorator.ets', () => {
81      const {actualDeclaration, expectedDeclaration} = getActualAndExpect('functionAndClassWithDecorator.d.ets');
82      expect(expectedDeclaration).to.be.equal(actualDeclaration);
83    });
84
85    it('functionWithDecorators.ets', () => {
86      const {actualDeclaration, expectedDeclaration} = getActualAndExpect('functionWithDecorators.d.ets');
87      expect(expectedDeclaration).to.be.equal(actualDeclaration);
88    });
89
90    it('limitationAndExtension.ets', () => {
91      const {actualDeclaration, expectedDeclaration} = getActualAndExpect('limitationAndExtension.d.ets');
92      expect(expectedDeclaration).to.be.equal(actualDeclaration);
93    });
94
95    it('renderControl.ets', () => {
96      const {actualDeclaration, expectedDeclaration} = getActualAndExpect('renderControl.d.ets');
97      expect(expectedDeclaration).to.be.equal(actualDeclaration);
98    });
99
100    it('statusManagementOfApplicationLevelVariables.ets', () => {
101      const {actualDeclaration, expectedDeclaration} = getActualAndExpect('statusManagementOfApplicationLevelVariables.d.ets');
102      expect(expectedDeclaration).to.be.equal(actualDeclaration);
103    });
104
105    it('statusManagementOfPageLevelVariables.ets', () => {
106      const {actualDeclaration, expectedDeclaration} = getActualAndExpect('statusManagementOfPageLevelVariables.d.ets');
107      expect(expectedDeclaration).to.be.equal(actualDeclaration);
108    });
109
110    it('targetEtsExample.ets', () => {
111      const { actualDeclaration, expectedDeclaration } = getActualAndExpect('targetEtsExample.d.ets');
112      expect(expectedDeclaration).to.be.equal(actualDeclaration);
113    });
114  });
115}
116