ObfuscatedCodeFileUtils.spec.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. import { assert } from 'chai';
  2. import * as fs from 'fs';
  3. import * as mkdirp from 'mkdirp';
  4. import * as path from 'path';
  5. import * as rimraf from 'rimraf';
  6. import { ObfuscatedCodeFileUtils } from '../../../../src/cli/utils/ObfuscatedCodeFileUtils';
  7. describe('obfuscatedCodeFileUtils', () => {
  8. const tmpDirectoryPath: string = 'test/tmp';
  9. describe('getOutputCodePath', () => {
  10. before(() => {
  11. mkdirp.sync(path.join(tmpDirectoryPath, 'input', 'nested',));
  12. fs.writeFileSync(
  13. path.join(tmpDirectoryPath, 'input', 'nested', 'test-input.js'),
  14. 'var foo = 1;'
  15. );
  16. });
  17. describe('Variant #1: raw input path is a file path, raw output path is a file path', () => {
  18. const inputPath: string = path.join(tmpDirectoryPath, 'input', 'nested', 'test-input.js');
  19. const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'nested', 'test-input.js');
  20. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  21. const expectedOutputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  22. let outputCodePath: string;
  23. before(() => {
  24. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  25. rawInputPath,
  26. {
  27. output: rawOutputPath
  28. }
  29. );
  30. outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
  31. });
  32. it('should return output path that equals to passed output file path', () => {
  33. assert.equal(outputCodePath, expectedOutputCodePath);
  34. });
  35. });
  36. describe('Variant #2: raw input path is a file path, raw output path is a directory path', () => {
  37. const inputPath: string = path.join(tmpDirectoryPath, 'input', 'nested', 'test-input.js');
  38. const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'nested', 'test-input.js');
  39. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output');
  40. const expectedOutputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-input.js');
  41. let outputCodePath: string;
  42. before(() => {
  43. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  44. rawInputPath,
  45. {
  46. output: rawOutputPath
  47. }
  48. );
  49. outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
  50. });
  51. it('should return output path that equals to passed output directory with file name from actual file path', () => {
  52. assert.equal(outputCodePath, expectedOutputCodePath);
  53. });
  54. });
  55. describe('Variant #3: raw input path is a directory path, raw output path is a file path', () => {
  56. const inputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
  57. const rawInputPath: string = path.join(tmpDirectoryPath, 'input');
  58. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  59. let testFunc: () => string;
  60. before(() => {
  61. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  62. rawInputPath,
  63. {
  64. output: rawOutputPath
  65. }
  66. );
  67. testFunc = () => obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
  68. });
  69. it('should throw an error if output path is a file path', () => {
  70. assert.throws(testFunc, Error);
  71. });
  72. });
  73. describe('Variant #4: raw input path is a directory path, raw output path is a directory path', () => {
  74. describe('Variant #1: base directory name', () => {
  75. const inputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
  76. const rawInputPath: string = path.join(tmpDirectoryPath, 'input');
  77. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output');
  78. const expectedOutputCodePath: string = path.join(
  79. tmpDirectoryPath,
  80. 'output',
  81. 'test-input.js'
  82. );
  83. let outputCodePath: string;
  84. before(() => {
  85. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  86. rawInputPath,
  87. {
  88. output: rawOutputPath
  89. }
  90. );
  91. outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
  92. });
  93. it('should return output path that contains raw output path and actual file input path', () => {
  94. assert.equal(outputCodePath, expectedOutputCodePath);
  95. });
  96. });
  97. describe('Variant #2: base directory name with leading dot in output path', () => {
  98. const inputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
  99. const rawInputPath: string = path.join(tmpDirectoryPath, 'input');
  100. const rawOutputPath: string = path.join('.', tmpDirectoryPath, 'output');
  101. const expectedOutputCodePath: string = path.join(
  102. tmpDirectoryPath,
  103. 'output',
  104. 'test-input.js'
  105. );
  106. let outputCodePath: string;
  107. before(() => {
  108. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  109. rawInputPath,
  110. {
  111. output: rawOutputPath
  112. }
  113. );
  114. outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
  115. });
  116. it('should return output path that contains raw output path and actual file input path', () => {
  117. assert.equal(outputCodePath, expectedOutputCodePath);
  118. });
  119. });
  120. describe('Variant #3: base nested directory name', () => {
  121. const inputPath: string = path.join(tmpDirectoryPath, 'input', 'nested', 'test-input.js');
  122. const rawInputPath: string = path.join(tmpDirectoryPath, 'input');
  123. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output');
  124. const expectedOutputCodePath: string = path.join(
  125. tmpDirectoryPath,
  126. 'output',
  127. 'nested',
  128. 'test-input.js'
  129. );
  130. let outputCodePath: string;
  131. before(() => {
  132. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  133. rawInputPath,
  134. {
  135. output: rawOutputPath
  136. }
  137. );
  138. outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
  139. });
  140. it('should return output path that contains raw output path and actual file input path', () => {
  141. assert.equal(outputCodePath, expectedOutputCodePath);
  142. });
  143. });
  144. describe('Variant #4: directory name with dot', () => {
  145. const inputPath: string = path.join(tmpDirectoryPath, 'input', 'nested', 'test-input.js');
  146. const rawInputPath: string = path.join(tmpDirectoryPath, 'input');
  147. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'foo.bar');
  148. const expectedOutputCodePath: string = path.join(
  149. tmpDirectoryPath,
  150. 'output',
  151. 'foo.bar',
  152. 'nested',
  153. 'test-input.js'
  154. );
  155. let outputCodePath: string;
  156. before(() => {
  157. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  158. rawInputPath,
  159. {
  160. output: rawOutputPath
  161. }
  162. );
  163. outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
  164. });
  165. it('should return output path that contains raw output path and actual file input path', () => {
  166. assert.equal(outputCodePath, expectedOutputCodePath);
  167. });
  168. });
  169. describe('Variant #5: input directory name with dot only', () => {
  170. const inputPath: string = path.join('test-input.js');
  171. const rawInputPath: string = path.join('.');
  172. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output');
  173. const expectedOutputCodePath: string = path.join(
  174. tmpDirectoryPath,
  175. 'output',
  176. 'test-input.js'
  177. );
  178. let outputCodePath: string;
  179. before(() => {
  180. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  181. rawInputPath,
  182. {
  183. output: rawOutputPath
  184. }
  185. );
  186. outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
  187. });
  188. it('should return output path that contains raw output path and actual file input path', () => {
  189. assert.equal(outputCodePath, expectedOutputCodePath);
  190. });
  191. });
  192. describe('Variant #6: input directory name with dot and slash only', () => {
  193. const inputPath: string = path.join('test-input.js');
  194. const rawInputPath: string = path.join('./');
  195. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output');
  196. const expectedOutputCodePath: string = path.join(
  197. tmpDirectoryPath,
  198. 'output',
  199. 'test-input.js'
  200. );
  201. let outputCodePath: string;
  202. before(() => {
  203. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  204. rawInputPath,
  205. {
  206. output: rawOutputPath
  207. }
  208. );
  209. outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
  210. });
  211. it('should return output path that contains raw output path and actual file input path', () => {
  212. assert.equal(outputCodePath, expectedOutputCodePath);
  213. });
  214. });
  215. });
  216. describe('Variant #5: Win32 environment', () => {
  217. const baseDirnamePath: string = __dirname;
  218. before(() => {
  219. mkdirp.sync(path.join(baseDirnamePath, tmpDirectoryPath, 'input', 'nested'));
  220. fs.writeFileSync(
  221. path.join(baseDirnamePath, tmpDirectoryPath, 'input', 'nested', 'test-input.js'),
  222. 'var foo = 1;'
  223. );
  224. });
  225. describe('Variant #1: raw input absolute path is a directory path, raw output absolute path is a directory path', () => {
  226. describe('Variant #1: base directory name', () => {
  227. const inputPath: string = path.join(baseDirnamePath, tmpDirectoryPath, 'input', 'nested', 'test-input.js');
  228. const rawInputPath: string = path.join(baseDirnamePath, tmpDirectoryPath, 'input');
  229. const rawOutputPath: string = path.join(baseDirnamePath, tmpDirectoryPath, 'output');
  230. const expectedOutputCodePath: string = path.join(
  231. baseDirnamePath,
  232. tmpDirectoryPath,
  233. 'output',
  234. 'nested',
  235. 'test-input.js'
  236. );
  237. let outputCodePath: string;
  238. before(() => {
  239. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  240. rawInputPath,
  241. {
  242. output: rawOutputPath
  243. }
  244. );
  245. outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath);
  246. });
  247. it('should return output path that contains raw output path and actual file input path', () => {
  248. assert.equal(outputCodePath, expectedOutputCodePath);
  249. });
  250. });
  251. });
  252. after(() => {
  253. rimraf.sync(path.join(baseDirnamePath, tmpDirectoryPath));
  254. });
  255. });
  256. after(() => {
  257. rimraf.sync(tmpDirectoryPath);
  258. });
  259. });
  260. describe('getOutputSourceMapPath', () => {
  261. describe('Variant #1: output code path is a file path', () => {
  262. const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
  263. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  264. const outputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  265. const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js.map');
  266. let outputSourceMapPath: string;
  267. before(() => {
  268. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  269. rawInputPath,
  270. {
  271. output: rawOutputPath
  272. }
  273. );
  274. outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath);
  275. });
  276. it('should return output path for source map', () => {
  277. assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
  278. });
  279. });
  280. describe('Variant #2: output code path is a directory path and source map file name is not set', () => {
  281. const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
  282. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  283. const outputCodePath: string = path.join(tmpDirectoryPath, 'output');
  284. let testFunc: () => string;
  285. before(() => {
  286. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  287. rawInputPath,
  288. {
  289. output: rawOutputPath
  290. }
  291. );
  292. testFunc = () => obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath);
  293. });
  294. it('should throw an error if output code path is a directory path and source map file name is not set', () => {
  295. assert.throws(testFunc, Error);
  296. });
  297. });
  298. describe('Variant #3: output code path with dot', () => {
  299. const rawInputPath: string = path.join(tmpDirectoryPath, 'input.with.dot', 'test-input.js');
  300. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output.with.dot', 'test-output.js');
  301. const outputCodePath: string = path.join(tmpDirectoryPath, 'output.with.dot', 'test-output.js');
  302. const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output.with.dot', 'test-output.js.map');
  303. let outputSourceMapPath: string;
  304. before(() => {
  305. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  306. rawInputPath,
  307. {
  308. output: rawOutputPath
  309. }
  310. );
  311. outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath);
  312. });
  313. it('should return output path for source map', () => {
  314. assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
  315. });
  316. });
  317. describe('Variant #4: source map file name without extension is set', () => {
  318. const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
  319. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  320. const outputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  321. const sourceMapFileName: string = 'foo';
  322. const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'foo.js.map');
  323. let outputSourceMapPath: string;
  324. before(() => {
  325. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  326. rawInputPath,
  327. {
  328. output: rawOutputPath
  329. }
  330. );
  331. outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
  332. });
  333. it('should return output path for source map', () => {
  334. assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
  335. });
  336. });
  337. describe('Variant #5: output code path is a directory path and source map file name without extension is set', () => {
  338. const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
  339. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  340. const outputCodePath: string = path.join(tmpDirectoryPath, 'output');
  341. const sourceMapFileName: string = 'foo';
  342. const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'foo.js.map');
  343. let outputSourceMapPath: string;
  344. before(() => {
  345. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  346. rawInputPath,
  347. {
  348. output: rawOutputPath
  349. }
  350. );
  351. outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
  352. });
  353. it('should return output path for source map', () => {
  354. assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
  355. });
  356. });
  357. describe('Variant #6: source map file name with wrong extension is set', () => {
  358. const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
  359. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  360. const outputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  361. const sourceMapFileName: string = 'foo.js';
  362. const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'foo.js.map');
  363. let outputSourceMapPath: string;
  364. before(() => {
  365. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  366. rawInputPath,
  367. {
  368. output: rawOutputPath
  369. }
  370. );
  371. outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
  372. });
  373. it('should return output path for source map', () => {
  374. assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
  375. });
  376. });
  377. describe('Variant #7: source map file name with valid extension is set', () => {
  378. const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
  379. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  380. const outputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  381. const sourceMapFileName: string = 'foo.js.map';
  382. const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'foo.js.map');
  383. let outputSourceMapPath: string;
  384. before(() => {
  385. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  386. rawInputPath,
  387. {
  388. output: rawOutputPath
  389. }
  390. );
  391. outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
  392. });
  393. it('should return output path for source map', () => {
  394. assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
  395. });
  396. });
  397. describe('Variant #8: source map file name is a path', () => {
  398. const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
  399. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  400. const outputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  401. const sourceMapFileName: string = path.join('parent', 'foo.js.map');
  402. const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'parent', 'foo.js.map');
  403. let outputSourceMapPath: string;
  404. before(() => {
  405. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  406. rawInputPath,
  407. {
  408. output: rawOutputPath
  409. }
  410. );
  411. outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
  412. });
  413. it('should return output path for source map', () => {
  414. assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
  415. });
  416. });
  417. describe('Variant #9: Win32 environment', () => {
  418. describe('Variant #1: output code path is a directory path', () => {
  419. const rawInputPath: string = path.join('C:\\', tmpDirectoryPath, 'input', 'test-input.js');
  420. const rawOutputPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js');
  421. const outputCodePath: string = path.join('C:\\', tmpDirectoryPath, 'output');
  422. const sourceMapFileName: string = path.join('foo');
  423. const expectedOutputSourceMapPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'foo.js.map');
  424. let outputSourceMapPath: string;
  425. before(() => {
  426. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  427. rawInputPath,
  428. {
  429. output: rawOutputPath
  430. }
  431. );
  432. outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
  433. });
  434. it('should return output path for source map', () => {
  435. assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
  436. });
  437. });
  438. describe('Variant #2: source map file name is a file name without extension', () => {
  439. const rawInputPath: string = path.join('C:\\', tmpDirectoryPath, 'input', 'test-input.js');
  440. const rawOutputPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js');
  441. const outputCodePath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js');
  442. const sourceMapFileName: string = path.join('foo');
  443. const expectedOutputSourceMapPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'foo.js.map');
  444. let outputSourceMapPath: string;
  445. before(() => {
  446. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  447. rawInputPath,
  448. {
  449. output: rawOutputPath
  450. }
  451. );
  452. outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
  453. });
  454. it('should return output path for source map', () => {
  455. assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
  456. });
  457. });
  458. describe('Variant #3: source map file name is a file name with an extension', () => {
  459. const rawInputPath: string = path.join('C:\\', tmpDirectoryPath, 'input', 'test-input.js');
  460. const rawOutputPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js');
  461. const outputCodePath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js');
  462. const sourceMapFileName: string = path.join('foo.js.map');
  463. const expectedOutputSourceMapPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'foo.js.map');
  464. let outputSourceMapPath: string;
  465. before(() => {
  466. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  467. rawInputPath,
  468. {
  469. output: rawOutputPath
  470. }
  471. );
  472. outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
  473. });
  474. it('should return output path for source map', () => {
  475. assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
  476. });
  477. });
  478. describe('Variant #4: output path and win32 path in source map file name', () => {
  479. const rawInputPath: string = path.join('C:\\', tmpDirectoryPath, 'input', 'test-input.js');
  480. const rawOutputPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js');
  481. const outputCodePath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js');
  482. const sourceMapFileName: string = path.join('C:\\', 'parent', 'foo.js.map');
  483. const expectedOutputSourceMapPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'parent', 'foo.js.map');
  484. let outputSourceMapPath: string;
  485. before(() => {
  486. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  487. rawInputPath,
  488. {
  489. output: rawOutputPath
  490. }
  491. );
  492. outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName);
  493. });
  494. it('should return output path for source map', () => {
  495. assert.equal(outputSourceMapPath, expectedOutputSourceMapPath);
  496. });
  497. });
  498. });
  499. describe('Variant #10: empty paths', () => {
  500. const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js');
  501. const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js');
  502. let testFunc: () => string;
  503. before(() => {
  504. const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(
  505. rawInputPath,
  506. {
  507. output: rawOutputPath
  508. }
  509. );
  510. testFunc = () => obfuscatedCodeFileUtils.getOutputSourceMapPath('', '');
  511. });
  512. it('should throw an error if output code path is empty', () => {
  513. assert.throws(testFunc, Error);
  514. });
  515. });
  516. });
  517. });