mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
tests, refactoring, typings update
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import * as fs from 'fs';
|
||||
import * as mkdirp from 'mkdirp';
|
||||
import * as sinon from 'sinon';
|
||||
|
||||
import { StdoutWriteMock } from "../test/mocks/StdoutWriteMock";
|
||||
|
||||
import { JavaScriptObfuscator } from "../src/JavaScriptObfuscator";
|
||||
|
||||
const assert: Chai.AssertStatic = require('chai').assert;
|
||||
|
||||
describe('JavaScriptObfuscatorCLI', () => {
|
||||
describe('JavaScriptObfuscatorCLI', function (): void {
|
||||
let fixturesDirName: string = 'test/fixtures',
|
||||
fixtureFileName: string = 'sample.js',
|
||||
fixtureFilePath: string = `${fixturesDirName}/${fixtureFileName}`,
|
||||
@@ -13,6 +16,8 @@ describe('JavaScriptObfuscatorCLI', () => {
|
||||
outputFileName: string = 'sample-obfuscated.js',
|
||||
outputFilePath: string = `${outputDirName}/${outputFileName}`;
|
||||
|
||||
this.timeout(5000);
|
||||
|
||||
describe('run (): void', () => {
|
||||
before(() => {
|
||||
mkdirp.sync(outputDirName);
|
||||
@@ -40,7 +45,7 @@ describe('JavaScriptObfuscatorCLI', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('—output option is not set', () => {
|
||||
describe('--output option is not set', () => {
|
||||
it(`should creates file called \`${outputFileName}\` with obfuscated JS code in \`${fixturesDirName}\` directory`, () => {
|
||||
let outputFixturesFilePath: string = `${fixturesDirName}/${outputFileName}`;
|
||||
|
||||
@@ -79,6 +84,48 @@ describe('JavaScriptObfuscatorCLI', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('help output', () => {
|
||||
let callback: Sinon.SinonSpy,
|
||||
stdoutWriteMock: StdoutWriteMock;
|
||||
|
||||
beforeEach(() => {
|
||||
callback = sinon.spy(console, 'log');
|
||||
stdoutWriteMock = new StdoutWriteMock(process.stdout.write);
|
||||
});
|
||||
|
||||
it('should print `console.log` help if `--help` option is set', () => {
|
||||
stdoutWriteMock.mute();
|
||||
|
||||
JavaScriptObfuscator.runCLI([
|
||||
'node',
|
||||
'javascript-obfuscator',
|
||||
fixtureFilePath,
|
||||
'--help'
|
||||
]);
|
||||
|
||||
stdoutWriteMock.restore();
|
||||
|
||||
assert.equal(callback.called, true);
|
||||
});
|
||||
|
||||
it('should print `console.log` help if no options is passed', () => {
|
||||
stdoutWriteMock.mute();
|
||||
|
||||
JavaScriptObfuscator.runCLI([
|
||||
'node',
|
||||
'javascript-obfuscator'
|
||||
]);
|
||||
|
||||
stdoutWriteMock.restore();
|
||||
|
||||
assert.equal(callback.called, true);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
callback.restore();
|
||||
});
|
||||
});
|
||||
|
||||
after(() => {
|
||||
fs.rmdirSync(outputDirName);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user