Refactoring of JavaSriptObfuscatorCLI class

This commit is contained in:
sanex3339
2017-08-05 14:00:14 +03:00
parent 848a31d92b
commit bdb5aaebd8
13 changed files with 157 additions and 74 deletions
+1
View File
@@ -5,6 +5,7 @@ require('source-map-support').install();
/**
* Unit tests
*/
import './unit-tests/cli/sanitizers/ArraySanitizer.spec';
import './unit-tests/cli/sanitizers/BooleanSanitizer.spec';
import './unit-tests/cli/sanitizers/SourceMapModeSanitizer.spec';
import './unit-tests/cli/sanitizers/StringArrayEncodingSanitizer.spec';
@@ -0,0 +1,38 @@
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'];
let value: string[];
before(() => {
value = ArraySanitizer(inputValue);
});
it('should sanitize value', () => {
assert.deepEqual(value, expectedValue);
});
});
describe('variant #2: input value `foo, bar`', () => {
const inputValue: string = 'foo, bar';
const expectedValue: string[] = ['foo', 'bar'];
let value: string[];
before(() => {
value = ArraySanitizer(inputValue);
});
it('should sanitize value', () => {
assert.deepEqual(value, expectedValue);
});
});
});
});
+7 -7
View File
@@ -87,20 +87,20 @@ describe('CLIUtils', () => {
});
});
describe('validateInputPath (inputPath: string): void', () => {
describe('readSourceCode (inputPath: string): void', () => {
describe('`inputPath` is a valid path', () => {
const tmpFileName: string = 'test.js';
const inputPath: string = `${tmpDir}/${tmpFileName}`;
let testFunc: () => void;
let result: string;
before(() => {
fs.writeFileSync(inputPath, fileContent);
testFunc = () => CLIUtils.validateInputPath(inputPath);
result = CLIUtils.readSourceCode(inputPath);
});
it('shouldn\'t throw an error if `inputPath` is a valid path', () => {
assert.doesNotThrow(testFunc, ReferenceError);
it('should return content of file', () => {
assert.equal(result, fileContent);
});
after(() => {
@@ -115,7 +115,7 @@ describe('CLIUtils', () => {
let testFunc: () => void;
before(() => {
testFunc = () => CLIUtils.validateInputPath(inputPath);
testFunc = () => CLIUtils.readSourceCode(inputPath);
});
it('should throw an error if `inputPath` is not a valid path', () => {
@@ -131,7 +131,7 @@ describe('CLIUtils', () => {
before(() => {
fs.writeFileSync(inputPath, fileContent);
testFunc = () => CLIUtils.validateInputPath(inputPath);
testFunc = () => CLIUtils.readSourceCode(inputPath);
});
it('should throw an error if `inputPath` is a file name has invalid extension', () => {