it('should replace object expression node `key` property with literal value by unicode value', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( `var test = { 'foo': 0 };`, Object.assign({}, NO_CUSTOM_NODES_PRESET) ); assert.match(obfuscationResult.getObfuscatedCode(), /^var *test *= *\{'\\x66\\x6f\\x6f':0x0\};$/); });
it('should replace member expression dot notation call by square brackets call with unicode literal value', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( `var test = console.log;`, Object.assign({}, NO_CUSTOM_NODES_PRESET) ); assert.match(obfuscationResult.getObfuscatedCode(), /var *test *= *console\['\\x6c\\x6f\\x67'\];/); });
it('should not obfuscate method definition node with `constructor` key', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( code, Object.assign({}, NO_CUSTOM_NODES_PRESET) ); assert.match(obfuscationResult.getObfuscatedCode(), /constructor\(\)\{\}/); });
it('stack frames', () => { try { dummy1(); assert.ok(false); } catch (e) { assert.match(e.stack, /dummy2[\s\S]*?dummy1/); } });
it('should replace method definition node `key` property with unicode value', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( code, Object.assign({}, NO_CUSTOM_NODES_PRESET) ); assert.match(obfuscationResult.getObfuscatedCode(), /\['\\x62\\x61\\x72'\]\(\)\{\}/); });
it('should obfuscate simple code with variable inside global scope', () => { assert.match( JavaScriptObfuscator.obfuscate( `var test = 1;`, Object.assign({}, NO_CUSTOM_NODES_PRESET) ).getObfuscatedCode(), /^var *test *= *0x\d+;$/ ); });
helper.dataDrivenTest(tests, function(data, expect) { try { parse(data); } catch (e) { assert.match(e.message, expect); return; } assert.fail(undefined, undefined, "No exception thrown."); });
test('will log to a file when asked to', async() => { const {client, baseDir} = await createTestEnvironment(); const logFile = join(baseDir, 'pes.log'); await client.changeConfiguration({logToFile: logFile}); await delay(100); assert.match( readFileSync(logFile, 'utf-8'), /^\n\n\n\n\nInitialized with workspace path:/); });
it('should obfuscate simple code with variable inside block-scope', () => { assert.match( JavaScriptObfuscator.obfuscate( `(function () {var test = 1;})()`, Object.assign({}, NO_CUSTOM_NODES_PRESET) ).getObfuscatedCode(), /^\(function *\(\) *\{ *var *_0x[\w]+ *= *0x\d+; *\}(\(\)\)|\)\(\));?$/ ); });
it('should add source map import to obfuscated code if source map mode is `separate`', () => { expectedObfuscationResult = getCorrectedObfuscationResult( obfuscatedCode, sourceMap, 'output.js.map', SourceMapMode.Separate ); assert.match(expectedObfuscationResult.getObfuscatedCode(), /sourceMappingURL=output\.js\.map/); });