mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
CLI tests refactoring
This commit is contained in:
Vendored
-1
@@ -1084,7 +1084,6 @@ var JavaScriptObfuscatorCLI = function () {
|
||||
this.configureCommands();
|
||||
if (!this.arguments.length || this.arguments.indexOf('--help') >= 0) {
|
||||
this.commands.outputHelp();
|
||||
return;
|
||||
}
|
||||
this.inputPath = this.getInputPath();
|
||||
this.getData();
|
||||
|
||||
@@ -94,8 +94,6 @@ export class JavaScriptObfuscatorCLI {
|
||||
|
||||
if (!this.arguments.length || this.arguments.indexOf('--help') >= 0) {
|
||||
this.commands.outputHelp();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.inputPath = this.getInputPath();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as fs from 'fs';
|
||||
import * as mkdirp from 'mkdirp';
|
||||
|
||||
import { JavaScriptObfuscator } from "../src/JavaScriptObfuscator";
|
||||
|
||||
@@ -6,14 +7,17 @@ const assert: Chai.AssertStatic = require('chai').assert;
|
||||
|
||||
describe('JavaScriptObfuscatorCLI', () => {
|
||||
let fixturesDirName: string = 'test/fixtures',
|
||||
tmpDirName: string = 'test/tmp',
|
||||
fixtureFileName: string = 'sample.js',
|
||||
fixtureFilePath: string = `${fixturesDirName}/${fixtureFileName}`,
|
||||
outputDirName: string = 'test/tmp',
|
||||
outputFileName: string = 'sample-obfuscated.js',
|
||||
outputFixturesFilePath: string = `${fixturesDirName}/${outputFileName}`,
|
||||
outputFilePath: string = `${tmpDirName}/${outputFileName}`;
|
||||
outputFilePath: string = `${outputDirName}/${outputFileName}`;
|
||||
|
||||
describe('run (): void', () => {
|
||||
before(() => {
|
||||
mkdirp.sync(outputDirName);
|
||||
});
|
||||
|
||||
describe('--output option is set', () => {
|
||||
it('should creates file with obfuscated JS code in --output directory', () => {
|
||||
JavaScriptObfuscator.runCLI([
|
||||
@@ -21,7 +25,11 @@ describe('JavaScriptObfuscatorCLI', () => {
|
||||
'javascript-obfuscator',
|
||||
fixtureFilePath,
|
||||
'--output',
|
||||
outputFilePath
|
||||
outputFilePath,
|
||||
'--compact',
|
||||
'true',
|
||||
'--selfDefending',
|
||||
'0'
|
||||
]);
|
||||
|
||||
assert.equal(fs.existsSync(outputFilePath), true);
|
||||
@@ -29,12 +37,13 @@ describe('JavaScriptObfuscatorCLI', () => {
|
||||
|
||||
afterEach(() => {
|
||||
fs.unlinkSync(outputFilePath);
|
||||
fs.rmdirSync(tmpDirName);
|
||||
});
|
||||
});
|
||||
|
||||
describe('—output option is not set', () => {
|
||||
it(`should creates file called \`${outputFileName}\` with obfuscated JS code in \`${fixturesDirName}\` directory`, () => {
|
||||
let outputFixturesFilePath: string = `${fixturesDirName}/${outputFileName}`;
|
||||
|
||||
JavaScriptObfuscator.runCLI([
|
||||
'node',
|
||||
'javascript-obfuscator',
|
||||
@@ -42,11 +51,36 @@ describe('JavaScriptObfuscatorCLI', () => {
|
||||
]);
|
||||
|
||||
assert.equal(fs.existsSync(outputFixturesFilePath), true);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.unlinkSync(outputFixturesFilePath);
|
||||
});
|
||||
|
||||
it(`should throw an error if input path is not a valid file path`, () => {
|
||||
assert.throws(() => JavaScriptObfuscator.runCLI([
|
||||
'node',
|
||||
'javascript-obfuscator',
|
||||
'wrong/file/path'
|
||||
]), ReferenceError);
|
||||
});
|
||||
|
||||
it(`should throw an error if input file extension is not a .js extension`, () => {
|
||||
let outputWrongExtensionFileName: string = 'sample-obfuscated.ts',
|
||||
outputWrongExtensionFilePath: string = `${outputDirName}/${outputWrongExtensionFileName}`;
|
||||
|
||||
fs.writeFileSync(outputWrongExtensionFilePath, 'data');
|
||||
|
||||
assert.throws(() => JavaScriptObfuscator.runCLI([
|
||||
'node',
|
||||
'javascript-obfuscator',
|
||||
outputWrongExtensionFilePath
|
||||
]), ReferenceError);
|
||||
|
||||
fs.unlinkSync(outputWrongExtensionFilePath);
|
||||
});
|
||||
});
|
||||
|
||||
after(() => {
|
||||
fs.rmdirSync(outputDirName);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user