OptionsNormalizer.spec.ts 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. import 'reflect-metadata';
  2. import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
  3. import { assert } from 'chai';
  4. import { TInputOptions } from '../../../src/types/options/TInputOptions';
  5. import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
  6. import { IOptions } from '../../../src/interfaces/options/IOptions';
  7. import { IOptionsNormalizer } from '../../../src/interfaces/options/IOptionsNormalizer';
  8. import { StringArrayEncoding } from '../../../src/enums/node-transformers/string-array-transformers/StringArrayEncoding';
  9. import { DEFAULT_PRESET } from '../../../src/options/presets/Default';
  10. import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
  11. /**
  12. * @param optionsPreset
  13. * @returns {IOptions}
  14. */
  15. function getNormalizedOptions (optionsPreset: TInputOptions): TInputOptions {
  16. const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
  17. inversifyContainerFacade.load('', '', optionsPreset);
  18. const options: IOptions = inversifyContainerFacade
  19. .get<IOptions>(ServiceIdentifiers.IOptions);
  20. const optionsNormalizer: IOptionsNormalizer = inversifyContainerFacade
  21. .get<IOptionsNormalizer>(ServiceIdentifiers.IOptionsNormalizer);
  22. return <TInputOptions>optionsNormalizer.normalize(options);
  23. }
  24. function getDefaultOptions(): TInputOptions {
  25. return {
  26. ...DEFAULT_PRESET,
  27. seed: 1 // set `seed` to the fixed value, to prevent a new seed for the each case
  28. };
  29. }
  30. describe('OptionsNormalizer', () => {
  31. describe('normalize', () => {
  32. let optionsPreset: TInputOptions,
  33. expectedOptionsPreset: TInputOptions;
  34. describe('controlFlowFlatteningThresholdRule', () => {
  35. before(() => {
  36. optionsPreset = getNormalizedOptions({
  37. ...getDefaultOptions(),
  38. controlFlowFlattening: true,
  39. controlFlowFlatteningThreshold: 0
  40. });
  41. expectedOptionsPreset = {
  42. ...getDefaultOptions(),
  43. controlFlowFlattening: false,
  44. controlFlowFlatteningThreshold: 0
  45. };
  46. });
  47. it('should normalize options preset', () => {
  48. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  49. });
  50. });
  51. describe('deadCodeInjectionRule', () => {
  52. before(() => {
  53. optionsPreset = getNormalizedOptions({
  54. ...getDefaultOptions(),
  55. deadCodeInjection: true,
  56. deadCodeInjectionThreshold: 0.4,
  57. stringArray: false,
  58. stringArrayThreshold: 0
  59. });
  60. expectedOptionsPreset = {
  61. ...getDefaultOptions(),
  62. deadCodeInjection: true,
  63. deadCodeInjectionThreshold: 0.4,
  64. stringArray: true,
  65. stringArrayThreshold: 0.75
  66. };
  67. });
  68. it('should normalize options preset', () => {
  69. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  70. });
  71. });
  72. describe('deadCodeInjectionRule', () => {
  73. describe('`stringArrayThreshold` option is empty', () => {
  74. before(() => {
  75. optionsPreset = getNormalizedOptions({
  76. ...getDefaultOptions(),
  77. deadCodeInjection: true,
  78. deadCodeInjectionThreshold: 0.4,
  79. stringArray: false,
  80. stringArrayThreshold: 0
  81. });
  82. expectedOptionsPreset = {
  83. ...getDefaultOptions(),
  84. deadCodeInjection: true,
  85. deadCodeInjectionThreshold: 0.4,
  86. stringArray: true,
  87. stringArrayThreshold: 0.75
  88. };
  89. });
  90. it('should normalize options preset', () => {
  91. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  92. });
  93. });
  94. describe('`stringArrayThreshold` option is not empty', () => {
  95. before(() => {
  96. optionsPreset = getNormalizedOptions({
  97. ...getDefaultOptions(),
  98. deadCodeInjection: true,
  99. deadCodeInjectionThreshold: 0.4,
  100. stringArray: false,
  101. stringArrayThreshold: 0.5
  102. });
  103. expectedOptionsPreset = {
  104. ...getDefaultOptions(),
  105. deadCodeInjection: true,
  106. deadCodeInjectionThreshold: 0.4,
  107. stringArray: true,
  108. stringArrayThreshold: 0.5
  109. };
  110. });
  111. it('should normalize options preset', () => {
  112. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  113. });
  114. });
  115. });
  116. describe('deadCodeInjectionThresholdRule', () => {
  117. before(() => {
  118. optionsPreset = getNormalizedOptions({
  119. ...getDefaultOptions(),
  120. deadCodeInjection: true,
  121. deadCodeInjectionThreshold: 0
  122. });
  123. expectedOptionsPreset = {
  124. ...getDefaultOptions(),
  125. deadCodeInjection: false,
  126. deadCodeInjectionThreshold: 0
  127. };
  128. });
  129. it('should normalize options preset', () => {
  130. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  131. });
  132. });
  133. describe('domainLockRedirectUrlRule', () => {
  134. describe('Variant #1: `domainLock` option is set', () => {
  135. before(() => {
  136. optionsPreset = getNormalizedOptions({
  137. ...getDefaultOptions(),
  138. domainLock: [
  139. 'localhost'
  140. ],
  141. domainLockRedirectUrl: 'https://example.com'
  142. });
  143. expectedOptionsPreset = {
  144. ...getDefaultOptions(),
  145. domainLock: [
  146. 'localhost'
  147. ],
  148. domainLockRedirectUrl: 'https://example.com'
  149. };
  150. });
  151. it('should not normalize options preset', () => {
  152. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  153. });
  154. });
  155. describe('Variant #2 `domainLock` option is not set', () => {
  156. before(() => {
  157. optionsPreset = getNormalizedOptions({
  158. ...getDefaultOptions(),
  159. domainLock: [],
  160. domainLockRedirectUrl: 'https://example.com'
  161. });
  162. expectedOptionsPreset = {
  163. ...getDefaultOptions(),
  164. domainLock: [],
  165. domainLockRedirectUrl: 'about:blank'
  166. };
  167. });
  168. it('should normalize options preset', () => {
  169. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  170. });
  171. });
  172. });
  173. describe('domainLockRule', () => {
  174. before(() => {
  175. optionsPreset = getNormalizedOptions({
  176. ...getDefaultOptions(),
  177. domainLock: [
  178. '//localhost:9000',
  179. 'https://google.ru/abc?cde=fgh'
  180. ]
  181. });
  182. expectedOptionsPreset = {
  183. ...getDefaultOptions(),
  184. domainLock: [
  185. 'localhost',
  186. 'google.ru'
  187. ]
  188. };
  189. });
  190. it('should normalize options preset', () => {
  191. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  192. });
  193. });
  194. describe('inputFileNameRule', () => {
  195. describe('Variant #1: extension isn\'t set', () => {
  196. before(() => {
  197. optionsPreset = getNormalizedOptions({
  198. ...getDefaultOptions(),
  199. inputFileName: 'foo'
  200. });
  201. expectedOptionsPreset = {
  202. ...getDefaultOptions(),
  203. inputFileName: 'foo.js'
  204. };
  205. });
  206. it('should normalize options preset', () => {
  207. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  208. });
  209. });
  210. describe('Variant #2: extension is set', () => {
  211. before(() => {
  212. optionsPreset = getNormalizedOptions({
  213. ...getDefaultOptions(),
  214. inputFileName: 'foo.js'
  215. });
  216. expectedOptionsPreset = {
  217. ...getDefaultOptions(),
  218. inputFileName: 'foo.js'
  219. };
  220. });
  221. it('should normalize options preset', () => {
  222. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  223. });
  224. });
  225. describe('Variant #3: extension in set with `.map` postfix', () => {
  226. before(() => {
  227. optionsPreset = getNormalizedOptions({
  228. ...getDefaultOptions(),
  229. inputFileName: 'foo.map.js'
  230. });
  231. expectedOptionsPreset = {
  232. ...getDefaultOptions(),
  233. inputFileName: 'foo.map.js'
  234. };
  235. });
  236. it('should normalize options preset', () => {
  237. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  238. });
  239. });
  240. describe('Variant #4: no file name', () => {
  241. before(() => {
  242. optionsPreset = getNormalizedOptions({
  243. ...getDefaultOptions(),
  244. inputFileName: ''
  245. });
  246. expectedOptionsPreset = {
  247. ...getDefaultOptions(),
  248. inputFileName: ''
  249. };
  250. });
  251. it('should normalize options preset', () => {
  252. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  253. });
  254. });
  255. describe('Variant #5: relative path', () => {
  256. before(() => {
  257. optionsPreset = getNormalizedOptions({
  258. ...getDefaultOptions(),
  259. inputFileName: 'baz/bar/foo.js'
  260. });
  261. expectedOptionsPreset = {
  262. ...getDefaultOptions(),
  263. inputFileName: 'baz/bar/foo.js'
  264. };
  265. });
  266. it('should normalize options preset', () => {
  267. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  268. });
  269. });
  270. });
  271. describe('identifierNamesCacheRule', () => {
  272. describe('Variant #1: all fields are exist with values', () => {
  273. before(() => {
  274. optionsPreset = getNormalizedOptions({
  275. ...getDefaultOptions(),
  276. identifierNamesCache: {
  277. globalIdentifiers: {
  278. foo: '_0x123456'
  279. },
  280. propertyIdentifiers: {
  281. bar: '_0x654321'
  282. }
  283. }
  284. });
  285. expectedOptionsPreset = {
  286. ...getDefaultOptions(),
  287. identifierNamesCache: {
  288. globalIdentifiers: {
  289. foo: '_0x123456'
  290. },
  291. propertyIdentifiers: {
  292. bar: '_0x654321'
  293. }
  294. }
  295. };
  296. });
  297. it('should not normalize options preset', () => {
  298. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  299. });
  300. });
  301. describe('Variant #2: some fields are exist with values', () => {
  302. before(() => {
  303. optionsPreset = getNormalizedOptions({
  304. ...getDefaultOptions(),
  305. identifierNamesCache: {
  306. globalIdentifiers: {
  307. foo: '_0x123456'
  308. },
  309. propertyIdentifiers: {}
  310. }
  311. });
  312. expectedOptionsPreset = {
  313. ...getDefaultOptions(),
  314. identifierNamesCache: {
  315. globalIdentifiers: {
  316. foo: '_0x123456'
  317. },
  318. propertyIdentifiers: {}
  319. }
  320. };
  321. });
  322. it('should not normalize options preset', () => {
  323. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  324. });
  325. });
  326. describe('Variant #3: all fields are exist with empty objects', () => {
  327. before(() => {
  328. optionsPreset = getNormalizedOptions({
  329. ...getDefaultOptions(),
  330. identifierNamesCache: {
  331. globalIdentifiers: {},
  332. propertyIdentifiers: {}
  333. }
  334. });
  335. expectedOptionsPreset = {
  336. ...getDefaultOptions(),
  337. identifierNamesCache: {
  338. globalIdentifiers: {},
  339. propertyIdentifiers: {}
  340. }
  341. };
  342. });
  343. it('should not normalize options preset', () => {
  344. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  345. });
  346. });
  347. describe('Variant #4: some fields are missing', () => {
  348. before(() => {
  349. optionsPreset = getNormalizedOptions({
  350. ...getDefaultOptions(),
  351. identifierNamesCache: {
  352. globalIdentifiers: {
  353. foo: '_0x123456'
  354. }
  355. }
  356. });
  357. expectedOptionsPreset = {
  358. ...getDefaultOptions(),
  359. identifierNamesCache: {
  360. globalIdentifiers: {
  361. foo: '_0x123456'
  362. },
  363. propertyIdentifiers: {}
  364. }
  365. };
  366. });
  367. it('should normalize options preset', () => {
  368. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  369. });
  370. });
  371. describe('Variant #5: all fields are missing', () => {
  372. before(() => {
  373. optionsPreset = getNormalizedOptions({
  374. ...getDefaultOptions(),
  375. identifierNamesCache: {}
  376. });
  377. expectedOptionsPreset = {
  378. ...getDefaultOptions(),
  379. identifierNamesCache: {
  380. globalIdentifiers: {},
  381. propertyIdentifiers: {}
  382. }
  383. };
  384. });
  385. it('should normalize options preset', () => {
  386. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  387. });
  388. });
  389. });
  390. describe('seedRule', () => {
  391. describe('Variant #1: seed value is string', () => {
  392. before(() => {
  393. optionsPreset = getNormalizedOptions({
  394. ...getDefaultOptions(),
  395. seed: 'abc'
  396. });
  397. expectedOptionsPreset = {
  398. ...getDefaultOptions(),
  399. seed: 'abc'
  400. };
  401. });
  402. it('should not normalize options preset', () => {
  403. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  404. });
  405. });
  406. describe('Variant #2: seed value is number', () => {
  407. before(() => {
  408. optionsPreset = getNormalizedOptions({
  409. ...getDefaultOptions(),
  410. seed: 123
  411. });
  412. expectedOptionsPreset = {
  413. ...getDefaultOptions(),
  414. seed: 123
  415. };
  416. });
  417. it('should normalize options preset', () => {
  418. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  419. });
  420. });
  421. describe('Variant #3: seed value is `0``', () => {
  422. let seedValue: number;
  423. before(() => {
  424. optionsPreset = getNormalizedOptions({
  425. ...getDefaultOptions(),
  426. seed: 0
  427. });
  428. seedValue = Number(optionsPreset.seed);
  429. });
  430. it('should normalize seed value', () => {
  431. assert.isAtLeast(seedValue, 0);
  432. assert.isBelow(seedValue, 999_999_999);
  433. });
  434. });
  435. });
  436. describe('selfDefendingRule', () => {
  437. before(() => {
  438. optionsPreset = getNormalizedOptions({
  439. ...getDefaultOptions(),
  440. selfDefending: true,
  441. compact: false
  442. });
  443. expectedOptionsPreset = {
  444. ...getDefaultOptions(),
  445. selfDefending: true,
  446. compact: true
  447. };
  448. });
  449. it('should normalize options preset', () => {
  450. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  451. });
  452. });
  453. describe('sourceMapBaseUrlRule', () => {
  454. describe('Variant #1: only source map base url', () => {
  455. before(() => {
  456. optionsPreset = getNormalizedOptions({
  457. ...getDefaultOptions(),
  458. sourceMapBaseUrl: 'http://localhost:9000',
  459. });
  460. expectedOptionsPreset = {
  461. ...getDefaultOptions(),
  462. sourceMapBaseUrl: ''
  463. };
  464. });
  465. it('should normalize options preset', () => {
  466. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  467. });
  468. });
  469. describe('Variant #2: source map base url with source map file name', () => {
  470. before(() => {
  471. optionsPreset = getNormalizedOptions({
  472. ...getDefaultOptions(),
  473. sourceMapBaseUrl: 'http://localhost:9000',
  474. sourceMapFileName: '/outputSourceMapName.map'
  475. });
  476. expectedOptionsPreset = {
  477. ...getDefaultOptions(),
  478. sourceMapBaseUrl: 'http://localhost:9000/',
  479. sourceMapFileName: 'outputSourceMapName.js.map'
  480. };
  481. });
  482. it('should normalize options preset', () => {
  483. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  484. });
  485. });
  486. });
  487. describe('sourceMapFileNameRule', () => {
  488. describe('Base filename without extension', () => {
  489. before(() => {
  490. optionsPreset = getNormalizedOptions({
  491. ...getDefaultOptions(),
  492. sourceMapBaseUrl: 'http://localhost:9000',
  493. sourceMapFileName: 'outputSourceMapName'
  494. });
  495. expectedOptionsPreset = {
  496. ...getDefaultOptions(),
  497. sourceMapBaseUrl: 'http://localhost:9000/',
  498. sourceMapFileName: 'outputSourceMapName.js.map'
  499. };
  500. });
  501. it('should normalize options preset', () => {
  502. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  503. });
  504. });
  505. describe('Slashes in file name', () => {
  506. before(() => {
  507. optionsPreset = getNormalizedOptions({
  508. ...getDefaultOptions(),
  509. sourceMapBaseUrl: 'http://localhost:9000',
  510. sourceMapFileName: '//outputSourceMapName'
  511. });
  512. expectedOptionsPreset = {
  513. ...getDefaultOptions(),
  514. sourceMapBaseUrl: 'http://localhost:9000/',
  515. sourceMapFileName: 'outputSourceMapName.js.map'
  516. };
  517. });
  518. it('should normalize options preset', () => {
  519. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  520. });
  521. });
  522. describe('`js` file extension in file name', () => {
  523. before(() => {
  524. optionsPreset = getNormalizedOptions({
  525. ...getDefaultOptions(),
  526. sourceMapBaseUrl: 'http://localhost:9000',
  527. sourceMapFileName: 'outputSourceMapName.js'
  528. });
  529. expectedOptionsPreset = {
  530. ...getDefaultOptions(),
  531. sourceMapBaseUrl: 'http://localhost:9000/',
  532. sourceMapFileName: 'outputSourceMapName.js.map'
  533. };
  534. });
  535. it('should normalize options preset', () => {
  536. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  537. });
  538. });
  539. describe('Non `js` file extension in file name', () => {
  540. before(() => {
  541. optionsPreset = getNormalizedOptions({
  542. ...getDefaultOptions(),
  543. sourceMapBaseUrl: 'http://localhost:9000',
  544. sourceMapFileName: 'outputSourceMapName.exe'
  545. });
  546. expectedOptionsPreset = {
  547. ...getDefaultOptions(),
  548. sourceMapBaseUrl: 'http://localhost:9000/',
  549. sourceMapFileName: 'outputSourceMapName.js.map'
  550. };
  551. });
  552. it('should normalize options preset', () => {
  553. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  554. });
  555. });
  556. describe('File hash in file name', () => {
  557. before(() => {
  558. optionsPreset = getNormalizedOptions({
  559. ...getDefaultOptions(),
  560. sourceMapBaseUrl: 'http://localhost:9000',
  561. sourceMapFileName: 'outputSourceMapName.7e2c49a622975ebd9b7e'
  562. });
  563. expectedOptionsPreset = {
  564. ...getDefaultOptions(),
  565. sourceMapBaseUrl: 'http://localhost:9000/',
  566. sourceMapFileName: 'outputSourceMapName.7e2c49a622975ebd9b7e.js.map'
  567. };
  568. });
  569. it('should normalize options preset', () => {
  570. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  571. });
  572. });
  573. describe('File hash and `js` file extension in file name #1', () => {
  574. before(() => {
  575. optionsPreset = getNormalizedOptions({
  576. ...getDefaultOptions(),
  577. sourceMapBaseUrl: 'http://localhost:9000',
  578. sourceMapFileName: 'outputSourceMapName.7e2c49a622975ebd9b7e.js'
  579. });
  580. expectedOptionsPreset = {
  581. ...getDefaultOptions(),
  582. sourceMapBaseUrl: 'http://localhost:9000/',
  583. sourceMapFileName: 'outputSourceMapName.7e2c49a622975ebd9b7e.js.map'
  584. };
  585. });
  586. it('should normalize options preset', () => {
  587. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  588. });
  589. });
  590. describe('File hash and non `js` file extension in file name', () => {
  591. before(() => {
  592. optionsPreset = getNormalizedOptions({
  593. ...getDefaultOptions(),
  594. sourceMapBaseUrl: 'http://localhost:9000',
  595. sourceMapFileName: 'outputSourceMapName.7e2c49a622975ebd9b7e.exe'
  596. });
  597. expectedOptionsPreset = {
  598. ...getDefaultOptions(),
  599. sourceMapBaseUrl: 'http://localhost:9000/',
  600. sourceMapFileName: 'outputSourceMapName.7e2c49a622975ebd9b7e.js.map'
  601. };
  602. });
  603. it('should normalize options preset', () => {
  604. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  605. });
  606. });
  607. });
  608. describe('splitStringsChunkLengthRule', () => {
  609. describe('`splitStringsChunkLengthRule` value is float number', () => {
  610. before(() => {
  611. optionsPreset = getNormalizedOptions({
  612. ...getDefaultOptions(),
  613. splitStrings: true,
  614. splitStringsChunkLength: 5.6
  615. });
  616. expectedOptionsPreset = {
  617. ...getDefaultOptions(),
  618. splitStrings: true,
  619. splitStringsChunkLength: 5
  620. };
  621. });
  622. it('should normalize options preset', () => {
  623. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  624. });
  625. });
  626. });
  627. describe('stringArrayRule', () => {
  628. before(() => {
  629. optionsPreset = getNormalizedOptions({
  630. ...getDefaultOptions(),
  631. shuffleStringArray: true,
  632. stringArray: false,
  633. stringArrayEncoding: [StringArrayEncoding.Rc4],
  634. stringArrayIndexShift: true,
  635. stringArrayWrappersChainedCalls: true,
  636. stringArrayWrappersCount: 5,
  637. stringArrayThreshold: 0.5,
  638. rotateStringArray: true
  639. });
  640. expectedOptionsPreset = {
  641. ...getDefaultOptions(),
  642. shuffleStringArray: false,
  643. stringArray: false,
  644. stringArrayEncoding: [StringArrayEncoding.None],
  645. stringArrayIndexShift: false,
  646. stringArrayWrappersChainedCalls: false,
  647. stringArrayWrappersCount: 0,
  648. stringArrayThreshold: 0,
  649. rotateStringArray: false
  650. };
  651. });
  652. it('should normalize options preset', () => {
  653. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  654. });
  655. });
  656. describe('stringArrayEncodingRule', () => {
  657. before(() => {
  658. optionsPreset = getNormalizedOptions({
  659. ...getDefaultOptions(),
  660. stringArrayEncoding: []
  661. });
  662. expectedOptionsPreset = {
  663. ...getDefaultOptions(),
  664. stringArrayEncoding: [
  665. StringArrayEncoding.None
  666. ]
  667. };
  668. });
  669. it('should normalize options preset', () => {
  670. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  671. });
  672. });
  673. describe('stringArrayWrappersChainedCallsRule', () => {
  674. before(() => {
  675. optionsPreset = getNormalizedOptions({
  676. ...getDefaultOptions(),
  677. stringArrayWrappersChainedCalls: true,
  678. stringArrayWrappersCount: 0
  679. });
  680. expectedOptionsPreset = {
  681. ...getDefaultOptions(),
  682. stringArrayWrappersChainedCalls: false,
  683. stringArrayWrappersCount: 0
  684. };
  685. });
  686. it('should normalize options preset', () => {
  687. assert.deepEqual(optionsPreset, expectedOptionsPreset);
  688. });
  689. });
  690. });
  691. });