mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Some refactoring
This commit is contained in:
@@ -3,7 +3,7 @@ import { assert } from 'chai';
|
||||
import { StackTraceAnalyzer } from '../../../../src/analyzers/stack-trace-analyzer/StackTraceAnalyzer';
|
||||
|
||||
describe('StackTraceAnalyzer', () => {
|
||||
describe('getLimitIndex (blockScopeBodyLength: number): number', () => {
|
||||
describe('getLimitIndex', () => {
|
||||
let limitIndex: number;
|
||||
|
||||
describe('Variant #1: length - 10000', () => {
|
||||
|
||||
@@ -3,47 +3,45 @@ import { assert } from 'chai';
|
||||
import { ArraySanitizer } from '../../../../src/cli/sanitizers/ArraySanitizer';
|
||||
|
||||
describe('ArraySanitizer', () => {
|
||||
describe('ArraySanitizer: TCLISanitizer = (value: string): string[]', () => {
|
||||
describe('Variant #1: input value `foo`', () => {
|
||||
const inputValue: string = 'foo';
|
||||
const expectedValue: string[] = ['foo'];
|
||||
describe('Variant #1: input value `foo`', () => {
|
||||
const inputValue: string = 'foo';
|
||||
const expectedValue: string[] = ['foo'];
|
||||
|
||||
let value: string[];
|
||||
let value: string[];
|
||||
|
||||
before(() => {
|
||||
value = ArraySanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.deepEqual(value, expectedValue);
|
||||
});
|
||||
before(() => {
|
||||
value = ArraySanitizer(inputValue);
|
||||
});
|
||||
|
||||
describe('Variant #2: input value `foo, bar`', () => {
|
||||
const inputValue: string = 'foo, bar';
|
||||
const expectedValue: string[] = ['foo', 'bar'];
|
||||
it('should sanitize value', () => {
|
||||
assert.deepEqual(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
let value: string[];
|
||||
describe('Variant #2: input value `foo, bar`', () => {
|
||||
const inputValue: string = 'foo, bar';
|
||||
const expectedValue: string[] = ['foo', 'bar'];
|
||||
|
||||
before(() => {
|
||||
value = ArraySanitizer(inputValue);
|
||||
});
|
||||
let value: string[];
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.deepEqual(value, expectedValue);
|
||||
});
|
||||
before(() => {
|
||||
value = ArraySanitizer(inputValue);
|
||||
});
|
||||
|
||||
describe('Variant #3: input value `foo,`', () => {
|
||||
const inputValue: string = 'foo,';
|
||||
it('should sanitize value', () => {
|
||||
assert.deepEqual(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
const testFunc: () => void = () => {
|
||||
ArraySanitizer(inputValue);
|
||||
};
|
||||
describe('Variant #3: input value `foo,`', () => {
|
||||
const inputValue: string = 'foo,';
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.throw(testFunc, SyntaxError);
|
||||
});
|
||||
const testFunc: () => void = () => {
|
||||
ArraySanitizer(inputValue);
|
||||
};
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.throw(testFunc, SyntaxError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,65 +4,63 @@ import { BooleanSanitizer } from '../../../../src/cli/sanitizers/BooleanSanitize
|
||||
|
||||
|
||||
describe('BooleanSanitizer', () => {
|
||||
describe('BooleanSanitizer: TCLISanitizer = (value: string): boolean', () => {
|
||||
describe('Variant #1: input value `true`', () => {
|
||||
const inputValue: string = 'true';
|
||||
const expectedValue: boolean = true;
|
||||
describe('Variant #1: input value `true`', () => {
|
||||
const inputValue: string = 'true';
|
||||
const expectedValue: boolean = true;
|
||||
|
||||
let value: boolean;
|
||||
let value: boolean;
|
||||
|
||||
before(() => {
|
||||
value = BooleanSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
before(() => {
|
||||
value = BooleanSanitizer(inputValue);
|
||||
});
|
||||
|
||||
describe('Variant #2: input value `1`', () => {
|
||||
const inputValue: string = '1';
|
||||
const expectedValue: boolean = true;
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
let value: boolean;
|
||||
describe('Variant #2: input value `1`', () => {
|
||||
const inputValue: string = '1';
|
||||
const expectedValue: boolean = true;
|
||||
|
||||
before(() => {
|
||||
value = BooleanSanitizer(inputValue);
|
||||
});
|
||||
let value: boolean;
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
before(() => {
|
||||
value = BooleanSanitizer(inputValue);
|
||||
});
|
||||
|
||||
describe('Variant #3: input value `false`', () => {
|
||||
const inputValue: string = 'false';
|
||||
const expectedValue: boolean = false;
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
let value: boolean;
|
||||
describe('Variant #3: input value `false`', () => {
|
||||
const inputValue: string = 'false';
|
||||
const expectedValue: boolean = false;
|
||||
|
||||
before(() => {
|
||||
value = BooleanSanitizer(inputValue);
|
||||
});
|
||||
let value: boolean;
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
before(() => {
|
||||
value = BooleanSanitizer(inputValue);
|
||||
});
|
||||
|
||||
describe('Variant #4: input value `foo`', () => {
|
||||
const inputValue: string = 'foo';
|
||||
const expectedValue: boolean = false;
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
let value: boolean;
|
||||
describe('Variant #4: input value `foo`', () => {
|
||||
const inputValue: string = 'foo';
|
||||
const expectedValue: boolean = false;
|
||||
|
||||
before(() => {
|
||||
value = BooleanSanitizer(inputValue);
|
||||
});
|
||||
let value: boolean;
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
before(() => {
|
||||
value = BooleanSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,34 +3,32 @@ import { assert } from 'chai';
|
||||
import { IdentifierNamesGeneratorSanitizer } from '../../../../src/cli/sanitizers/IdentifierNamesGeneratorSanitizer';
|
||||
|
||||
describe('IdentifierNamesGeneratorSanitizer', () => {
|
||||
describe('IdentifierNamesGeneratorSanitizer: TCLISanitizer = (value: string): string', () => {
|
||||
describe('Variant #1: valid identifier names generator', () => {
|
||||
const inputValue: string = 'mangled';
|
||||
const expectedValue: string = inputValue;
|
||||
describe('Variant #1: valid identifier names generator', () => {
|
||||
const inputValue: string = 'mangled';
|
||||
const expectedValue: string = inputValue;
|
||||
|
||||
let value: string;
|
||||
let value: string;
|
||||
|
||||
before(() => {
|
||||
value = IdentifierNamesGeneratorSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
before(() => {
|
||||
value = IdentifierNamesGeneratorSanitizer(inputValue);
|
||||
});
|
||||
|
||||
describe('Variant #2: invalid identifier names generator', () => {
|
||||
const inputValue: string = 'foo';
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
let testFunc: () => void;
|
||||
describe('Variant #2: invalid identifier names generator', () => {
|
||||
const inputValue: string = 'foo';
|
||||
|
||||
before(() => {
|
||||
testFunc = () => IdentifierNamesGeneratorSanitizer(inputValue);
|
||||
});
|
||||
let testFunc: () => void;
|
||||
|
||||
it('should throw error', () => {
|
||||
assert.throw(testFunc, ReferenceError);
|
||||
});
|
||||
before(() => {
|
||||
testFunc = () => IdentifierNamesGeneratorSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should throw error', () => {
|
||||
assert.throw(testFunc, ReferenceError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,34 +3,32 @@ import { assert } from 'chai';
|
||||
import { ObfuscationTargetSanitizer } from '../../../../src/cli/sanitizers/ObfuscatingTargetSanitizer';
|
||||
|
||||
describe('ObfuscationTargetSanitizer', () => {
|
||||
describe('ObfuscationTargetSanitizer: TCLISanitizer = (value: string): string', () => {
|
||||
describe('Variant #1: valid obfuscation target', () => {
|
||||
const inputValue: string = 'browser';
|
||||
const expectedValue: string = inputValue;
|
||||
describe('Variant #1: valid obfuscation target', () => {
|
||||
const inputValue: string = 'browser';
|
||||
const expectedValue: string = inputValue;
|
||||
|
||||
let value: string;
|
||||
let value: string;
|
||||
|
||||
before(() => {
|
||||
value = ObfuscationTargetSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
before(() => {
|
||||
value = ObfuscationTargetSanitizer(inputValue);
|
||||
});
|
||||
|
||||
describe('Variant #2: invalid obfuscation target', () => {
|
||||
const inputValue: string = 'foo';
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
let testFunc: () => void;
|
||||
describe('Variant #2: invalid obfuscation target', () => {
|
||||
const inputValue: string = 'foo';
|
||||
|
||||
before(() => {
|
||||
testFunc = () => ObfuscationTargetSanitizer(inputValue);
|
||||
});
|
||||
let testFunc: () => void;
|
||||
|
||||
it('should throw error', () => {
|
||||
assert.throw(testFunc, ReferenceError);
|
||||
});
|
||||
before(() => {
|
||||
testFunc = () => ObfuscationTargetSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should throw error', () => {
|
||||
assert.throw(testFunc, ReferenceError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,34 +3,32 @@ import { assert } from 'chai';
|
||||
import { SourceMapModeSanitizer } from '../../../../src/cli/sanitizers/SourceMapModeSanitizer';
|
||||
|
||||
describe('SourceMapModeSanitizer', () => {
|
||||
describe('SourceMapModeSanitizer: TCLISanitizer = (value: string): string', () => {
|
||||
describe('Variant #1: valid source map mode', () => {
|
||||
const inputValue: string = 'inline';
|
||||
const expectedValue: string = inputValue;
|
||||
describe('Variant #1: valid source map mode', () => {
|
||||
const inputValue: string = 'inline';
|
||||
const expectedValue: string = inputValue;
|
||||
|
||||
let value: string;
|
||||
let value: string;
|
||||
|
||||
before(() => {
|
||||
value = SourceMapModeSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
before(() => {
|
||||
value = SourceMapModeSanitizer(inputValue);
|
||||
});
|
||||
|
||||
describe('Variant #2: invalid source map mode', () => {
|
||||
const inputValue: string = 'foo';
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
let testFunc: () => void;
|
||||
describe('Variant #2: invalid source map mode', () => {
|
||||
const inputValue: string = 'foo';
|
||||
|
||||
before(() => {
|
||||
testFunc = () => SourceMapModeSanitizer(inputValue);
|
||||
});
|
||||
let testFunc: () => void;
|
||||
|
||||
it('should throw error', () => {
|
||||
assert.throw(testFunc, ReferenceError);
|
||||
});
|
||||
before(() => {
|
||||
testFunc = () => SourceMapModeSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should throw error', () => {
|
||||
assert.throw(testFunc, ReferenceError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,80 +7,78 @@ import { StringArrayEncoding } from '../../../../src/enums/StringArrayEncoding';
|
||||
import { StringArrayEncodingSanitizer } from '../../../../src/cli/sanitizers/StringArrayEncodingSanitizer';
|
||||
|
||||
describe('StringArrayEncodingSanitizer', () => {
|
||||
describe('StringArrayEncodingSanitizer: TCLISanitizer = (value: string): TStringArrayEncoding', () => {
|
||||
describe('Variant #1: string array encoding `base64`', () => {
|
||||
const inputValue: string = 'base64';
|
||||
const expectedValue: TStringArrayEncoding = true;
|
||||
describe('Variant #1: string array encoding `base64`', () => {
|
||||
const inputValue: string = 'base64';
|
||||
const expectedValue: TStringArrayEncoding = true;
|
||||
|
||||
let value: TStringArrayEncoding;
|
||||
let value: TStringArrayEncoding;
|
||||
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
});
|
||||
|
||||
describe('Variant #2: string array encoding `true`', () => {
|
||||
const inputValue: string = 'true';
|
||||
const expectedValue: TStringArrayEncoding = true;
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
let value: TStringArrayEncoding;
|
||||
describe('Variant #2: string array encoding `true`', () => {
|
||||
const inputValue: string = 'true';
|
||||
const expectedValue: TStringArrayEncoding = true;
|
||||
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
});
|
||||
let value: TStringArrayEncoding;
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
});
|
||||
|
||||
describe('Variant #3: string array encoding `1`', () => {
|
||||
const inputValue: string = '1';
|
||||
const expectedValue: TStringArrayEncoding = true;
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
let value: TStringArrayEncoding;
|
||||
describe('Variant #3: string array encoding `1`', () => {
|
||||
const inputValue: string = '1';
|
||||
const expectedValue: TStringArrayEncoding = true;
|
||||
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
});
|
||||
let value: TStringArrayEncoding;
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
});
|
||||
|
||||
describe('Variant #4: string array encoding `rc4`', () => {
|
||||
const inputValue: string = 'rc4';
|
||||
const expectedValue: TStringArrayEncoding = StringArrayEncoding.Rc4;
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
let value: TStringArrayEncoding;
|
||||
describe('Variant #4: string array encoding `rc4`', () => {
|
||||
const inputValue: string = 'rc4';
|
||||
const expectedValue: TStringArrayEncoding = StringArrayEncoding.Rc4;
|
||||
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
});
|
||||
let value: TStringArrayEncoding;
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
});
|
||||
|
||||
describe('Variant #5: string array encoding `foo`', () => {
|
||||
const inputValue: string = 'foo';
|
||||
const expectedValue: TStringArrayEncoding = false;
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
let value: TStringArrayEncoding;
|
||||
describe('Variant #5: string array encoding `foo`', () => {
|
||||
const inputValue: string = 'foo';
|
||||
const expectedValue: TStringArrayEncoding = false;
|
||||
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
});
|
||||
let value: TStringArrayEncoding;
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import { TInputOptions } from '../../../../src/types/options/TInputOptions';
|
||||
import { CLIUtils } from '../../../../src/cli/utils/CLIUtils';
|
||||
|
||||
describe('CLIUtils', () => {
|
||||
describe('getOutputCodePath (inputPath: string): string', () => {
|
||||
describe('getOutputCodePath', () => {
|
||||
describe('Variant #1: base input path', () => {
|
||||
let expectedOutputPath: string = 'test/input/test-obfuscated.js',
|
||||
inputPath: string = 'test/input/test.js';
|
||||
@@ -25,7 +25,7 @@ describe('CLIUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getOutputSourceMapPath (outputCodePath: string): string', () => {
|
||||
describe('getOutputSourceMapPath', () => {
|
||||
let expectedOutputSourceMapPath: string = 'test/output/test.js.map',
|
||||
outputCodePath: string = 'test/output/test.js';
|
||||
|
||||
@@ -34,7 +34,7 @@ describe('CLIUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getUserConfig (configPath: string): Object', () => {
|
||||
describe('getUserConfig', () => {
|
||||
describe('Variant #1: valid config file path', () => {
|
||||
describe('Variant #1: js file with config', () => {
|
||||
const configDirName: string = 'test/fixtures';
|
||||
|
||||
@@ -18,7 +18,7 @@ describe('SourceCodeReader', () => {
|
||||
mkdirp.sync(tmpDirectoryPath);
|
||||
});
|
||||
|
||||
describe('readSourceCode (inputPath: string): TSourceCodeData', () => {
|
||||
describe('readSourceCode', () => {
|
||||
describe('Variant #1: input path is a file path', () => {
|
||||
describe('Variant #1: `inputPath` is a valid path', () => {
|
||||
const tmpFileName: string = 'test.js';
|
||||
|
||||
@@ -6,195 +6,193 @@ import { initializable } from '../../../../src/decorators/Initializable';
|
||||
import { IInitializable } from '../../../../src/interfaces/IInitializable';
|
||||
|
||||
describe('@initializable', () => {
|
||||
describe('initializable (initializeMethodKey: string): any', () => {
|
||||
describe('Variant #1: property was initialized', () => {
|
||||
describe('Variant #1: property was initialized', () => {
|
||||
const testFunc: () => void = () => {
|
||||
class Foo implements IInitializable {
|
||||
@initializable()
|
||||
public property!: string;
|
||||
|
||||
public initialize (property: string): void {
|
||||
this.property = property;
|
||||
}
|
||||
}
|
||||
|
||||
const foo: Foo = new Foo();
|
||||
|
||||
foo.initialize('baz');
|
||||
|
||||
foo.property;
|
||||
};
|
||||
|
||||
it('shouldn\'t throws an errors if property was initialized', () => {
|
||||
assert.doesNotThrow(testFunc, Error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: `initialize` method should be called first', () => {
|
||||
describe('Variant #1: `initialize` method was called first', () => {
|
||||
const testFunc: () => void = () => {
|
||||
class Foo implements IInitializable {
|
||||
class Foo {
|
||||
@initializable()
|
||||
public property!: string;
|
||||
|
||||
public initialize (property: string): void {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public bar (): void {}
|
||||
}
|
||||
|
||||
const foo: Foo = new Foo();
|
||||
|
||||
foo.initialize('baz');
|
||||
foo.bar();
|
||||
};
|
||||
|
||||
it('shouldn\'t throw an error if `initialize` method was called first', () => {
|
||||
assert.doesNotThrow(testFunc, /Class should be initialized/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: other method was called inside `initialize` method with initialization of the property', () => {
|
||||
const testFunc: () => void = () => {
|
||||
class Foo {
|
||||
@initializable()
|
||||
public property!: string;
|
||||
|
||||
public initialize (property: string): void {
|
||||
this.innerInitialize(property);
|
||||
}
|
||||
|
||||
public innerInitialize (property: string): void {
|
||||
this.property = property;
|
||||
}
|
||||
}
|
||||
|
||||
const foo: Foo = new Foo();
|
||||
|
||||
foo.initialize('baz');
|
||||
|
||||
foo.property;
|
||||
};
|
||||
|
||||
it('shouldn\'t throws an errors if property was initialized', () => {
|
||||
assert.doesNotThrow(testFunc, Error);
|
||||
it('shouldn\'t throw an error if other method was called inside `initialize` method', () => {
|
||||
assert.doesNotThrow(testFunc, /Class should be initialized/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: `initialize` method should be called first', () => {
|
||||
describe('Variant #1: `initialize` method was called first', () => {
|
||||
const testFunc: () => void = () => {
|
||||
class Foo {
|
||||
@initializable()
|
||||
public property!: string;
|
||||
|
||||
public initialize (property: string): void {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public bar (): void {}
|
||||
}
|
||||
|
||||
const foo: Foo = new Foo();
|
||||
|
||||
foo.initialize('baz');
|
||||
foo.bar();
|
||||
};
|
||||
|
||||
it('shouldn\'t throw an error if `initialize` method was called first', () => {
|
||||
assert.doesNotThrow(testFunc, /Class should be initialized/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: other method was called inside `initialize` method with initialization of the property', () => {
|
||||
const testFunc: () => void = () => {
|
||||
class Foo {
|
||||
@initializable()
|
||||
public property!: string;
|
||||
|
||||
public initialize (property: string): void {
|
||||
this.innerInitialize(property);
|
||||
}
|
||||
|
||||
public innerInitialize (property: string): void {
|
||||
this.property = property;
|
||||
}
|
||||
}
|
||||
|
||||
const foo: Foo = new Foo();
|
||||
|
||||
foo.initialize('baz');
|
||||
};
|
||||
|
||||
it('shouldn\'t throw an error if other method was called inside `initialize` method', () => {
|
||||
assert.doesNotThrow(testFunc, /Class should be initialized/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #3: other method was called inside `initialize` method without initialization of the property', () => {
|
||||
const testFunc: () => void = () => {
|
||||
class Foo {
|
||||
@initializable()
|
||||
public property!: string;
|
||||
|
||||
public initialize (property: string): void {
|
||||
this.innerInitialize(property);
|
||||
}
|
||||
|
||||
public innerInitialize (property: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
const foo: Foo = new Foo();
|
||||
|
||||
foo.initialize('baz');
|
||||
};
|
||||
|
||||
it('should throws an error if other method was called inside `initialize` method without initialization of the property', () => {
|
||||
assert.throws(testFunc, /Property `property` is not initialized/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #4: `initialize` method wasn\'t called first', () => {
|
||||
const testFunc: () => void = () => {
|
||||
class Foo {
|
||||
@initializable()
|
||||
public property!: string;
|
||||
|
||||
public initialize (property: string): void {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public bar (): void {}
|
||||
}
|
||||
|
||||
const foo: Foo = new Foo();
|
||||
|
||||
foo.bar();
|
||||
foo.initialize('baz');
|
||||
};
|
||||
|
||||
it('should throws an error if `initialize` method wasn\'t called first', () => {
|
||||
assert.throws(testFunc, /Class should be initialized/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #5: `initialize` method wasn\'t called', () => {
|
||||
const testFunc: () => void = () => {
|
||||
class Foo {
|
||||
@initializable()
|
||||
public property!: string;
|
||||
|
||||
public initialize (property: string): void {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public bar (): void {}
|
||||
}
|
||||
|
||||
const foo: Foo = new Foo();
|
||||
|
||||
foo.bar();
|
||||
};
|
||||
|
||||
it('should throws an error if `initialize` method wasn\'t called first', () => {
|
||||
assert.throws(testFunc, /Class should be initialized/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #3: property didn\'t initialized', () => {
|
||||
describe('Variant #3: other method was called inside `initialize` method without initialization of the property', () => {
|
||||
const testFunc: () => void = () => {
|
||||
class Foo implements IInitializable {
|
||||
class Foo {
|
||||
@initializable()
|
||||
public property!: string;
|
||||
|
||||
public initialize (property: string): void {
|
||||
this.innerInitialize(property);
|
||||
}
|
||||
|
||||
public innerInitialize (property: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
const foo: Foo = new Foo();
|
||||
|
||||
foo.initialize('baz');
|
||||
|
||||
foo.property;
|
||||
};
|
||||
|
||||
it('should throws an error if property didn\'t initialized', () => {
|
||||
it('should throws an error if other method was called inside `initialize` method without initialization of the property', () => {
|
||||
assert.throws(testFunc, /Property `property` is not initialized/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #4: `initialize` method with custom name', () => {
|
||||
describe('Variant #4: `initialize` method wasn\'t called first', () => {
|
||||
const testFunc: () => void = () => {
|
||||
class Foo {
|
||||
@initializable('bar')
|
||||
@initializable()
|
||||
public property!: string;
|
||||
|
||||
public initialize (property: string): void {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public bar (): void {}
|
||||
}
|
||||
|
||||
const foo: Foo = new Foo();
|
||||
|
||||
foo.bar();
|
||||
foo.initialize('baz');
|
||||
|
||||
foo.property;
|
||||
};
|
||||
|
||||
it('should throws an error if `initialize` method with custom name wasn\'t found', () => {
|
||||
assert.throws(testFunc, /method with initialization logic not found/);
|
||||
it('should throws an error if `initialize` method wasn\'t called first', () => {
|
||||
assert.throws(testFunc, /Class should be initialized/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #5: `initialize` method wasn\'t called', () => {
|
||||
const testFunc: () => void = () => {
|
||||
class Foo {
|
||||
@initializable()
|
||||
public property!: string;
|
||||
|
||||
public initialize (property: string): void {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public bar (): void {}
|
||||
}
|
||||
|
||||
const foo: Foo = new Foo();
|
||||
|
||||
foo.bar();
|
||||
};
|
||||
|
||||
it('should throws an error if `initialize` method wasn\'t called first', () => {
|
||||
assert.throws(testFunc, /Class should be initialized/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #3: property didn\'t initialized', () => {
|
||||
const testFunc: () => void = () => {
|
||||
class Foo implements IInitializable {
|
||||
@initializable()
|
||||
public property!: string;
|
||||
|
||||
public initialize (property: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
const foo: Foo = new Foo();
|
||||
|
||||
foo.initialize('baz');
|
||||
|
||||
foo.property;
|
||||
};
|
||||
|
||||
it('should throws an error if property didn\'t initialized', () => {
|
||||
assert.throws(testFunc, /Property `property` is not initialized/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #4: `initialize` method with custom name', () => {
|
||||
const testFunc: () => void = () => {
|
||||
class Foo {
|
||||
@initializable('bar')
|
||||
public property!: string;
|
||||
|
||||
public initialize (property: string): void {
|
||||
this.property = property;
|
||||
}
|
||||
}
|
||||
|
||||
const foo: Foo = new Foo();
|
||||
|
||||
foo.initialize('baz');
|
||||
|
||||
foo.property;
|
||||
};
|
||||
|
||||
it('should throws an error if `initialize` method with custom name wasn\'t found', () => {
|
||||
assert.throws(testFunc, /method with initialization logic not found/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import { IdentifierNamesGenerator } from '../../../../src/enums/generators/ident
|
||||
import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade';
|
||||
|
||||
describe('HexadecimalIdentifierNamesGenerator', () => {
|
||||
describe('generate (): string', () => {
|
||||
describe('generate', () => {
|
||||
let identifierNamesGenerator: IIdentifierNamesGenerator,
|
||||
hexadecimalIdentifierName: string,
|
||||
regExp: RegExp;
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import { IdentifierNamesGenerator } from '../../../../src/enums/generators/ident
|
||||
import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade';
|
||||
|
||||
describe('MangledIdentifierNamesGenerator', () => {
|
||||
describe('generate (): string', () => {
|
||||
describe('generate', () => {
|
||||
let identifierNamesGenerator: IIdentifierNamesGenerator,
|
||||
mangledIdentifierName: string;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { EspreeFacade } from '../../../src/EspreeFacade';
|
||||
|
||||
|
||||
describe('EspreeFacade', () => {
|
||||
describe(`parse (input: string, config: espree.ParseOptions): ESTree.Program`, () => {
|
||||
describe(`parse`, () => {
|
||||
describe(`\`Unexpected token\` error code preview`, () => {
|
||||
describe('Variant #1: 5 lines of code', () => {
|
||||
const sourceCode: string = `` +
|
||||
|
||||
@@ -11,7 +11,7 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../../src/options/presets/NoCusto
|
||||
import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
|
||||
|
||||
describe('JavaScriptObfuscator', () => {
|
||||
describe(`obfuscate (sourceCode: string): IObfuscationResult`, () => {
|
||||
describe(`obfuscate`, () => {
|
||||
describe(`source map`, () => {
|
||||
const code: string = 'var test = 1;';
|
||||
const sourceMapUrl: string = 'test.js.map';
|
||||
|
||||
@@ -17,7 +17,7 @@ import { Logger } from '../../../src/logger/Logger';
|
||||
import { LoggingMessage } from '../../../src/enums/logger/LoggingMessage';
|
||||
|
||||
describe('Logger', () => {
|
||||
describe('log (loggingLevelColor: Chalk, loggingPrefix: LoggingPrefix, loggingMessage: string, value?: string | number): void', () => {
|
||||
describe('log', () => {
|
||||
const loggingMessage: string = '[javascript-obfuscator] foo';
|
||||
const expectedConsoleLogCallResult: boolean = true;
|
||||
|
||||
@@ -46,7 +46,7 @@ describe('Logger', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('info (loggingMessage: LoggingMessage, value?: string | number): void', () => {
|
||||
describe('info', () => {
|
||||
describe('`log` option is enabled', () => {
|
||||
const loggingMessage: string = '[javascript-obfuscator] Obfuscation started...';
|
||||
const expectedConsoleLogCallResult: boolean = true;
|
||||
@@ -117,7 +117,7 @@ describe('Logger', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('success (loggingMessage: LoggingMessage, value?: string | number): void', () => {
|
||||
describe('success', () => {
|
||||
describe('`log` option is enabled', () => {
|
||||
const loggingMessage: string = '[javascript-obfuscator] Obfuscation started...';
|
||||
const expectedConsoleLogCallResult: boolean = true;
|
||||
@@ -188,7 +188,7 @@ describe('Logger', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('warn (loggingMessage: LoggingMessage, value?: string | number): void', () => {
|
||||
describe('warn', () => {
|
||||
describe('`log` option is enabled', () => {
|
||||
const loggingMessage: string = '[javascript-obfuscator] Obfuscation started...';
|
||||
const expectedConsoleLogCallResult: boolean = true;
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ import { NodeUtils } from '../../../../src/node/NodeUtils';
|
||||
import { NodeMetadata } from '../../../../src/node/NodeMetadata';
|
||||
|
||||
describe('ObfuscatingGuardsTransformer', () => {
|
||||
describe('transformNode (node: ESTree.Node, parentNode: ESTree.Node): ESTree.Node', () => {
|
||||
describe('transformNode', () => {
|
||||
let inversifyContainerFacade: IInversifyContainerFacade,
|
||||
obfuscatingGuardsTransformer: INodeTransformer;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ const convertCodeToAst: (fixturePath: string) => ESTree.Program = (fixturePath)
|
||||
};
|
||||
|
||||
describe('NodeAppender', () => {
|
||||
describe('appendNode (blockScopeNode: TNodeWithBlockScope[], nodeBodyStatements: TStatement[]): void', () => {
|
||||
describe('append', () => {
|
||||
let astTree: ESTree.Program,
|
||||
expectedAstTree: ESTree.Program,
|
||||
node: TStatement[];
|
||||
@@ -51,10 +51,10 @@ describe('NodeAppender', () => {
|
||||
astTree = convertCodeToAst('/fixtures/append-node.js');
|
||||
expectedAstTree = convertCodeToAst('/fixtures/append-node-expected.js');
|
||||
|
||||
astTree = NodeUtils.parentize(astTree);
|
||||
expectedAstTree = NodeUtils.parentize(expectedAstTree);
|
||||
astTree = NodeUtils.parentizeAst(astTree);
|
||||
expectedAstTree = NodeUtils.parentizeAst(expectedAstTree);
|
||||
|
||||
NodeAppender.appendNode(astTree, node);
|
||||
NodeAppender.append(astTree, node);
|
||||
});
|
||||
|
||||
it('should append given node to a `BlockStatement` node body', () => {
|
||||
@@ -62,7 +62,7 @@ describe('NodeAppender', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('appendNodeToOptimalBlockScope (blockScopeStackTraceData: IStackTraceData[], blockScopeNode: TNodeWithBlockScope, nodeBodyStatements: TStatement[], index: number = 0): void', () => {
|
||||
describe('appendToOptimalBlockScope', () => {
|
||||
let stackTraceAnalyzer: IStackTraceAnalyzer,
|
||||
astTree: ESTree.Program,
|
||||
expectedAstTree: ESTree.Program,
|
||||
@@ -87,7 +87,7 @@ describe('NodeAppender', () => {
|
||||
expectedAstTree = convertCodeToAst('/fixtures/append-node-to-optimal-block-scope/variant-1-expected.js');
|
||||
|
||||
stackTraceData = stackTraceAnalyzer.analyze(astTree);
|
||||
NodeAppender.appendNodeToOptimalBlockScope(stackTraceData, astTree, node);
|
||||
NodeAppender.appendToOptimalBlockScope(stackTraceData, astTree, node);
|
||||
});
|
||||
|
||||
it('should append node into first and deepest function call in nested function calls', () => {
|
||||
@@ -101,7 +101,7 @@ describe('NodeAppender', () => {
|
||||
expectedAstTree = convertCodeToAst('/fixtures/append-node-to-optimal-block-scope/variant-2-expected.js');
|
||||
|
||||
stackTraceData = stackTraceAnalyzer.analyze(astTree);
|
||||
NodeAppender.appendNodeToOptimalBlockScope(stackTraceData, astTree, node);
|
||||
NodeAppender.appendToOptimalBlockScope(stackTraceData, astTree, node);
|
||||
|
||||
});
|
||||
|
||||
@@ -122,7 +122,7 @@ describe('NodeAppender', () => {
|
||||
expectedAstTree = convertCodeToAst('/fixtures/append-node-to-optimal-block-scope/by-index-variant-1-expected.js');
|
||||
|
||||
stackTraceData = stackTraceAnalyzer.analyze(astTree);
|
||||
NodeAppender.appendNodeToOptimalBlockScope(stackTraceData, astTree, node, 2);
|
||||
NodeAppender.appendToOptimalBlockScope(stackTraceData, astTree, node, 2);
|
||||
|
||||
});
|
||||
|
||||
@@ -136,7 +136,7 @@ describe('NodeAppender', () => {
|
||||
expectedAstTree = convertCodeToAst('/fixtures/append-node-to-optimal-block-scope/by-index-variant-2-expected.js');
|
||||
|
||||
stackTraceData = stackTraceAnalyzer.analyze(astTree);
|
||||
NodeAppender.appendNodeToOptimalBlockScope(stackTraceData, astTree, node, 1);
|
||||
NodeAppender.appendToOptimalBlockScope(stackTraceData, astTree, node, 1);
|
||||
|
||||
});
|
||||
|
||||
@@ -151,7 +151,7 @@ describe('NodeAppender', () => {
|
||||
expectedAstTree = convertCodeToAst('/fixtures/append-node-to-optimal-block-scope/by-index-variant-3-expected.js');
|
||||
|
||||
stackTraceData = stackTraceAnalyzer.analyze(astTree);
|
||||
NodeAppender.appendNodeToOptimalBlockScope(
|
||||
NodeAppender.appendToOptimalBlockScope(
|
||||
stackTraceData,
|
||||
astTree,
|
||||
node,
|
||||
@@ -167,7 +167,7 @@ describe('NodeAppender', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('insertNodeAfter (scopeNode: TNodeWithScope, scopeStatements: TStatement[], targetStatement: ESTree.Statement): void', () => {
|
||||
describe('insertAfter', () => {
|
||||
let astTree: ESTree.Program,
|
||||
expectedAstTree: ESTree.Program,
|
||||
node: TStatement[],
|
||||
@@ -179,10 +179,10 @@ describe('NodeAppender', () => {
|
||||
expectedAstTree = convertCodeToAst('/fixtures/insert-node-after-expected.js');
|
||||
targetStatement = <ESTree.Statement>astTree.body[1];
|
||||
|
||||
astTree = NodeUtils.parentize(astTree);
|
||||
expectedAstTree = NodeUtils.parentize(expectedAstTree);
|
||||
astTree = NodeUtils.parentizeAst(astTree);
|
||||
expectedAstTree = NodeUtils.parentizeAst(expectedAstTree);
|
||||
|
||||
NodeAppender.insertNodeAfter(astTree, node, targetStatement);
|
||||
NodeAppender.insertAfter(astTree, node, targetStatement);
|
||||
});
|
||||
|
||||
it('should insert given node in `BlockStatement` node body after target statement', () => {
|
||||
@@ -190,7 +190,7 @@ describe('NodeAppender', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('insertNodeAtIndex (blockScopeNode: TNodeWithBlockScope[], nodeBodyStatements: TStatement[], index: number): void', () => {
|
||||
describe('insertAtIndex', () => {
|
||||
let astTree: ESTree.Program,
|
||||
expectedAstTree: ESTree.Program,
|
||||
node: TStatement[];
|
||||
@@ -200,10 +200,10 @@ describe('NodeAppender', () => {
|
||||
astTree = convertCodeToAst('/fixtures/insert-node-at-index.js');
|
||||
expectedAstTree = convertCodeToAst('/fixtures/insert-node-at-index-expected.js');
|
||||
|
||||
astTree = NodeUtils.parentize(astTree);
|
||||
expectedAstTree = NodeUtils.parentize(expectedAstTree);
|
||||
astTree = NodeUtils.parentizeAst(astTree);
|
||||
expectedAstTree = NodeUtils.parentizeAst(expectedAstTree);
|
||||
|
||||
NodeAppender.insertNodeAtIndex(astTree, node, 2);
|
||||
NodeAppender.insertAtIndex(astTree, node, 2);
|
||||
});
|
||||
|
||||
it('should insert given node in `BlockStatement` node body at index', () => {
|
||||
@@ -211,7 +211,7 @@ describe('NodeAppender', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('prependNode (blockScopeNode: TNodeWithBlockScope[], nodeBodyStatements: TStatement[]): void', () => {
|
||||
describe('prepend', () => {
|
||||
let astTree: ESTree.Program,
|
||||
expectedAstTree: ESTree.Program,
|
||||
node: TStatement[];
|
||||
@@ -221,10 +221,10 @@ describe('NodeAppender', () => {
|
||||
astTree = convertCodeToAst('/fixtures/prepend-node.js');
|
||||
expectedAstTree = convertCodeToAst('/fixtures/prepend-node-expected.js');
|
||||
|
||||
astTree = NodeUtils.parentize(astTree);
|
||||
expectedAstTree = NodeUtils.parentize(expectedAstTree);
|
||||
astTree = NodeUtils.parentizeAst(astTree);
|
||||
expectedAstTree = NodeUtils.parentizeAst(expectedAstTree);
|
||||
|
||||
NodeAppender.prependNode(astTree, node);
|
||||
NodeAppender.prepend(astTree, node);
|
||||
});
|
||||
|
||||
it('should prepend given node to a `BlockStatement` node body', () => {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { NodeFactory } from '../../../../src/node/NodeFactory';
|
||||
import { NodeUtils } from '../../../../src/node/NodeUtils';
|
||||
|
||||
describe('NodeGuards', () => {
|
||||
describe('isNodeHasBlockScope (node: ESTree.Node): node is TNodeWithBlockScope', () => {
|
||||
describe('isNodeHasBlockScope', () => {
|
||||
describe('truthful checks', () => {
|
||||
describe('Variant #1: block statement of function declaration', () => {
|
||||
const expectedResult: boolean = true;
|
||||
@@ -21,7 +21,7 @@ describe('NodeGuards', () => {
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
NodeUtils.parentize(parentNode);
|
||||
NodeUtils.parentizeAst(parentNode);
|
||||
result = NodeGuards.isNodeHasBlockScope(node, parentNode);
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ describe('NodeGuards', () => {
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
NodeUtils.parentize(parentNode);
|
||||
NodeUtils.parentizeAst(parentNode);
|
||||
result = NodeGuards.isNodeHasBlockScope(node, parentNode);
|
||||
});
|
||||
|
||||
@@ -79,7 +79,7 @@ describe('NodeGuards', () => {
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
NodeUtils.parentize(parentNode);
|
||||
NodeUtils.parentizeAst(parentNode);
|
||||
result = NodeGuards.isNodeHasBlockScope(node, parentNode);
|
||||
});
|
||||
|
||||
@@ -107,7 +107,7 @@ describe('NodeGuards', () => {
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
NodeUtils.parentize(parentNode);
|
||||
NodeUtils.parentizeAst(parentNode);
|
||||
result = NodeGuards.isNodeHasBlockScope(node, parentNode);
|
||||
});
|
||||
|
||||
@@ -127,7 +127,7 @@ describe('NodeGuards', () => {
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
NodeUtils.parentize(parentNode);
|
||||
NodeUtils.parentizeAst(parentNode);
|
||||
result = NodeGuards.isNodeHasBlockScope(node, parentNode);
|
||||
});
|
||||
|
||||
@@ -138,7 +138,7 @@ describe('NodeGuards', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isNodeHasScope (node: ESTree.Node): node is TNodeWithScope', () => {
|
||||
describe('isNodeHasScope', () => {
|
||||
describe('truthful checks', () => {
|
||||
describe('Variant #1: program node', () => {
|
||||
const expectedResult: boolean = true;
|
||||
@@ -258,7 +258,7 @@ describe('NodeGuards', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isReplaceableIdentifierNode (node: ESTree.Node, parentNode: ESTree.Node): node is ESTree.Identifier', () => {
|
||||
describe('isReplaceableIdentifierNode', () => {
|
||||
describe('truthful checks', () => {
|
||||
describe('Variant #1: parent node is function declaration node', () => {
|
||||
const expectedResult: boolean = true;
|
||||
@@ -272,7 +272,7 @@ describe('NodeGuards', () => {
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
NodeUtils.parentize(parentNode);
|
||||
NodeUtils.parentizeAst(parentNode);
|
||||
result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
|
||||
});
|
||||
|
||||
@@ -293,7 +293,7 @@ describe('NodeGuards', () => {
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
NodeUtils.parentize(parentNode);
|
||||
NodeUtils.parentizeAst(parentNode);
|
||||
result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
|
||||
});
|
||||
|
||||
@@ -314,7 +314,7 @@ describe('NodeGuards', () => {
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
NodeUtils.parentize(parentNode);
|
||||
NodeUtils.parentizeAst(parentNode);
|
||||
result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
|
||||
});
|
||||
|
||||
@@ -336,7 +336,7 @@ describe('NodeGuards', () => {
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
NodeUtils.parentize(parentNode);
|
||||
NodeUtils.parentizeAst(parentNode);
|
||||
result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
|
||||
});
|
||||
|
||||
@@ -360,7 +360,7 @@ describe('NodeGuards', () => {
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
NodeUtils.parentize(parentNode);
|
||||
NodeUtils.parentizeAst(parentNode);
|
||||
result = NodeGuards.isReplaceableIdentifierNode(literal, parentNode);
|
||||
});
|
||||
|
||||
@@ -381,7 +381,7 @@ describe('NodeGuards', () => {
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
NodeUtils.parentize(parentNode);
|
||||
NodeUtils.parentizeAst(parentNode);
|
||||
result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
|
||||
});
|
||||
|
||||
@@ -402,7 +402,7 @@ describe('NodeGuards', () => {
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
NodeUtils.parentize(parentNode);
|
||||
NodeUtils.parentizeAst(parentNode);
|
||||
result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
|
||||
});
|
||||
|
||||
@@ -424,7 +424,7 @@ describe('NodeGuards', () => {
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
NodeUtils.parentize(parentNode);
|
||||
NodeUtils.parentizeAst(parentNode);
|
||||
result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
|
||||
});
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ describe('NodeMetadata', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isIgnoredNode (node: ESTree.Node): boolean', () => {
|
||||
describe('isIgnoredNode', () => {
|
||||
const expectedValue: boolean = true;
|
||||
|
||||
let node: ESTree.Identifier,
|
||||
@@ -65,7 +65,7 @@ describe('NodeMetadata', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isRenamedIdentifier (identifierNode: ESTree.Identifier): boolean', () => {
|
||||
describe('isRenamedIdentifier', () => {
|
||||
const expectedValue: boolean = true;
|
||||
|
||||
let node: ESTree.Identifier,
|
||||
@@ -83,7 +83,7 @@ describe('NodeMetadata', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isReplacedLiteral (literalNode: ESTree.Literal): boolean', () => {
|
||||
describe('isReplacedLiteral', () => {
|
||||
const expectedValue: boolean = true;
|
||||
|
||||
let node: ESTree.Literal,
|
||||
|
||||
@@ -10,7 +10,7 @@ import { NodeFactory } from '../../../../src/node/NodeFactory';
|
||||
import { NodeUtils } from '../../../../src/node/NodeUtils';
|
||||
|
||||
describe('NodeUtils', () => {
|
||||
describe('addXVerbatimPropertyToLiterals (node: ESTree.Node): void', () => {
|
||||
describe('addXVerbatimPropertyTo', () => {
|
||||
let literalNode: ESTree.Literal,
|
||||
expectedLiteralNode: ESTree.Literal;
|
||||
|
||||
@@ -20,7 +20,7 @@ describe('NodeUtils', () => {
|
||||
|
||||
expectedLiteralNode = NodeFactory.literalNode('value');
|
||||
|
||||
NodeUtils.addXVerbatimPropertyToLiteralNode(literalNode);
|
||||
NodeUtils.addXVerbatimPropertyTo(literalNode);
|
||||
});
|
||||
|
||||
it('should add `x-verbatim-property` to `Literal` node', () => {
|
||||
@@ -28,7 +28,7 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('clone <T extends ESTree.Node> (astTree: T): T', () => {
|
||||
describe('clone', () => {
|
||||
describe('Variant #1: simple AST-tree', () => {
|
||||
let programNode: ESTree.Program,
|
||||
expectedProgramNode: ESTree.Program;
|
||||
@@ -67,7 +67,7 @@ describe('NodeUtils', () => {
|
||||
ifStatementNode1
|
||||
])
|
||||
);
|
||||
expectedProgramNode = NodeUtils.parentize(
|
||||
expectedProgramNode = NodeUtils.parentizeAst(
|
||||
NodeFactory.programNode([
|
||||
ifStatementNode2
|
||||
])
|
||||
@@ -111,7 +111,7 @@ describe('NodeUtils', () => {
|
||||
expressionStatementNode
|
||||
])
|
||||
);
|
||||
expectedProgramNode = NodeUtils.parentize(
|
||||
expectedProgramNode = NodeUtils.parentizeAst(
|
||||
NodeFactory.programNode([
|
||||
expectedExpressionStatementNode
|
||||
])
|
||||
@@ -124,7 +124,7 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertCodeToStructure (code: string): ESTree.Statement[]', () => {
|
||||
describe('convertCodeToStructure', () => {
|
||||
let structure: TStatement[],
|
||||
expectedStructure: TStatement[];
|
||||
|
||||
@@ -158,7 +158,7 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertStructureToCode (structure: ESTree.Node[]): string', () => {
|
||||
describe('convertStructureToCode', () => {
|
||||
let structure: ESTree.Node[],
|
||||
expectedCode: string;
|
||||
|
||||
@@ -181,7 +181,7 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getBlockScopesOfNode (node: ESTree.Node, blockScopes: TNodeWithBlockScope[] = []): TNodeWithBlockScope[]', () => {
|
||||
describe('getBlockScopesOfNode', () => {
|
||||
let functionDeclarationBlockStatementNode: ESTree.BlockStatement,
|
||||
ifStatementBlockStatementNode1: ESTree.BlockStatement,
|
||||
ifStatementBlockStatementNode2: ESTree.BlockStatement,
|
||||
@@ -296,7 +296,7 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getNextSiblingStatementNode (node: ESTree.Statement): TStatement | null', () => {
|
||||
describe('getNextSiblingStatement', () => {
|
||||
describe('Variant #1: block statement node as scope node', () => {
|
||||
let statementNode1: ESTree.Statement,
|
||||
statementNode2: ESTree.Statement,
|
||||
@@ -325,15 +325,15 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
|
||||
it('should return next sibling statement node', () => {
|
||||
assert.deepEqual(NodeUtils.getNextSiblingStatementNode(statementNode1), statementNode2);
|
||||
assert.deepEqual(NodeUtils.getNextSiblingStatement(statementNode1), statementNode2);
|
||||
});
|
||||
|
||||
it('should return next sibling statement node', () => {
|
||||
assert.deepEqual(NodeUtils.getNextSiblingStatementNode(statementNode2), statementNode3);
|
||||
assert.deepEqual(NodeUtils.getNextSiblingStatement(statementNode2), statementNode3);
|
||||
});
|
||||
|
||||
it('should return `null` if given statement node is last node in the scope', () => {
|
||||
assert.deepEqual(NodeUtils.getNextSiblingStatementNode(statementNode3), null);
|
||||
assert.deepEqual(NodeUtils.getNextSiblingStatement(statementNode3), null);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -368,20 +368,20 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
|
||||
it('should return next sibling statement node', () => {
|
||||
assert.deepEqual(NodeUtils.getNextSiblingStatementNode(statementNode1), statementNode2);
|
||||
assert.deepEqual(NodeUtils.getNextSiblingStatement(statementNode1), statementNode2);
|
||||
});
|
||||
|
||||
it('should return next sibling statement node', () => {
|
||||
assert.deepEqual(NodeUtils.getNextSiblingStatementNode(statementNode2), statementNode3);
|
||||
assert.deepEqual(NodeUtils.getNextSiblingStatement(statementNode2), statementNode3);
|
||||
});
|
||||
|
||||
it('should return `null` if given statement node is last node in the scope', () => {
|
||||
assert.deepEqual(NodeUtils.getNextSiblingStatementNode(statementNode3), null);
|
||||
assert.deepEqual(NodeUtils.getNextSiblingStatement(statementNode3), null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPreviousSiblingStatementNode (node: ESTree.Statement): TStatement | null', () => {
|
||||
describe('getPreviousSiblingStatement', () => {
|
||||
describe('Variant #1: block statement node as scope node', () => {
|
||||
let statementNode1: ESTree.Statement,
|
||||
statementNode2: ESTree.Statement,
|
||||
@@ -410,15 +410,15 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
|
||||
it('should return next sibling statement node', () => {
|
||||
assert.deepEqual(NodeUtils.getPreviousSiblingStatementNode(statementNode1), null);
|
||||
assert.deepEqual(NodeUtils.getPreviousSiblingStatement(statementNode1), null);
|
||||
});
|
||||
|
||||
it('should return next sibling statement node', () => {
|
||||
assert.deepEqual(NodeUtils.getPreviousSiblingStatementNode(statementNode2), statementNode1);
|
||||
assert.deepEqual(NodeUtils.getPreviousSiblingStatement(statementNode2), statementNode1);
|
||||
});
|
||||
|
||||
it('should return `null` if given statement node is last node in the scope', () => {
|
||||
assert.deepEqual(NodeUtils.getPreviousSiblingStatementNode(statementNode3), statementNode2);
|
||||
assert.deepEqual(NodeUtils.getPreviousSiblingStatement(statementNode3), statementNode2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -453,20 +453,20 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
|
||||
it('should return next sibling statement node', () => {
|
||||
assert.deepEqual(NodeUtils.getPreviousSiblingStatementNode(statementNode1), null);
|
||||
assert.deepEqual(NodeUtils.getPreviousSiblingStatement(statementNode1), null);
|
||||
});
|
||||
|
||||
it('should return next sibling statement node', () => {
|
||||
assert.deepEqual(NodeUtils.getPreviousSiblingStatementNode(statementNode2), statementNode1);
|
||||
assert.deepEqual(NodeUtils.getPreviousSiblingStatement(statementNode2), statementNode1);
|
||||
});
|
||||
|
||||
it('should return `null` if given statement node is last node in the scope', () => {
|
||||
assert.deepEqual(NodeUtils.getPreviousSiblingStatementNode(statementNode3), statementNode2);
|
||||
assert.deepEqual(NodeUtils.getPreviousSiblingStatement(statementNode3), statementNode2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getScopeOfNode (node: ESTree.Node): TNodeWithScope | null', () => {
|
||||
describe('getScopeOfNode', () => {
|
||||
let functionDeclarationBlockStatementNode: ESTree.BlockStatement,
|
||||
ifStatementBlockStatementNode1: ESTree.BlockStatement,
|
||||
ifStatementBlockStatementNode2: ESTree.BlockStatement,
|
||||
@@ -607,7 +607,7 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getUnaryExpressionArgumentNode (unaryExpressionNode: ESTree.UnaryExpression): ESTree.Node', () => {
|
||||
describe('getUnaryExpressionArgumentNode', () => {
|
||||
let expectedNode: ESTree.Literal,
|
||||
unaryExpressionArgumentNode: ESTree.Node;
|
||||
|
||||
@@ -635,7 +635,7 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('parentize <T extends ESTree.Node> (astTree: T): T', () => {
|
||||
describe('parentizeAst', () => {
|
||||
let ifStatementNode: ESTree.IfStatement,
|
||||
ifStatementBlockStatementNode: ESTree.BlockStatement,
|
||||
expressionStatementNode1: ESTree.ExpressionStatement,
|
||||
@@ -663,7 +663,7 @@ describe('NodeUtils', () => {
|
||||
ifStatementNode
|
||||
]);
|
||||
|
||||
programNode = NodeUtils.parentize(programNode);
|
||||
programNode = NodeUtils.parentizeAst(programNode);
|
||||
});
|
||||
|
||||
it('should parentize `program` node with `ProgramNode` as root node', () => {
|
||||
@@ -689,7 +689,7 @@ describe('NodeUtils', () => {
|
||||
|
||||
describe('Variant #2: parentize AST-tree', () => {
|
||||
beforeEach(() => {
|
||||
ifStatementNode = NodeUtils.parentize(ifStatementNode);
|
||||
ifStatementNode = NodeUtils.parentizeAst(ifStatementNode);
|
||||
});
|
||||
|
||||
it('should parentize `ifStatement` node', () => {
|
||||
@@ -710,7 +710,7 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('parentizeNode <T extends ESTree.Node = ESTree.Program> (node: T, parentNode: ESTree.Node): T', () => {
|
||||
describe('parentizeNode', () => {
|
||||
describe('Variant #1: node with parent node', () => {
|
||||
const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
|
||||
const breakStatement: ESTree.BreakStatement = NodeFactory.breakStatement(identifier);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { IObfuscationResult } from '../../../src/interfaces/IObfuscationResult';
|
||||
import { ObfuscationResult } from '../../../src/ObfuscationResult';
|
||||
|
||||
describe('ObfuscationResult', () => {
|
||||
describe('constructor (obfuscatedCode: string, sourceMap: string)', () => {
|
||||
describe('constructor', () => {
|
||||
let obfuscatedCode: string = 'obfuscatedCode',
|
||||
obfuscationResult: IObfuscationResult,
|
||||
sourceMap: string = 'sourceMap';
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ValidationError } from 'class-validator';
|
||||
import { ValidationErrorsFormatter } from '../../../src/options/ValidationErrorsFormatter';
|
||||
|
||||
describe('ValidationErrorsFormatter', () => {
|
||||
describe('format (validationErrors: ValidationError[]): string', () => {
|
||||
describe('format', () => {
|
||||
describe('Variant #1: one constraint group with one constraint', () => {
|
||||
const constraintGroupRegExp: RegExp = /`foo` *errors:/;
|
||||
const constraintRegExp: RegExp = /(?: *-)+ *constraint *text/;
|
||||
|
||||
@@ -43,7 +43,7 @@ function getCorrectedObfuscationResult (
|
||||
}
|
||||
|
||||
describe('SourceMapCorrector', () => {
|
||||
describe('correct (): IObfuscationResult', () => {
|
||||
describe('correct', () => {
|
||||
const expectedObfuscatedCode: string = 'var test = 1;';
|
||||
const sourceMap: string = 'test';
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ describe('ArrayStorage', () => {
|
||||
|
||||
let storage: IArrayStorage <any>;
|
||||
|
||||
describe('initialize (...args: any[]): void', () => {
|
||||
describe('initialize', () => {
|
||||
const expectedError: ErrorConstructor = Error;
|
||||
|
||||
let testFunc: () => void;
|
||||
@@ -58,7 +58,7 @@ describe('ArrayStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getStorage (): T[]', () => {
|
||||
describe('getStorage', () => {
|
||||
const expectedInstanceOf: ArrayConstructor = Array;
|
||||
|
||||
let arrayStorage: string[];
|
||||
@@ -74,7 +74,7 @@ describe('ArrayStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('get (key: number): T', () => {
|
||||
describe('get', () => {
|
||||
describe('Variant #1: value exist', () => {
|
||||
const expectedValue: string = storageValue;
|
||||
|
||||
@@ -109,7 +109,7 @@ describe('ArrayStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getLength (): number', () => {
|
||||
describe('getLength', () => {
|
||||
const expectedStorageLength: number = 1;
|
||||
|
||||
let storageLength: number;
|
||||
@@ -126,7 +126,7 @@ describe('ArrayStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getKeyOf (value: T): number | null', () => {
|
||||
describe('getKeyOf', () => {
|
||||
let key: string | number | null;
|
||||
|
||||
describe('Variant #1', () => {
|
||||
@@ -178,7 +178,7 @@ describe('ArrayStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('set (key: number, value: T): void', () => {
|
||||
describe('set', () => {
|
||||
let value: string;
|
||||
|
||||
before(() => {
|
||||
@@ -193,7 +193,7 @@ describe('ArrayStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('mergeWith (storage: this, mergeId: boolean = false): void', () => {
|
||||
describe('mergeWith', () => {
|
||||
const secondStorageKey: number = 1;
|
||||
const secondStorageValue: string = 'bar';
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('MapStorage', () => {
|
||||
|
||||
let storage: IMapStorage <string, any>;
|
||||
|
||||
describe('initialize (...args: any[]): void', () => {
|
||||
describe('initialize', () => {
|
||||
const expectedError: ErrorConstructor = Error;
|
||||
|
||||
let testFunc: () => void;
|
||||
@@ -57,7 +57,7 @@ describe('MapStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getStorage (): Map <K, V>', () => {
|
||||
describe('getStorage', () => {
|
||||
const expectedInstanceOf: MapConstructor = Map;
|
||||
|
||||
let mapStorage: Map <string, string>;
|
||||
@@ -73,7 +73,7 @@ describe('MapStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('get (key: K): V', () => {
|
||||
describe('get', () => {
|
||||
describe('Variant #1: value exist', () => {
|
||||
const expectedValue: string = storageValue;
|
||||
|
||||
@@ -108,7 +108,7 @@ describe('MapStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getLength (): number', () => {
|
||||
describe('getLength', () => {
|
||||
const expectedStorageLength: number = 1;
|
||||
|
||||
let storageLength: number;
|
||||
@@ -125,7 +125,7 @@ describe('MapStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getKeyOf (value: V): K | null', () => {
|
||||
describe('getKeyOf', () => {
|
||||
let key: string | number | null;
|
||||
|
||||
describe('Variant #1', () => {
|
||||
@@ -177,7 +177,7 @@ describe('MapStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('has (key: K): boolean', () => {
|
||||
describe('has', () => {
|
||||
describe('Variant #1: item is presenting in storage', () => {
|
||||
const expectedItemExistence: boolean = true;
|
||||
|
||||
@@ -212,7 +212,7 @@ describe('MapStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('set (key: K, value: V): void', () => {
|
||||
describe('set', () => {
|
||||
let value: string;
|
||||
|
||||
before(() => {
|
||||
@@ -227,7 +227,7 @@ describe('MapStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('mergeWith (storage: this, mergeId: boolean = false): void', () => {
|
||||
describe('mergeWith', () => {
|
||||
const secondStorageKey: string = 'baz';
|
||||
const secondStorageValue: string = 'quux';
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { IInversifyContainerFacade } from '../../../src/interfaces/container/IIn
|
||||
|
||||
import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
|
||||
|
||||
describe('Utils', () => {
|
||||
describe('ArrayUtils', () => {
|
||||
let arrayUtils: IArrayUtils;
|
||||
|
||||
before(() => {
|
||||
@@ -17,7 +17,7 @@ describe('Utils', () => {
|
||||
arrayUtils = inversifyContainerFacade.get<IArrayUtils>(ServiceIdentifiers.IArrayUtils);
|
||||
});
|
||||
|
||||
describe('arrayRange (length: number): number[]', () => {
|
||||
describe('createWithRange', () => {
|
||||
describe('range length more than 0', () => {
|
||||
const rangeLength: number = 5;
|
||||
const expectedArray: number[] = [0, 1, 2, 3, 4];
|
||||
@@ -25,7 +25,7 @@ describe('Utils', () => {
|
||||
let array: number[];
|
||||
|
||||
before(() => {
|
||||
array = arrayUtils.arrayRange(rangeLength);
|
||||
array = arrayUtils.createWithRange(rangeLength);
|
||||
});
|
||||
|
||||
it('should return array with range of numbers', () => {
|
||||
@@ -40,7 +40,7 @@ describe('Utils', () => {
|
||||
let array: number[];
|
||||
|
||||
before(() => {
|
||||
array = arrayUtils.arrayRange(rangeLength);
|
||||
array = arrayUtils.createWithRange(rangeLength);
|
||||
});
|
||||
|
||||
it('should return empty array', () => {
|
||||
@@ -55,7 +55,7 @@ describe('Utils', () => {
|
||||
let array: number[];
|
||||
|
||||
before(() => {
|
||||
array = arrayUtils.arrayRange(rangeLength);
|
||||
array = arrayUtils.createWithRange(rangeLength);
|
||||
});
|
||||
|
||||
it('should return empty array', () => {
|
||||
@@ -64,7 +64,7 @@ describe('Utils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('arrayRotate <T> (array: T[], times: number): T[]', () => {
|
||||
describe('rotate', () => {
|
||||
let array: number[],
|
||||
rotatedArray: number[];
|
||||
|
||||
@@ -77,7 +77,7 @@ describe('Utils', () => {
|
||||
const expectedArray: number[] = [5, 6, 1, 2, 3, 4];
|
||||
|
||||
beforeEach(() => {
|
||||
rotatedArray = arrayUtils.arrayRotate(array, rotateValue);
|
||||
rotatedArray = arrayUtils.rotate(array, rotateValue);
|
||||
});
|
||||
|
||||
it('should rotate (shift) array by a given value', () => {
|
||||
@@ -90,7 +90,7 @@ describe('Utils', () => {
|
||||
const expectedArray: number[] = [1, 2, 3, 4, 5, 6];
|
||||
|
||||
beforeEach(() => {
|
||||
rotatedArray = arrayUtils.arrayRotate(array, rotateValue);
|
||||
rotatedArray = arrayUtils.rotate(array, rotateValue);
|
||||
});
|
||||
|
||||
it('shouldn\'t rotate array', () => {
|
||||
@@ -106,7 +106,7 @@ describe('Utils', () => {
|
||||
let testFunc: () => void;
|
||||
|
||||
beforeEach(() => {
|
||||
testFunc = () => arrayUtils.arrayRotate(emptyArray, rotateValue);
|
||||
testFunc = () => arrayUtils.rotate(emptyArray, rotateValue);
|
||||
});
|
||||
|
||||
it('should throw exception if array is empty', () => {
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('CryptUtils', () => {
|
||||
cryptUtils = inversifyContainerFacade.get<ICryptUtils>(ServiceIdentifiers.ICryptUtils);
|
||||
});
|
||||
|
||||
describe('btoa (string: string): string', () => {
|
||||
describe('btoa', () => {
|
||||
const expectedString: string = 'c3RyaW5n';
|
||||
|
||||
let string: string;
|
||||
@@ -31,7 +31,7 @@ describe('CryptUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('hideString (str: string, length: number): [string, string]', () => {
|
||||
describe('hideString', () => {
|
||||
const originalString: string = 'example.com';
|
||||
const hiddenStringLength: number = 30;
|
||||
|
||||
@@ -71,7 +71,7 @@ describe('CryptUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('rc4 (string: string, key: string): string', () => {
|
||||
describe('rc4', () => {
|
||||
const string: string = 'test';
|
||||
const key: string = 'key';
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import { IEscapeSequenceEncoder } from '../../../src/interfaces/utils/IEscapeSeq
|
||||
|
||||
|
||||
describe('EscapeSequenceEncoder', () => {
|
||||
describe('encode (string: string, encodeAllSymbols: boolean = false): string', () => {
|
||||
describe('encode', () => {
|
||||
let escapeSequenceEncoder: IEscapeSequenceEncoder;
|
||||
|
||||
before(() => {
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { NumberUtils } from '../../../src/utils/NumberUtils';
|
||||
|
||||
describe('NumberUtils', () => {
|
||||
describe('toHex', () => {
|
||||
describe('Variant #1: number `0`', () => {
|
||||
const number: number = 0;
|
||||
const expectedHexString = '0';
|
||||
|
||||
let hexString: string;
|
||||
|
||||
before(() => {
|
||||
hexString = NumberUtils.toHex(number);
|
||||
});
|
||||
|
||||
it('should create a string with hexadecimal value from a given decimal number', () => {
|
||||
assert.equal(hexString, expectedHexString);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: number `10`', () => {
|
||||
const number: number = 10;
|
||||
const expectedHexString = 'a';
|
||||
|
||||
let hexString: string;
|
||||
|
||||
before(() => {
|
||||
hexString = NumberUtils.toHex(number);
|
||||
});
|
||||
|
||||
it('should create a string with hexadecimal value from a given decimal number', () => {
|
||||
assert.equal(hexString, expectedHexString);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #3: number `17`', () => {
|
||||
const number: number = 17;
|
||||
const expectedHexString = '11';
|
||||
|
||||
let hexString: string;
|
||||
|
||||
before(() => {
|
||||
hexString = NumberUtils.toHex(number);
|
||||
});
|
||||
|
||||
it('should create a string with hexadecimal value from a given decimal number', () => {
|
||||
assert.equal(hexString, expectedHexString);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #4: number `536870912`', () => {
|
||||
const number: number = 536870912;
|
||||
const expectedHexString = '20000000';
|
||||
|
||||
let hexString: string;
|
||||
|
||||
before(() => {
|
||||
hexString = NumberUtils.toHex(number);
|
||||
});
|
||||
|
||||
it('should create a string with hexadecimal value from a given decimal number', () => {
|
||||
assert.equal(hexString, expectedHexString);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isCeil', () => {
|
||||
describe('given number is a ceil', () => {
|
||||
const number: number = 4;
|
||||
const expectedResult: boolean = true;
|
||||
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
result = NumberUtils.isCeil(number);
|
||||
});
|
||||
|
||||
it('should return true', () => {
|
||||
assert.equal(result, expectedResult);
|
||||
});
|
||||
});
|
||||
|
||||
describe('given number is a float', () => {
|
||||
const number: number = 4.5;
|
||||
const expectedResult: boolean = false;
|
||||
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
result = NumberUtils.isCeil(number);
|
||||
});
|
||||
|
||||
it('should return false', () => {
|
||||
assert.equal(result, expectedResult);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,73 +1,9 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { JSFuck } from '../../../src/enums/JSFuck';
|
||||
|
||||
import { Utils } from '../../../src/utils/Utils';
|
||||
|
||||
describe('Utils', () => {
|
||||
describe('decToHex (dec: number): string', () => {
|
||||
describe('Variant #1: number `0`', () => {
|
||||
const number: number = 0;
|
||||
const expectedHexString = '0';
|
||||
|
||||
let hexString: string;
|
||||
|
||||
before(() => {
|
||||
hexString = Utils.decToHex(number);
|
||||
});
|
||||
|
||||
it('should create a string with hexadecimal value from a given decimal number', () => {
|
||||
assert.equal(hexString, expectedHexString);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: number `10`', () => {
|
||||
const number: number = 10;
|
||||
const expectedHexString = 'a';
|
||||
|
||||
let hexString: string;
|
||||
|
||||
before(() => {
|
||||
hexString = Utils.decToHex(number);
|
||||
});
|
||||
|
||||
it('should create a string with hexadecimal value from a given decimal number', () => {
|
||||
assert.equal(hexString, expectedHexString);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #3: number `17`', () => {
|
||||
const number: number = 17;
|
||||
const expectedHexString = '11';
|
||||
|
||||
let hexString: string;
|
||||
|
||||
before(() => {
|
||||
hexString = Utils.decToHex(number);
|
||||
});
|
||||
|
||||
it('should create a string with hexadecimal value from a given decimal number', () => {
|
||||
assert.equal(hexString, expectedHexString);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #4: number `536870912`', () => {
|
||||
const number: number = 536870912;
|
||||
const expectedHexString = '20000000';
|
||||
|
||||
let hexString: string;
|
||||
|
||||
before(() => {
|
||||
hexString = Utils.decToHex(number);
|
||||
});
|
||||
|
||||
it('should create a string with hexadecimal value from a given decimal number', () => {
|
||||
assert.equal(hexString, expectedHexString);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('extractDomainFromUrl (url: string): string', () => {
|
||||
describe('extractDomainFrom', () => {
|
||||
describe('Variant #1: simple url', () => {
|
||||
const url: string = 'http://google.ru';
|
||||
const expectedDomain: string = 'google.ru';
|
||||
@@ -75,7 +11,7 @@ describe('Utils', () => {
|
||||
let domain: string;
|
||||
|
||||
before(() => {
|
||||
domain = Utils.extractDomainFromUrl(url);
|
||||
domain = Utils.extractDomainFrom(url);
|
||||
});
|
||||
|
||||
it('should extract domain from the given URL', () => {
|
||||
@@ -90,7 +26,7 @@ describe('Utils', () => {
|
||||
let domain: string;
|
||||
|
||||
before(() => {
|
||||
domain = Utils.extractDomainFromUrl(url);
|
||||
domain = Utils.extractDomainFrom(url);
|
||||
});
|
||||
|
||||
it('should extract domain from the given URL', () => {
|
||||
@@ -105,7 +41,7 @@ describe('Utils', () => {
|
||||
let domain: string;
|
||||
|
||||
before(() => {
|
||||
domain = Utils.extractDomainFromUrl(url);
|
||||
domain = Utils.extractDomainFrom(url);
|
||||
});
|
||||
|
||||
it('should extract domain from the given URL', () => {
|
||||
@@ -120,7 +56,7 @@ describe('Utils', () => {
|
||||
let domain: string;
|
||||
|
||||
before(() => {
|
||||
domain = Utils.extractDomainFromUrl(url);
|
||||
domain = Utils.extractDomainFrom(url);
|
||||
});
|
||||
|
||||
it('should extract domain from the given URL', () => {
|
||||
@@ -135,7 +71,7 @@ describe('Utils', () => {
|
||||
let domain: string;
|
||||
|
||||
before(() => {
|
||||
domain = Utils.extractDomainFromUrl(url);
|
||||
domain = Utils.extractDomainFrom(url);
|
||||
});
|
||||
|
||||
it('should extract domain from the given URL', () => {
|
||||
@@ -143,99 +79,4 @@ describe('Utils', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isCeilNumber (number: number): boolean', () => {
|
||||
describe('given number is a ceil', () => {
|
||||
const number: number = 4;
|
||||
const expectedResult: boolean = true;
|
||||
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
result = Utils.isCeilNumber(number);
|
||||
});
|
||||
|
||||
it('should return true', () => {
|
||||
assert.equal(result, expectedResult);
|
||||
});
|
||||
});
|
||||
|
||||
describe('given number is a float', () => {
|
||||
const number: number = 4.5;
|
||||
const expectedResult: boolean = false;
|
||||
|
||||
let result: boolean;
|
||||
|
||||
before(() => {
|
||||
result = Utils.isCeilNumber(number);
|
||||
});
|
||||
|
||||
it('should return false', () => {
|
||||
assert.equal(result, expectedResult);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('stringRotate (string: string, times: number): string', () => {
|
||||
const string: string = 'abcdefg';
|
||||
|
||||
let rotatedString: string;
|
||||
|
||||
describe('value is not 0', () => {
|
||||
const rotateValue: number = 2;
|
||||
const expectedString: string = 'fgabcde';
|
||||
|
||||
before(() => {
|
||||
rotatedString = Utils.stringRotate(string, rotateValue);
|
||||
});
|
||||
|
||||
it('should rotate string by a given value', () => {
|
||||
assert.deepEqual(rotatedString, expectedString);
|
||||
});
|
||||
});
|
||||
|
||||
describe('value equals or less 0', () => {
|
||||
const rotateValue: number = 0;
|
||||
const expectedString: string = 'abcdefg';
|
||||
|
||||
before(() => {
|
||||
rotatedString = Utils.stringRotate(string, rotateValue);
|
||||
});
|
||||
|
||||
it('shouldn\'t rotate string', () => {
|
||||
assert.deepEqual(rotatedString, expectedString);
|
||||
});
|
||||
});
|
||||
|
||||
describe('empty array', () => {
|
||||
const emptyString: string = '';
|
||||
const rotateValue: number = 5;
|
||||
const expectedError: ReferenceErrorConstructor = ReferenceError;
|
||||
|
||||
let testFunc: () => void ;
|
||||
|
||||
before(() => {
|
||||
testFunc = () => Utils.stringRotate(emptyString, rotateValue);
|
||||
});
|
||||
|
||||
it('should throw exception if string is empty', () => {
|
||||
assert.throws(testFunc, expectedError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('stringToJSFuck (string: string): string', () => {
|
||||
const string: string = 'string';
|
||||
const expectedString: string = `${JSFuck.s} + ${JSFuck.t} + ${JSFuck.r} + ${JSFuck.i} + ${JSFuck.n} + ${JSFuck.g}`;
|
||||
|
||||
let actualString: string;
|
||||
|
||||
before(() => {
|
||||
actualString = Utils.stringToJSFuck(string);
|
||||
});
|
||||
|
||||
it('should create a JSFuck encoded string from a given string', () => {
|
||||
assert.equal(actualString, expectedString);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user