mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Refactoring of JavaSriptObfuscatorCLI class
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user