mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Usage of path.join in tests
This commit is contained in:
@@ -15,15 +15,15 @@ describe('JavaScriptObfuscatorCLI', function (): void {
|
||||
|
||||
const expectedError: RegExp = /Given input path must be a valid/;
|
||||
|
||||
const fixturesDirName: string = 'test/fixtures';
|
||||
const fixturesDirName: string = path.join('test', 'fixtures');
|
||||
const fixtureFileName: string = 'sample.js';
|
||||
const fixtureFilePath: string = `${fixturesDirName}/${fixtureFileName}`;
|
||||
const outputDirName: string = 'test/tmp';
|
||||
const fixtureFilePath: string = path.join(fixturesDirName, fixtureFileName);
|
||||
const outputDirName: string = path.join('test', 'tmp');
|
||||
const outputFileName: string = 'sample-obfuscated.js';
|
||||
const outputFilePath: string = `${outputDirName}/${outputFileName}`;
|
||||
const configDirName: string = 'test/fixtures';
|
||||
const outputFilePath: string = path.join(outputDirName, outputFileName);
|
||||
const configDirName: string = path.join('test', 'fixtures');
|
||||
const configFileName: string = 'config.js';
|
||||
const configFilePath: string = `${configDirName}/${configFileName}`;
|
||||
const configFilePath: string = path.join(configDirName, configFileName);
|
||||
|
||||
|
||||
describe('run', () => {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { assert } from 'chai';
|
||||
import * as fs from 'fs';
|
||||
import * as mkdirp from 'mkdirp';
|
||||
import * as path from 'path';
|
||||
import * as rimraf from 'rimraf';
|
||||
import * as fs from "fs";
|
||||
|
||||
import { ObfuscatedCodeWriter } from '../../../../src/cli/utils/ObfuscatedCodeWriter';
|
||||
|
||||
@@ -10,18 +11,18 @@ describe('ObfuscatedCodeWriter', () => {
|
||||
|
||||
describe('getOutputCodePath', () => {
|
||||
before(() => {
|
||||
mkdirp.sync(`${tmpDirectoryPath}/input/`);
|
||||
mkdirp.sync(path.join(tmpDirectoryPath, 'input'));
|
||||
fs.writeFileSync(
|
||||
`${tmpDirectoryPath}/input/test-input.js`,
|
||||
path.join(tmpDirectoryPath, 'input', 'test-input.js'),
|
||||
'var foo = 1;'
|
||||
);
|
||||
});
|
||||
|
||||
describe('Variant #1: raw input path is a file path, raw output path is a file path', () => {
|
||||
const inputPath: string = `${tmpDirectoryPath}/input/test-input.js`;
|
||||
const rawInputPath: string = `${tmpDirectoryPath}/input/test-input.js`;
|
||||
const rawOutputPath: string = `${tmpDirectoryPath}/output/test-output.js`;
|
||||
const expectedOutputCodePath: string = `${tmpDirectoryPath}/output/test-output.js`;
|
||||
const inputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
|
||||
const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
|
||||
const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
|
||||
const expectedOutputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
|
||||
|
||||
let outputCodePath: string;
|
||||
|
||||
@@ -41,10 +42,10 @@ describe('ObfuscatedCodeWriter', () => {
|
||||
});
|
||||
|
||||
describe('Variant #2: raw input path is a file path, raw output path is a directory path', () => {
|
||||
const inputPath: string = `${tmpDirectoryPath}/input/test-input.js`;
|
||||
const rawInputPath: string = `${tmpDirectoryPath}/input/test-input.js`;
|
||||
const rawOutputPath: string = `${tmpDirectoryPath}/output`;
|
||||
const expectedOutputCodePath: string = `${tmpDirectoryPath}/output/test-input.js`;
|
||||
const inputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
|
||||
const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
|
||||
const rawOutputPath: string = path.join(tmpDirectoryPath, 'output');
|
||||
const expectedOutputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-input.js');
|
||||
|
||||
let outputCodePath: string;
|
||||
|
||||
@@ -64,9 +65,9 @@ describe('ObfuscatedCodeWriter', () => {
|
||||
});
|
||||
|
||||
describe('Variant #3: raw input path is a directory path, raw output path is a file path', () => {
|
||||
const inputPath: string = `${tmpDirectoryPath}/input/test-input.js`;
|
||||
const rawInputPath: string = `${tmpDirectoryPath}/input`;
|
||||
const rawOutputPath: string = `${tmpDirectoryPath}/output/test-output.js`;
|
||||
const inputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
|
||||
const rawInputPath: string = path.join(tmpDirectoryPath, 'input');
|
||||
const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
|
||||
|
||||
let testFunc: () => string;
|
||||
|
||||
@@ -87,10 +88,16 @@ describe('ObfuscatedCodeWriter', () => {
|
||||
|
||||
describe('Variant #4: raw input path is a directory path, raw output path is a directory path', () => {
|
||||
describe('Variant #1: base directory name', () => {
|
||||
const inputPath: string = `${tmpDirectoryPath}/input/test-input.js`;
|
||||
const rawInputPath: string = `${tmpDirectoryPath}/input`;
|
||||
const rawOutputPath: string = `${tmpDirectoryPath}/output`;
|
||||
const expectedOutputCodePath: string = `${tmpDirectoryPath}/output/${tmpDirectoryPath}/input/test-input.js`;
|
||||
const inputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
|
||||
const rawInputPath: string = path.join(tmpDirectoryPath, 'input');
|
||||
const rawOutputPath: string = path.join(tmpDirectoryPath, 'output');
|
||||
const expectedOutputCodePath: string = path.join(
|
||||
tmpDirectoryPath,
|
||||
'output',
|
||||
tmpDirectoryPath,
|
||||
'input',
|
||||
'test-input.js'
|
||||
);
|
||||
|
||||
let outputCodePath: string;
|
||||
|
||||
@@ -110,10 +117,17 @@ describe('ObfuscatedCodeWriter', () => {
|
||||
});
|
||||
|
||||
describe('Variant #2: directory name with dot', () => {
|
||||
const inputPath: string = `${tmpDirectoryPath}/input/test-input.js`;
|
||||
const rawInputPath: string = `${tmpDirectoryPath}/input`;
|
||||
const rawOutputPath: string = `${tmpDirectoryPath}/output/foo.bar`;
|
||||
const expectedOutputCodePath: string = `${tmpDirectoryPath}/output/foo.bar/${tmpDirectoryPath}/input/test-input.js`;
|
||||
const inputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
|
||||
const rawInputPath: string = path.join(tmpDirectoryPath, 'input');
|
||||
const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'foo.bar');
|
||||
const expectedOutputCodePath: string = path.join(
|
||||
tmpDirectoryPath,
|
||||
'output',
|
||||
'foo.bar',
|
||||
tmpDirectoryPath,
|
||||
'input',
|
||||
'test-input.js'
|
||||
);
|
||||
|
||||
let outputCodePath: string;
|
||||
|
||||
@@ -139,10 +153,10 @@ describe('ObfuscatedCodeWriter', () => {
|
||||
});
|
||||
|
||||
describe('getOutputSourceMapPath', () => {
|
||||
const rawInputPath: string = `${tmpDirectoryPath}/input/test-input.js`;
|
||||
const rawOutputPath: string = `${tmpDirectoryPath}/output/test-output.js`;
|
||||
const outputCodePath: string = `${tmpDirectoryPath}/output/test-output.js`;
|
||||
const expectedOutputSourceMapPath: string = `${tmpDirectoryPath}/output/test-output.js.map`;
|
||||
const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
|
||||
const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
|
||||
const outputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
|
||||
const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js.map');
|
||||
|
||||
let outputSourceMapPath: string;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as fs from 'fs';
|
||||
import * as mkdirp from 'mkdirp';
|
||||
import * as path from 'path';
|
||||
import * as rimraf from 'rimraf';
|
||||
|
||||
import { assert } from 'chai';
|
||||
@@ -11,7 +12,7 @@ import { SourceCodeReader } from '../../../../src/cli/utils/SourceCodeReader';
|
||||
describe('SourceCodeReader', () => {
|
||||
const expectedError: RegExp = /Given input path must be a valid/;
|
||||
const fileContent: string = 'test';
|
||||
const tmpDirectoryPath: string = 'test/tmp';
|
||||
const tmpDirectoryPath: string = path.join('test', 'tmp');
|
||||
|
||||
before(() => {
|
||||
mkdirp.sync(tmpDirectoryPath);
|
||||
@@ -21,7 +22,7 @@ describe('SourceCodeReader', () => {
|
||||
describe('Variant #1: input path is a file path', () => {
|
||||
describe('Variant #1: `inputPath` is a valid path', () => {
|
||||
const tmpFileName: string = 'test.js';
|
||||
const inputPath: string = `${tmpDirectoryPath}/${tmpFileName}`;
|
||||
const inputPath: string = path.join(tmpDirectoryPath, tmpFileName);
|
||||
const expectedFilesData: IFileData[] = [{
|
||||
content: fileContent,
|
||||
filePath: inputPath
|
||||
@@ -45,7 +46,7 @@ describe('SourceCodeReader', () => {
|
||||
|
||||
describe('Variant #2: `inputPath` is not a valid path', () => {
|
||||
const tmpFileName: string = 'test.js';
|
||||
const inputPath: string = `${tmpDirectoryPath}/${tmpFileName}`;
|
||||
const inputPath: string = path.join(tmpDirectoryPath, tmpFileName);
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
@@ -60,7 +61,7 @@ describe('SourceCodeReader', () => {
|
||||
|
||||
describe('Variant #3: `inputPath` has invalid extension', () => {
|
||||
const tmpFileName: string = 'test.ts';
|
||||
const inputPath: string = `${tmpDirectoryPath}/${tmpFileName}`;
|
||||
const inputPath: string = path.join(tmpDirectoryPath, tmpFileName);
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
@@ -81,7 +82,7 @@ describe('SourceCodeReader', () => {
|
||||
describe('Variant #4: `exclude` option', () => {
|
||||
describe('Variant #1: `inputPath` isn\'t excluded path', () => {
|
||||
const tmpFileName: string = 'test.js';
|
||||
const inputPath: string = `${tmpDirectoryPath}/${tmpFileName}`;
|
||||
const inputPath: string = path.join(tmpDirectoryPath, tmpFileName);
|
||||
const expectedFilesData: IFileData[] = [{
|
||||
content: fileContent,
|
||||
filePath: inputPath
|
||||
@@ -94,7 +95,7 @@ describe('SourceCodeReader', () => {
|
||||
filesData = new SourceCodeReader(
|
||||
inputPath,
|
||||
{
|
||||
exclude: ['**/foo.js']
|
||||
exclude: [path.join('**', 'foo.js')]
|
||||
}
|
||||
).readSourceCode();
|
||||
});
|
||||
@@ -111,7 +112,7 @@ describe('SourceCodeReader', () => {
|
||||
describe('Variant #2: `inputPath` is excluded path', () => {
|
||||
describe('Variant #1: exclude by `glob` pattern', () => {
|
||||
const tmpFileName: string = 'test.js';
|
||||
const inputPath: string = `${tmpDirectoryPath}/${tmpFileName}`;
|
||||
const inputPath: string = path.join(tmpDirectoryPath, tmpFileName);
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
@@ -120,7 +121,7 @@ describe('SourceCodeReader', () => {
|
||||
testFunc = () => new SourceCodeReader(
|
||||
inputPath,
|
||||
{
|
||||
exclude: [`**/${tmpFileName}`]
|
||||
exclude: [path.join('**', tmpFileName)]
|
||||
}
|
||||
).readSourceCode();
|
||||
});
|
||||
@@ -136,7 +137,7 @@ describe('SourceCodeReader', () => {
|
||||
|
||||
describe('Variant #2: exclude by file name', () => {
|
||||
const tmpFileName: string = 'test.js';
|
||||
const inputPath: string = `${tmpDirectoryPath}/${tmpFileName}`;
|
||||
const inputPath: string = path.join(tmpDirectoryPath, tmpFileName);
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
@@ -161,7 +162,7 @@ describe('SourceCodeReader', () => {
|
||||
|
||||
describe('Variant #3: exclude by file path', () => {
|
||||
const tmpFileName: string = 'test.js';
|
||||
const inputPath: string = `${tmpDirectoryPath}/${tmpFileName}`;
|
||||
const inputPath: string = path.join(tmpDirectoryPath, tmpFileName);
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
@@ -193,10 +194,10 @@ describe('SourceCodeReader', () => {
|
||||
const tmpFileName2: string = 'bar.js';
|
||||
const tmpFileName3: string = 'baz.png';
|
||||
const tmpFileName4: string = 'bark-obfuscated.js';
|
||||
const filePath1: string = `${tmpDirectoryPath}/${tmpFileName1}`;
|
||||
const filePath2: string = `${tmpDirectoryPath}/${tmpFileName2}`;
|
||||
const filePath3: string = `${tmpDirectoryPath}/${tmpFileName3}`;
|
||||
const filePath4: string = `${tmpDirectoryPath}/${tmpFileName4}`;
|
||||
const filePath1: string = path.join(tmpDirectoryPath, tmpFileName1);
|
||||
const filePath2: string = path.join(tmpDirectoryPath, tmpFileName2);
|
||||
const filePath3: string = path.join(tmpDirectoryPath, tmpFileName3);
|
||||
const filePath4: string = path.join(tmpDirectoryPath, tmpFileName4);
|
||||
|
||||
const expectedResult: IFileData[] = [
|
||||
{
|
||||
@@ -248,16 +249,16 @@ describe('SourceCodeReader', () => {
|
||||
describe('Variant #3: `inputPath` is a directory with sub-directories', () => {
|
||||
const parentDirectoryName1: string = 'parent1';
|
||||
const parentDirectoryName2: string = 'parent';
|
||||
const parentDirectoryPath1: string = `${tmpDirectoryPath}/${parentDirectoryName1}`;
|
||||
const parentDirectoryPath2: string = `${tmpDirectoryPath}/${parentDirectoryName2}`;
|
||||
const parentDirectoryPath1: string = path.join(tmpDirectoryPath, parentDirectoryName1);
|
||||
const parentDirectoryPath2: string = path.join(tmpDirectoryPath, parentDirectoryName2);
|
||||
const tmpFileName1: string = 'foo.js';
|
||||
const tmpFileName2: string = 'bar.js';
|
||||
const tmpFileName3: string = 'baz.js';
|
||||
const tmpFileName4: string = 'bark.js';
|
||||
const filePath1: string = `${tmpDirectoryPath}/${tmpFileName1}`;
|
||||
const filePath2: string = `${tmpDirectoryPath}/${tmpFileName2}`;
|
||||
const filePath3: string = `${parentDirectoryPath1}/${tmpFileName3}`;
|
||||
const filePath4: string = `${parentDirectoryPath2}/${tmpFileName4}`;
|
||||
const filePath1: string = path.join(tmpDirectoryPath, tmpFileName1);
|
||||
const filePath2: string = path.join(tmpDirectoryPath, tmpFileName2);
|
||||
const filePath3: string = path.join(parentDirectoryPath1, tmpFileName3);
|
||||
const filePath4: string = path.join(parentDirectoryPath2, tmpFileName4);
|
||||
|
||||
const expectedResult: IFileData[] = [
|
||||
{
|
||||
@@ -310,10 +311,10 @@ describe('SourceCodeReader', () => {
|
||||
const tmpFileName2: string = 'bar.js';
|
||||
const tmpFileName3: string = 'baz.png';
|
||||
const tmpFileName4: string = 'bark-obfuscated.js';
|
||||
const filePath1: string = `${tmpDirectoryPath}/${tmpFileName1}`;
|
||||
const filePath2: string = `${tmpDirectoryPath}/${tmpFileName2}`;
|
||||
const filePath3: string = `${tmpDirectoryPath}/${tmpFileName3}`;
|
||||
const filePath4: string = `${tmpDirectoryPath}/${tmpFileName4}`;
|
||||
const filePath1: string = path.join(tmpDirectoryPath, tmpFileName1);
|
||||
const filePath2: string = path.join(tmpDirectoryPath, tmpFileName2);
|
||||
const filePath3: string = path.join(tmpDirectoryPath, tmpFileName3);
|
||||
const filePath4: string = path.join(tmpDirectoryPath, tmpFileName4);
|
||||
|
||||
const expectedResult: IFileData[] = [
|
||||
{
|
||||
@@ -359,10 +360,10 @@ describe('SourceCodeReader', () => {
|
||||
const tmpFileName2: string = 'bar.js';
|
||||
const tmpFileName3: string = 'baz.js';
|
||||
const tmpFileName4: string = 'bark.js';
|
||||
const filePath1: string = `${tmpDirectoryPath}/${tmpFileName1}`;
|
||||
const filePath2: string = `${tmpDirectoryPath}/${tmpFileName2}`;
|
||||
const filePath3: string = `${tmpDirectoryPath}/${tmpFileName3}`;
|
||||
const filePath4: string = `${tmpDirectoryPath}/${tmpFileName4}`;
|
||||
const filePath1: string = path.join(tmpDirectoryPath, tmpFileName1);
|
||||
const filePath2: string = path.join(tmpDirectoryPath, tmpFileName2);
|
||||
const filePath3: string = path.join(tmpDirectoryPath, tmpFileName3);
|
||||
const filePath4: string = path.join(tmpDirectoryPath, tmpFileName4);
|
||||
|
||||
const expectedResult: IFileData[] = [
|
||||
{
|
||||
@@ -410,10 +411,10 @@ describe('SourceCodeReader', () => {
|
||||
const tmpFileName2: string = 'bar.js';
|
||||
const tmpFileName3: string = 'baz.js';
|
||||
const tmpFileName4: string = 'bark.js';
|
||||
const filePath1: string = `${tmpDirectoryPath}/${tmpFileName1}`;
|
||||
const filePath2: string = `${tmpDirectoryPath}/${tmpFileName2}`;
|
||||
const filePath3: string = `${tmpDirectoryPath}/${tmpFileName3}`;
|
||||
const filePath4: string = `${tmpDirectoryPath}/${tmpFileName4}`;
|
||||
const filePath1: string = path.join(tmpDirectoryPath, tmpFileName1);
|
||||
const filePath2: string = path.join(tmpDirectoryPath, tmpFileName2);
|
||||
const filePath3: string = path.join(tmpDirectoryPath, tmpFileName3);
|
||||
const filePath4: string = path.join(tmpDirectoryPath, tmpFileName4);
|
||||
|
||||
const expectedResult: IFileData[] = [
|
||||
{
|
||||
@@ -461,10 +462,10 @@ describe('SourceCodeReader', () => {
|
||||
const tmpFileName2: string = 'bar.js';
|
||||
const tmpFileName3: string = 'baz.js';
|
||||
const tmpFileName4: string = 'bark.js';
|
||||
const filePath1: string = `${tmpDirectoryPath}/${tmpFileName1}`;
|
||||
const filePath2: string = `${tmpDirectoryPath}/${tmpFileName2}`;
|
||||
const filePath3: string = `${tmpDirectoryPath}/${tmpFileName3}`;
|
||||
const filePath4: string = `${tmpDirectoryPath}/${tmpFileName4}`;
|
||||
const filePath1: string = path.join(tmpDirectoryPath, tmpFileName1);
|
||||
const filePath2: string = path.join(tmpDirectoryPath, tmpFileName2);
|
||||
const filePath3: string = path.join(tmpDirectoryPath, tmpFileName3);
|
||||
const filePath4: string = path.join(tmpDirectoryPath, tmpFileName4);
|
||||
|
||||
const expectedResult: IFileData[] = [
|
||||
{
|
||||
@@ -512,10 +513,10 @@ describe('SourceCodeReader', () => {
|
||||
const tmpFileName2: string = 'bar.js';
|
||||
const tmpFileName3: string = 'baz.js';
|
||||
const tmpFileName4: string = 'bark.js';
|
||||
const filePath1: string = `${tmpDirectoryPath}/${tmpFileName1}`;
|
||||
const filePath2: string = `${tmpDirectoryPath}/${tmpFileName2}`;
|
||||
const filePath3: string = `${tmpDirectoryPath}/${tmpFileName3}`;
|
||||
const filePath4: string = `${tmpDirectoryPath}/${tmpFileName4}`;
|
||||
const filePath1: string = path.join(tmpDirectoryPath, tmpFileName1);
|
||||
const filePath2: string = path.join(tmpDirectoryPath, tmpFileName2);
|
||||
const filePath3: string = path.join(tmpDirectoryPath, tmpFileName3);
|
||||
const filePath4: string = path.join(tmpDirectoryPath, tmpFileName4);
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
@@ -549,7 +550,7 @@ describe('SourceCodeReader', () => {
|
||||
describe('Variant #5: `inputPath` is a valid path with dot', () => {
|
||||
const tmpDirectoryWithDotPath: string = `${tmpDirectoryPath}.bar`;
|
||||
const tmpFileName: string = 'foo.js';
|
||||
const filePath: string = `${tmpDirectoryWithDotPath}/${tmpFileName}`;
|
||||
const filePath: string = path.join(tmpDirectoryWithDotPath, tmpFileName);
|
||||
|
||||
const expectedResult: IFileData[] = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user