Options.spec.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import 'reflect-metadata';
  2. import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
  3. import { assert, use } from 'chai';
  4. import chaiExclude from 'chai-exclude';
  5. import { TInputOptions } from '../../../src/types/options/TInputOptions';
  6. import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
  7. import { IOptions } from '../../../src/interfaces/options/IOptions';
  8. import { OptionsPreset } from '../../../src/enums/options/presets/OptionsPreset';
  9. import { DEFAULT_PRESET } from '../../../src/options/presets/Default';
  10. import { LOW_OBFUSCATION_PRESET } from '../../../src/options/presets/LowObfuscation';
  11. import { MEDIUM_OBFUSCATION_PRESET } from '../../../src/options/presets/MediumObfuscation';
  12. import { HIGH_OBFUSCATION_PRESET } from '../../../src/options/presets/HighObfuscation';
  13. import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
  14. use(chaiExclude);
  15. /**
  16. * @param {TInputOptions} inputOptions
  17. */
  18. function getOptions (inputOptions: TInputOptions): IOptions {
  19. const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
  20. inversifyContainerFacade.load('', '', inputOptions);
  21. return inversifyContainerFacade
  22. .get<IOptions>(ServiceIdentifiers.IOptions);
  23. }
  24. describe('Options', () => {
  25. describe('Options preset', () => {
  26. let options: IOptions,
  27. expectedOptions: TInputOptions;
  28. describe('Preset selection', () => {
  29. describe('Default preset', () => {
  30. before(() => {
  31. options = getOptions({
  32. optionsPreset: OptionsPreset.Default
  33. });
  34. expectedOptions = DEFAULT_PRESET;
  35. });
  36. it('should return correct options preset', () => {
  37. assert.deepEqualExcluding<IOptions | TInputOptions>(options, expectedOptions, 'seed');
  38. });
  39. });
  40. describe('Low obfuscation preset', () => {
  41. before(() => {
  42. options = getOptions({
  43. optionsPreset: OptionsPreset.LowObfuscation
  44. });
  45. expectedOptions = LOW_OBFUSCATION_PRESET;
  46. });
  47. it('should return correct options preset', () => {
  48. assert.deepEqualExcluding<IOptions | TInputOptions>(options, expectedOptions, 'seed');
  49. });
  50. });
  51. describe('Medium obfuscation preset', () => {
  52. before(() => {
  53. options = getOptions({
  54. optionsPreset: OptionsPreset.MediumObfuscation
  55. });
  56. expectedOptions = MEDIUM_OBFUSCATION_PRESET;
  57. });
  58. it('should return correct options preset', () => {
  59. assert.deepEqualExcluding<IOptions | TInputOptions>(options, expectedOptions, 'seed');
  60. });
  61. });
  62. describe('High obfuscation preset', () => {
  63. before(() => {
  64. options = getOptions({
  65. optionsPreset: OptionsPreset.HighObfuscation
  66. });
  67. expectedOptions = HIGH_OBFUSCATION_PRESET;
  68. });
  69. it('should return correct options preset', () => {
  70. assert.deepEqualExcluding<IOptions | TInputOptions>(options, expectedOptions, 'seed');
  71. });
  72. });
  73. });
  74. describe('Input options merge with preset', () => {
  75. before(() => {
  76. options = getOptions({
  77. optionsPreset: OptionsPreset.HighObfuscation,
  78. numbersToExpressions: false
  79. });
  80. expectedOptions = {
  81. ...HIGH_OBFUSCATION_PRESET,
  82. numbersToExpressions: false
  83. };
  84. });
  85. it('should return merge input options with options preset', () => {
  86. assert.deepEqualExcluding<IOptions | TInputOptions>(options, expectedOptions, 'seed');
  87. });
  88. });
  89. });
  90. });