Skip to content

Commit b82407f

Browse files
committed
ObjectExpressionObfuscator tests
1 parent 48b656d commit b82407f

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { IObfuscationResult } from "../../../src/interfaces/IObfuscationResult";
2+
3+
import { NO_CUSTOM_NODES_PRESET } from "../../../src/preset-options/NoCustomNodesPreset";
4+
5+
import { JavaScriptObfuscator } from "../../../src/JavaScriptObfuscator";
6+
7+
const assert: Chai.AssertStatic = require('chai').assert;
8+
9+
describe('ObjectExpressionObfuscator', () => {
10+
it('should replace object expression node `key` property with literal value by unicode value', () => {
11+
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
12+
`var test = { 'foo': 0 };`,
13+
Object.assign({}, NO_CUSTOM_NODES_PRESET)
14+
);
15+
16+
assert.match(obfuscationResult.getObfuscatedCode(), /^var *test *= *\{'\\x66\\x6f\\x6f':0x0\};$/);
17+
});
18+
19+
it('should replace object expression node `key` property with identifier value by unicode value', () => {
20+
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
21+
`var test = { foo: 0 };`,
22+
Object.assign({}, NO_CUSTOM_NODES_PRESET)
23+
);
24+
25+
assert.match(obfuscationResult.getObfuscatedCode(), /^var *test *= *\{'\\x66\\x6f\\x6f':0x0\};$/);
26+
});
27+
});

test/index.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ import './functional-tests/JavaScriptObfuscatorInternal.spec';
2626
import './functional-tests/node-obfuscators/LiteralObfuscator.spec';
2727
import './functional-tests/node-obfuscators/MemberExpressionObfuscator.spec';
2828
import './functional-tests/node-obfuscators/MethodDefinitionObfuscator.spec';
29+
import './functional-tests/node-obfuscators/ObjectExpressionObfuscator.spec';

0 commit comments

Comments
 (0)