mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Changed file log messages
This commit is contained in:
@@ -3,7 +3,6 @@ import * as mkdirp from 'mkdirp';
|
||||
import * as rimraf from 'rimraf';
|
||||
|
||||
import { assert } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
|
||||
import { IFileData } from '../../../../src/interfaces/cli/IFileData';
|
||||
|
||||
@@ -547,41 +546,6 @@ describe('SourceCodeReader', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #3: logging', () => {
|
||||
const tmpFileName: string = 'test.js';
|
||||
const inputPath: string = `${tmpDirectoryPath}/${tmpFileName}`;
|
||||
const expectedConsoleLogCallResult: boolean = true;
|
||||
const expectedLoggingMessage: string = `[javascript-obfuscator-cli] Obfuscating file: ${inputPath}...`;
|
||||
|
||||
let consoleLogSpy: sinon.SinonSpy<any, void>,
|
||||
consoleLogCallResult: boolean,
|
||||
loggingMessageResult: string;
|
||||
|
||||
before(() => {
|
||||
consoleLogSpy = sinon.spy(console, 'log');
|
||||
|
||||
fs.writeFileSync(inputPath, fileContent);
|
||||
new SourceCodeReader(inputPath, {}).readSourceCode();
|
||||
|
||||
consoleLogCallResult = consoleLogSpy.called;
|
||||
loggingMessageResult = consoleLogSpy.getCall(0).args[0];
|
||||
});
|
||||
|
||||
it('should call `console.log`', () => {
|
||||
assert.equal(consoleLogCallResult, expectedConsoleLogCallResult);
|
||||
});
|
||||
|
||||
it('should log file name to the console', () => {
|
||||
assert.include(loggingMessageResult, expectedLoggingMessage);
|
||||
});
|
||||
|
||||
|
||||
after(() => {
|
||||
consoleLogSpy.restore();
|
||||
fs.unlinkSync(inputPath);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
after(() => {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { IASTParserFacadeInputData } from '../../../src/interfaces/IASTParserFacadeInputData';
|
||||
|
||||
import { ecmaVersion } from '../../../src/constants/EcmaVersion';
|
||||
|
||||
import { ASTParserFacade } from '../../../src/ASTParserFacade';
|
||||
@@ -20,13 +18,11 @@ describe('ASTParserFacade', () => {
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
const inputData: IASTParserFacadeInputData = {sourceCode};
|
||||
|
||||
testFunc = () => ASTParserFacade.parse(inputData, { ecmaVersion });
|
||||
testFunc = () => ASTParserFacade.parse(sourceCode, { ecmaVersion });
|
||||
});
|
||||
|
||||
it('should output code preview when AST parser throws a parse error', () => {
|
||||
assert.throws(testFunc, /ERROR in line 3: Unexpected token \(3:28\)\n.*\.\.\.var baz = 3;,\.\.\./);
|
||||
assert.throws(testFunc, /ERROR at line 3: Unexpected token \(3:28\)\n.*\.\.\.var baz = 3;,\.\.\./);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -51,13 +47,11 @@ describe('ASTParserFacade', () => {
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
const inputData: IASTParserFacadeInputData = {sourceCode};
|
||||
|
||||
testFunc = () => ASTParserFacade.parse(inputData, { ecmaVersion });
|
||||
testFunc = () => ASTParserFacade.parse(sourceCode, { ecmaVersion });
|
||||
});
|
||||
|
||||
it('should output code preview when AST parser throws a parse error', () => {
|
||||
assert.throws(testFunc, /ERROR in line 13: Unexpected token \(13:28\)\n.*\.\.\.var baz = 3;,\.\.\./);
|
||||
assert.throws(testFunc, /ERROR at line 13: Unexpected token \(13:28\)\n.*\.\.\.var baz = 3;,\.\.\./);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -76,37 +70,11 @@ describe('ASTParserFacade', () => {
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
const inputData: IASTParserFacadeInputData = {sourceCode};
|
||||
|
||||
testFunc = () => ASTParserFacade.parse(inputData, { ecmaVersion });
|
||||
testFunc = () => ASTParserFacade.parse(sourceCode, { ecmaVersion });
|
||||
});
|
||||
|
||||
it('should output code preview when AST parser throws a parse error', () => {
|
||||
assert.throws(testFunc, /ERROR in line 4: Unexpected token \(4:28\)\n.*\.\.\.functin baz \(\) {\.\.\./);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #4: input file path is set', () => {
|
||||
const sourceCode: string = `` +
|
||||
`var foo = 1;
|
||||
var bar = 2;
|
||||
var baz = 3;,
|
||||
var bark = 4;
|
||||
var hawk = 5;`;
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
const inputData: IASTParserFacadeInputData = {
|
||||
sourceCode,
|
||||
inputFilePath: '/src/foo.js'
|
||||
};
|
||||
|
||||
testFunc = () => ASTParserFacade.parse(inputData, { ecmaVersion });
|
||||
});
|
||||
|
||||
it('should output code preview when AST parser throws a parse error', () => {
|
||||
assert.throws(testFunc, /ERROR in \/src\/foo\.js, line 3: Unexpected token \(3:32\)\n.*\.\.\.var baz = 3;,\.\.\./);
|
||||
assert.throws(testFunc, /ERROR at line 4: Unexpected token \(4:28\)\n.*\.\.\.functin baz \(\) {\.\.\./);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user