|
@@ -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', 'nested',));
|
|
|
fs.writeFileSync(
|
|
|
- `${tmpDirectoryPath}/input/test-input.js`,
|
|
|
+ path.join(tmpDirectoryPath, 'input', 'nested', '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', 'nested', 'test-input.js');
|
|
|
+ const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'nested', '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', 'nested', 'test-input.js');
|
|
|
+ const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'nested', '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,15 @@ 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', 'nested', 'test-input.js');
|
|
|
+ const rawInputPath: string = path.join(tmpDirectoryPath, 'input');
|
|
|
+ const rawOutputPath: string = path.join(tmpDirectoryPath, 'output');
|
|
|
+ const expectedOutputCodePath: string = path.join(
|
|
|
+ tmpDirectoryPath,
|
|
|
+ 'output',
|
|
|
+ 'nested',
|
|
|
+ 'test-input.js'
|
|
|
+ );
|
|
|
|
|
|
let outputCodePath: string;
|
|
|
|
|
@@ -110,10 +116,16 @@ 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', 'nested', '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',
|
|
|
+ 'nested',
|
|
|
+ 'test-input.js'
|
|
|
+ );
|
|
|
|
|
|
let outputCodePath: string;
|
|
|
|
|
@@ -133,31 +145,364 @@ describe('ObfuscatedCodeWriter', () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ describe('Variant #5: Win32 environment', () => {
|
|
|
+ const baseDirnamePath: string = __dirname;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ mkdirp.sync(path.join(baseDirnamePath, tmpDirectoryPath, 'input', 'nested'));
|
|
|
+ fs.writeFileSync(
|
|
|
+ path.join(baseDirnamePath, tmpDirectoryPath, 'input', 'nested', 'test-input.js'),
|
|
|
+ 'var foo = 1;'
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #1: raw input absolute path is a directory path, raw output absolute path is a directory path', () => {
|
|
|
+ describe('Variant #1: base directory name', () => {
|
|
|
+ const inputPath: string = path.join(baseDirnamePath, tmpDirectoryPath, 'input', 'nested', 'test-input.js');
|
|
|
+ const rawInputPath: string = path.join(baseDirnamePath, tmpDirectoryPath, 'input');
|
|
|
+ const rawOutputPath: string = path.join(baseDirnamePath, tmpDirectoryPath, 'output');
|
|
|
+ const expectedOutputCodePath: string = path.join(
|
|
|
+ baseDirnamePath,
|
|
|
+ tmpDirectoryPath,
|
|
|
+ 'output',
|
|
|
+ 'nested',
|
|
|
+ 'test-input.js'
|
|
|
+ );
|
|
|
+
|
|
|
+ let outputCodePath: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
+ rawInputPath,
|
|
|
+ {
|
|
|
+ output: rawOutputPath
|
|
|
+ }
|
|
|
+ );
|
|
|
+ outputCodePath = obfuscatedCodeWriter.getOutputCodePath(inputPath);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return output path that contains raw output path and actual file input path', () => {
|
|
|
+ assert.equal(outputCodePath, expectedOutputCodePath);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ after(() => {
|
|
|
+ rimraf.sync(path.join(baseDirnamePath, tmpDirectoryPath));
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
after(() => {
|
|
|
rimraf.sync(tmpDirectoryPath);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
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`;
|
|
|
+ describe('Variant #1: output code path is a file path', () => {
|
|
|
+ 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;
|
|
|
+ let outputSourceMapPath: string;
|
|
|
|
|
|
- before(() => {
|
|
|
- const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
- rawInputPath,
|
|
|
- {
|
|
|
- output: rawOutputPath
|
|
|
- }
|
|
|
- );
|
|
|
- outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath);
|
|
|
+ before(() => {
|
|
|
+ const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
+ rawInputPath,
|
|
|
+ {
|
|
|
+ output: rawOutputPath
|
|
|
+ }
|
|
|
+ );
|
|
|
+ outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return output path for source map', () => {
|
|
|
+ assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #2: output code path is a directory path and source map file name is not set', () => {
|
|
|
+ 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');
|
|
|
+
|
|
|
+ let testFunc: () => string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
+ rawInputPath,
|
|
|
+ {
|
|
|
+ output: rawOutputPath
|
|
|
+ }
|
|
|
+ );
|
|
|
+ testFunc = () => obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should throw an error if output code path is a directory path and source map file name is not set', () => {
|
|
|
+ assert.throws(testFunc, Error);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #3: output code path with dot', () => {
|
|
|
+ const rawInputPath: string = path.join(tmpDirectoryPath, 'input.with.dot', 'test-input.js');
|
|
|
+ const rawOutputPath: string = path.join(tmpDirectoryPath, 'output.with.dot', 'test-output.js');
|
|
|
+ const outputCodePath: string = path.join(tmpDirectoryPath, 'output.with.dot', 'test-output.js');
|
|
|
+ const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output.with.dot', 'test-output.js.map');
|
|
|
+
|
|
|
+ let outputSourceMapPath: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
+ rawInputPath,
|
|
|
+ {
|
|
|
+ output: rawOutputPath
|
|
|
+ }
|
|
|
+ );
|
|
|
+ outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return output path for source map', () => {
|
|
|
+ assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #4: source map file name without extension is set', () => {
|
|
|
+ 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 sourceMapFileName: string = 'foo';
|
|
|
+ const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'foo.js.map');
|
|
|
+
|
|
|
+ let outputSourceMapPath: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
+ rawInputPath,
|
|
|
+ {
|
|
|
+ output: rawOutputPath
|
|
|
+ }
|
|
|
+ );
|
|
|
+ outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return output path for source map', () => {
|
|
|
+ assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #5: output code path is a directory path and source map file name without extension is set', () => {
|
|
|
+ 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');
|
|
|
+ const sourceMapFileName: string = 'foo';
|
|
|
+ const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'foo.js.map');
|
|
|
+
|
|
|
+ let outputSourceMapPath: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
+ rawInputPath,
|
|
|
+ {
|
|
|
+ output: rawOutputPath
|
|
|
+ }
|
|
|
+ );
|
|
|
+ outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return output path for source map', () => {
|
|
|
+ assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #6: source map file name with wrong extension is set', () => {
|
|
|
+ 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 sourceMapFileName: string = 'foo.js';
|
|
|
+ const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'foo.js.map');
|
|
|
+
|
|
|
+ let outputSourceMapPath: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
+ rawInputPath,
|
|
|
+ {
|
|
|
+ output: rawOutputPath
|
|
|
+ }
|
|
|
+ );
|
|
|
+ outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return output path for source map', () => {
|
|
|
+ assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #7: source map file name with valid extension is set', () => {
|
|
|
+ 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 sourceMapFileName: string = 'foo.js.map';
|
|
|
+ const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'foo.js.map');
|
|
|
+
|
|
|
+ let outputSourceMapPath: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
+ rawInputPath,
|
|
|
+ {
|
|
|
+ output: rawOutputPath
|
|
|
+ }
|
|
|
+ );
|
|
|
+ outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return output path for source map', () => {
|
|
|
+ assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #8: source map file name is a path', () => {
|
|
|
+ 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 sourceMapFileName: string = path.join('parent', 'foo.js.map');
|
|
|
+ const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'parent', 'foo.js.map');
|
|
|
+
|
|
|
+ let outputSourceMapPath: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
+ rawInputPath,
|
|
|
+ {
|
|
|
+ output: rawOutputPath
|
|
|
+ }
|
|
|
+ );
|
|
|
+ outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return output path for source map', () => {
|
|
|
+ assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #9: Win32 environment', () => {
|
|
|
+ describe('Variant #1: output code path is a directory path', () => {
|
|
|
+ const rawInputPath: string = path.join('C:\\', tmpDirectoryPath, 'input', 'test-input.js');
|
|
|
+ const rawOutputPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js');
|
|
|
+ const outputCodePath: string = path.join('C:\\', tmpDirectoryPath, 'output');
|
|
|
+ const sourceMapFileName: string = path.join('foo');
|
|
|
+ const expectedOutputSourceMapPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'foo.js.map');
|
|
|
+
|
|
|
+ let outputSourceMapPath: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
+ rawInputPath,
|
|
|
+ {
|
|
|
+ output: rawOutputPath
|
|
|
+ }
|
|
|
+ );
|
|
|
+ outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return output path for source map', () => {
|
|
|
+ assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #2: source map file name is a file name without extension', () => {
|
|
|
+ const rawInputPath: string = path.join('C:\\', tmpDirectoryPath, 'input', 'test-input.js');
|
|
|
+ const rawOutputPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js');
|
|
|
+ const outputCodePath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js');
|
|
|
+ const sourceMapFileName: string = path.join('foo');
|
|
|
+ const expectedOutputSourceMapPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'foo.js.map');
|
|
|
+
|
|
|
+ let outputSourceMapPath: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
+ rawInputPath,
|
|
|
+ {
|
|
|
+ output: rawOutputPath
|
|
|
+ }
|
|
|
+ );
|
|
|
+ outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return output path for source map', () => {
|
|
|
+ assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #3: source map file name is a file name with an extension', () => {
|
|
|
+ const rawInputPath: string = path.join('C:\\', tmpDirectoryPath, 'input', 'test-input.js');
|
|
|
+ const rawOutputPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js');
|
|
|
+ const outputCodePath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js');
|
|
|
+ const sourceMapFileName: string = path.join('foo.js.map');
|
|
|
+ const expectedOutputSourceMapPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'foo.js.map');
|
|
|
+
|
|
|
+ let outputSourceMapPath: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
+ rawInputPath,
|
|
|
+ {
|
|
|
+ output: rawOutputPath
|
|
|
+ }
|
|
|
+ );
|
|
|
+ outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return output path for source map', () => {
|
|
|
+ assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #4: output path and win32 path in source map file name', () => {
|
|
|
+ const rawInputPath: string = path.join('C:\\', tmpDirectoryPath, 'input', 'test-input.js');
|
|
|
+ const rawOutputPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js');
|
|
|
+ const outputCodePath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js');
|
|
|
+ const sourceMapFileName: string = path.join('C:\\', 'parent', 'foo.js.map');
|
|
|
+ const expectedOutputSourceMapPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'parent', 'foo.js.map');
|
|
|
+
|
|
|
+ let outputSourceMapPath: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
+ rawInputPath,
|
|
|
+ {
|
|
|
+ output: rawOutputPath
|
|
|
+ }
|
|
|
+ );
|
|
|
+ outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return output path for source map', () => {
|
|
|
+ assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
- it('should return output path for source map', () => {
|
|
|
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
|
|
|
+ describe('Variant #10: empty paths', () => {
|
|
|
+ const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
|
|
|
+ const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
|
|
|
+
|
|
|
+ let testFunc: () => string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
|
|
|
+ rawInputPath,
|
|
|
+ {
|
|
|
+ output: rawOutputPath
|
|
|
+ }
|
|
|
+ );
|
|
|
+ testFunc = () => obfuscatedCodeWriter.getOutputSourceMapPath('', '');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should throw an error if output code path is empty', () => {
|
|
|
+ assert.throws(testFunc, Error);
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
});
|