mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
ObfuscationResult unit test
This commit is contained in:
@@ -85,26 +85,35 @@ describe('JavaScriptObfuscator', () => {
|
||||
assert.isOk(JSON.parse(obfuscationResult.sourceMap).mappings);
|
||||
});
|
||||
|
||||
it('should returns object with obfuscated code and empty source map if `sourceMapMode` is `inline', () => {
|
||||
it('should returns object with obfuscated code with inline source map and empty `sourceMap` if `sourceMapMode` is `inline', () => {
|
||||
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscateWithSourceMap(
|
||||
`var test = 1;`,
|
||||
Object.assign({}, NO_CUSTOM_NODES_PRESET, {
|
||||
sourceMap: true,
|
||||
sourceMapMode: 'inline'
|
||||
})
|
||||
);
|
||||
|
||||
assert.isOk(obfuscationResult.obfuscatedCode);
|
||||
assert.match(
|
||||
obfuscationResult.obfuscatedCode,
|
||||
/sourceMappingURL=data:application\/json;base64/
|
||||
);
|
||||
assert.isNotOk(obfuscationResult.sourceMap);
|
||||
});
|
||||
|
||||
it('should returns object with empty obfuscated code and empty source map if source code is empty', () => {
|
||||
it('should returns object with empty obfuscated code and source map with empty data if source code is empty', () => {
|
||||
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscateWithSourceMap(
|
||||
'',
|
||||
Object.assign({}, NO_CUSTOM_NODES_PRESET)
|
||||
Object.assign({}, NO_CUSTOM_NODES_PRESET, {
|
||||
sourceMap: true
|
||||
})
|
||||
);
|
||||
|
||||
assert.isNotOk(obfuscationResult.obfuscatedCode);
|
||||
assert.isNotOk(obfuscationResult.sourceMap);
|
||||
assert.deepEqual(JSON.parse(obfuscationResult.sourceMap).names, []);
|
||||
assert.deepEqual(JSON.parse(obfuscationResult.sourceMap).sources, []);
|
||||
assert.isNotOk(JSON.parse(obfuscationResult.sourceMap).mappings);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ describe('JavaScriptObfuscatorInternal', () => {
|
||||
|
||||
it('should link obfuscated code with source map', () => {
|
||||
assert.match(obfuscationResult.obfuscatedCode, new RegExp(`sourceMappingURL=${sourceMapUrl}`));
|
||||
assert.isOk(JSON.parse(obfuscationResult.sourceMap).mappings);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { IObfuscationResult } from "../../src/interfaces/IObfuscationResult";
|
||||
|
||||
import { ObfuscationResult } from "../../src/ObfuscationResult";
|
||||
|
||||
const assert: Chai.AssertStatic = require('chai').assert;
|
||||
|
||||
describe('ObfuscationResult', () => {
|
||||
describe('constructor (obfuscatedCode: string, sourceMap: string)', () => {
|
||||
let obfuscatedCode: string = 'obfuscatedCode',
|
||||
obfuscationResult: IObfuscationResult,
|
||||
sourceMap: string = 'sourceMap';
|
||||
|
||||
beforeEach(() => {
|
||||
obfuscationResult = new ObfuscationResult(obfuscatedCode, sourceMap);
|
||||
});
|
||||
|
||||
it('should returns obfuscated code if `.toString()` was called on `ObfuscationResult` object', () => {
|
||||
assert.equal(obfuscationResult.toString(), obfuscatedCode);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user