123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730 |
- 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 { ObfuscatedCodeFileUtils } from '../../../../src/cli/utils/ObfuscatedCodeFileUtils';
- describe('obfuscatedCodeFileUtils', () => {
- const tmpDirectoryPath: string = 'test/tmp';
- describe('getOutputCodePath', () => {
- before(() => {
- mkdirp.sync(path.join(tmpDirectoryPath, 'input', 'nested',));
- fs.writeFileSync(
- 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 = 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;
- before(() => {
- const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
- });
- it('should return output path that equals to passed output file path', () => {
- assert.equal(outputCodePath, expectedOutputCodePath);
- });
- });
- describe('Variant #2: raw input path is a file path, raw output path is a directory path', () => {
- 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;
- before(() => {
- const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
- });
- it('should return output path that equals to passed output directory with file name from actual file path', () => {
- assert.equal(outputCodePath, expectedOutputCodePath);
- });
- });
- describe('Variant #3: raw input path is a directory path, raw output path is a file path', () => {
- 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;
- before(() => {
- const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- testFunc = () => obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
- });
- it('should throw an error if output path is a file path', () => {
- assert.throws(testFunc, Error);
- });
- });
- 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 = 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',
- 'test-input.js'
- );
- let outputCodePath: string;
- before(() => {
- const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
- });
- it('should return output path that contains raw output path and actual file input path', () => {
- assert.equal(outputCodePath, expectedOutputCodePath);
- });
- });
- describe('Variant #2: base directory name with leading dot in output path', () => {
- 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',
- 'test-input.js'
- );
- let outputCodePath: string;
- before(() => {
- const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
- });
- it('should return output path that contains raw output path and actual file input path', () => {
- assert.equal(outputCodePath, expectedOutputCodePath);
- });
- });
- describe('Variant #3: base nested directory name', () => {
- 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;
- before(() => {
- const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
- });
- it('should return output path that contains raw output path and actual file input path', () => {
- assert.equal(outputCodePath, expectedOutputCodePath);
- });
- });
- describe('Variant #4: directory name with dot', () => {
- 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;
- before(() => {
- const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
- });
- it('should return output path that contains raw output path and actual file input path', () => {
- assert.equal(outputCodePath, expectedOutputCodePath);
- });
- });
- describe('Variant #5: input directory name with dot only', () => {
- const inputPath: string = path.join('test-input.js');
- const rawInputPath: string = path.join('.');
- const rawOutputPath: string = path.join(tmpDirectoryPath, 'output');
- const expectedOutputCodePath: string = path.join(
- tmpDirectoryPath,
- 'output',
- 'test-input.js'
- );
- let outputCodePath: string;
- before(() => {
- const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
- });
- it('should return output path that contains raw output path and actual file input path', () => {
- assert.equal(outputCodePath, expectedOutputCodePath);
- });
- });
- describe('Variant #6: input directory name with dot and slash only', () => {
- const inputPath: string = path.join('test-input.js');
- const rawInputPath: string = path.join('./');
- const rawOutputPath: string = path.join(tmpDirectoryPath, 'output');
- const expectedOutputCodePath: string = path.join(
- tmpDirectoryPath,
- 'output',
- 'test-input.js'
- );
- let outputCodePath: string;
- before(() => {
- const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
- });
- it('should return output path that contains raw output path and actual file input path', () => {
- assert.equal(outputCodePath, expectedOutputCodePath);
- });
- });
- });
- 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 obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputCodePath = obfuscatedCodeFileUtils.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', () => {
- describe('Variant #1: output code path is a file path', () => {
- describe('Variant #1: file path with directory', () => {
- describe('Variant #1: source map file name is not set', () => {
- describe('Variant #1: base output code 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;
- before(() => {
- const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath);
- });
- it('should return output path for source map', () => {
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
- });
- });
- describe('Variant #2: 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 obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath);
- });
- it('should return output path for source map', () => {
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
- });
- });
- });
- describe('Variant #2: source map file name is set', () => {
- describe('Variant #1: 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 obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
- });
- it('should return output path for source map', () => {
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
- });
- });
- describe('Variant #2: 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 obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
- });
- it('should return output path for source map', () => {
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
- });
- });
- describe('Variant #3: 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 obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
- });
- it('should return output path for source map', () => {
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
- });
- });
- describe('Variant #4: source map file name contains directories', () => {
- 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 obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
- });
- it('should return output path for source map', () => {
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
- });
- });
- describe('Variant #5: 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 sourceMapFileName: string = path.join('parent', 'foo.js.map');
- const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output.with.dot', 'parent', 'foo.js.map');
- let outputSourceMapPath: string;
- before(() => {
- const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
- });
- it('should return output path for source map', () => {
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
- });
- });
- });
- });
- describe('Variant #2: file path without directory', () => {
- describe('Variant #1: source map file name is not set', () => {
- describe('Variant #1: base output code path', () => {
- const rawInputPath: string = 'test-input.js';
- const rawOutputPath: string = 'test-output.js';
- const outputCodePath: string = 'test-output.js';
- const expectedOutputSourceMapPath: string = 'test-output.js.map';
- let outputSourceMapPath: string;
- before(() => {
- const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath);
- });
- it('should return output path for source map', () => {
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
- });
- });
- });
- describe('Variant #2: source map file name is set', () => {
- describe('Variant #1: base output code path', () => {
- const rawInputPath: string = 'test-input.js';
- const rawOutputPath: string = 'test-output.js';
- const outputCodePath: string = 'test-output.js';
- const outputSourceMapFileName: string = 'test-output-source-map';
- const expectedOutputSourceMapPath: string = 'test-output-source-map.js.map';
- let outputSourceMapPath: string;
- before(() => {
- const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(
- outputCodePath,
- outputSourceMapFileName
- );
- });
- it('should return output path for source map', () => {
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
- });
- });
- });
- });
- describe('Variant #10: Win32 environment', () => {
- describe('Variant #1: 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 obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.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 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 obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
- });
- it('should return output path for source map', () => {
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
- });
- });
- describe('Variant #3: 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 obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
- });
- it('should return output path for source map', () => {
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
- });
- });
- });
- });
- describe(`Variant #2: output code path is a directory path`, () => {
- describe('Variant #1: 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 obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- testFunc = () => obfuscatedCodeFileUtils.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 #2: 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 obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
- });
- it('should return output path for source map', () => {
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
- });
- });
- describe('Variant #2: source map file name with 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.js.map';
- const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'foo.js.map');
- let outputSourceMapPath: string;
- before(() => {
- const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
- });
- it('should return output path for source map', () => {
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
- });
- });
- describe('Variant #3: Win32 environment', () => {
- 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 obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
- });
- it('should return output path for source map', () => {
- assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
- });
- });
- });
- describe('Variant #3: 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 obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
- rawInputPath,
- {
- output: rawOutputPath
- }
- );
- testFunc = () => obfuscatedCodeFileUtils.getOutputSourceMapPath('', '');
- });
- it('should throw an error if output code path is empty', () => {
- assert.throws(testFunc, Error);
- });
- });
- });
- });
|