mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Add --config CLI option that accepts name of js / json file that contains all config instead of passing everything in CLI
This commit is contained in:
@@ -17,6 +17,10 @@ describe('JavaScriptObfuscatorCLI', function (): void {
|
||||
const outputDirName: string = 'test/tmp';
|
||||
const outputFileName: string = 'sample-obfuscated.js';
|
||||
const outputFilePath: string = `${outputDirName}/${outputFileName}`;
|
||||
const configDirName: string = 'test/fixtures';
|
||||
const configFileName: string = 'config.js';
|
||||
const configFilePath: string = `${configDirName}/${configFileName}`;
|
||||
|
||||
|
||||
describe('run (): void', () => {
|
||||
before(() => {
|
||||
@@ -377,6 +381,93 @@ describe('JavaScriptObfuscatorCLI', function (): void {
|
||||
});
|
||||
});
|
||||
|
||||
describe('`--config` option is set', () => {
|
||||
const outputSourceMapPath: string = `${outputFilePath}.map`;
|
||||
|
||||
let isFileExist: boolean,
|
||||
sourceMapObject: any;
|
||||
|
||||
before(() => {
|
||||
JavaScriptObfuscator.runCLI([
|
||||
'node',
|
||||
'javascript-obfuscator',
|
||||
fixtureFilePath,
|
||||
'--output',
|
||||
outputFilePath,
|
||||
'--config',
|
||||
configFilePath
|
||||
]);
|
||||
|
||||
try {
|
||||
const content: string = fs.readFileSync(outputSourceMapPath, {encoding: 'utf8'});
|
||||
|
||||
isFileExist = true;
|
||||
sourceMapObject = JSON.parse(content);
|
||||
} catch (e) {
|
||||
isFileExist = false;
|
||||
}
|
||||
});
|
||||
|
||||
it('should create file with source map in the same directory as output file', () => {
|
||||
assert.equal(isFileExist, true);
|
||||
});
|
||||
|
||||
it('source map from created file should contains property `version`', () => {
|
||||
assert.property(sourceMapObject, 'version');
|
||||
});
|
||||
|
||||
it('source map from created file should contains property `sources`', () => {
|
||||
assert.property(sourceMapObject, 'sources');
|
||||
});
|
||||
|
||||
it('source map from created file should contains property `names`', () => {
|
||||
assert.property(sourceMapObject, 'names');
|
||||
});
|
||||
|
||||
after(() => {
|
||||
fs.unlinkSync(outputFilePath);
|
||||
fs.unlinkSync(outputSourceMapPath);
|
||||
});
|
||||
});
|
||||
|
||||
describe('`--config` option is set but overridden by CLI option', () => {
|
||||
const outputSourceMapPath: string = `${outputFilePath}.map`;
|
||||
|
||||
let isFileExist: boolean,
|
||||
sourceMapObject: any;
|
||||
|
||||
before(() => {
|
||||
JavaScriptObfuscator.runCLI([
|
||||
'node',
|
||||
'javascript-obfuscator',
|
||||
fixtureFilePath,
|
||||
'--output',
|
||||
outputFilePath,
|
||||
'--config',
|
||||
configFilePath,
|
||||
'--sourceMap',
|
||||
'false',
|
||||
]);
|
||||
|
||||
try {
|
||||
const content: string = fs.readFileSync(outputSourceMapPath, {encoding: 'utf8'});
|
||||
|
||||
isFileExist = true;
|
||||
sourceMapObject = JSON.parse(content);
|
||||
} catch (e) {
|
||||
isFileExist = false;
|
||||
}
|
||||
});
|
||||
|
||||
it('should create file without source map in the same directory as output file', () => {
|
||||
assert.equal(isFileExist, false);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
fs.unlinkSync(outputFilePath);
|
||||
});
|
||||
});
|
||||
|
||||
after(() => {
|
||||
fs.rmdirSync(outputDirName);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user