1/*
2 * Copyright (c) 2024 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
16import { describe, it } from 'mocha';
17import { TransformerManager } from '../../../src/transformers/TransformerManager';
18import { assert } from 'chai';
19import { FileUtils } from '../../../src/utils/FileUtils';
20import path from 'path';
21import { IOptions } from '../../../src/configs/IOptions';
22import { TransformerFactory, Node } from 'typescript';
23
24describe('Tester Cases for <FileUtils>.', function () {
25  it('Tester: loade transformers for obfuscation config', function () {
26    let mCustomProfiles: IOptions | undefined = FileUtils.readFileAsJson(path.join(__dirname, "default_config.json"));
27    assert.strictEqual(mCustomProfiles !== undefined, true);
28    let mTransformers: TransformerFactory<Node>[] = [];
29    if (mCustomProfiles) {
30      mTransformers = new TransformerManager(mCustomProfiles).getTransformers();
31      assert.strictEqual(mTransformers.length, 3);
32      assert.strictEqual(mTransformers.toString().includes('shorthandPropertyTransformFactory'), true);
33      assert.strictEqual(mTransformers.toString().includes('renameIdentifierFactory'), true);
34      assert.strictEqual(mTransformers.toString().includes('renamePropertiesFactory'), false);
35    }
36
37    mCustomProfiles = FileUtils.readFileAsJson(path.join(__dirname, "property_obf_config.json"));
38    assert.strictEqual(mCustomProfiles !== undefined, true);
39    if (mCustomProfiles) {
40      mTransformers = new TransformerManager(mCustomProfiles).getTransformers();
41      assert.strictEqual(mTransformers.length, 4);
42      assert.strictEqual(mTransformers.toString().includes('shorthandPropertyTransformFactory'), true);
43      assert.strictEqual(mTransformers.toString().includes('renameIdentifierFactory'), true);
44      assert.strictEqual(mTransformers.toString().includes('renamePropertiesFactory'), true);
45    }
46  });
47});
48