1
1
import JsConfuser from "../../../src/index" ;
2
2
3
- it ( "should extract properties", async ( ) => {
3
+ test ( "Variant #1: Extract properties", async ( ) => {
4
4
var code = `
5
5
var TEST_OBJECT = {
6
6
TEST_1: "Hello World",
@@ -34,7 +34,7 @@ it("should extract properties", async () => {
34
34
eval ( output ) ;
35
35
} ) ;
36
36
37
- it ( "should extract function properties correctly", async ( ) => {
37
+ test ( "Variant #2: Extract function properties correctly", async ( ) => {
38
38
var code = `
39
39
var TEST_OBJECT = {
40
40
isBoolean: x=>typeof x === "boolean",
@@ -68,7 +68,7 @@ it("should extract function properties correctly", async () => {
68
68
eval ( output ) ;
69
69
} ) ;
70
70
71
- it ( "should not extract properties on with dynamically added keys", async ( ) => {
71
+ test ( "Variant #3: Not extract properties on with dynamically added keys", async ( ) => {
72
72
var code = `
73
73
var TEST_OBJECT = {
74
74
first_key: 1
@@ -100,7 +100,7 @@ it("should not extract properties on with dynamically added keys", async () => {
100
100
eval ( output ) ;
101
101
} ) ;
102
102
103
- it ( "should not extract properties on with dynamically added keys even when in nested contexts", async ( ) => {
103
+ test ( "Variant #4: Not extract properties on with dynamically added keys even when in nested contexts", async ( ) => {
104
104
var code = `
105
105
var TEST_OBJECT = {
106
106
first_key: 1
@@ -135,7 +135,7 @@ it("should not extract properties on with dynamically added keys even when in ne
135
135
eval ( output ) ;
136
136
} ) ;
137
137
138
- it ( "should not extract properties on objects with computed properties", async ( ) => {
138
+ test ( "Variant #5: Not extract properties on objects with computed properties", async ( ) => {
139
139
var code = `
140
140
141
141
var key = "111"
@@ -166,7 +166,7 @@ it("should not extract properties on objects with computed properties", async ()
166
166
eval ( output ) ;
167
167
} ) ;
168
168
169
- it ( "should not extract properties on objects with computed properties (string)", async ( ) => {
169
+ test ( "Variant #6: Not extract properties on objects with computed properties (string)", async ( ) => {
170
170
var code = `
171
171
172
172
var v = "key";
@@ -197,7 +197,7 @@ it("should not extract properties on objects with computed properties (string)",
197
197
eval ( output ) ;
198
198
} ) ;
199
199
200
- it ( "should not extract properties on objects when the object is referenced independently", async ( ) => {
200
+ test ( "Variant #7: Not extract properties on objects when the object is referenced independently", async ( ) => {
201
201
var code = `
202
202
203
203
var TEST_OBJECT = {
@@ -229,7 +229,7 @@ it("should not extract properties on objects when the object is referenced indep
229
229
eval ( output ) ;
230
230
} ) ;
231
231
232
- it ( "should not extract properties on objects when the variable gets redefined", async ( ) => {
232
+ test ( "Variant #8: Not extract properties on objects when the variable gets redefined", async ( ) => {
233
233
var code = `
234
234
235
235
var TEST_OBJECT = {
@@ -260,7 +260,7 @@ it("should not extract properties on objects when the variable gets redefined",
260
260
eval ( output ) ;
261
261
} ) ;
262
262
263
- it ( "should not extract properties on objects when the variable gets reassigned", async ( ) => {
263
+ test ( "Variant #9: Not extract properties on objects when the variable gets reassigned", async ( ) => {
264
264
var code = `
265
265
266
266
var TEST_OBJECT = {
@@ -292,7 +292,7 @@ it("should not extract properties on objects when the variable gets reassigned",
292
292
eval ( output ) ;
293
293
} ) ;
294
294
295
- it ( "should not extract properties on objects with methods referencing 'this'", async ( ) => {
295
+ test ( "Variant #10: Not extract properties on objects with methods referencing 'this'", async ( ) => {
296
296
var code = `
297
297
298
298
var TEST_OBJECT = {
@@ -325,7 +325,7 @@ it("should not extract properties on objects with methods referencing 'this'", a
325
325
eval ( output ) ;
326
326
} ) ;
327
327
328
- it ( "should not extract properties on objects when properties are dynamically deleted", async ( ) => {
328
+ test ( "Variant #11: Not extract properties on objects when properties are dynamically deleted", async ( ) => {
329
329
var code = `
330
330
331
331
var TEST_OBJECT = {
@@ -356,7 +356,7 @@ it("should not extract properties on objects when properties are dynamically del
356
356
eval ( output ) ;
357
357
} ) ;
358
358
359
- it ( "should not extract properties on objects with computed accessors", async ( ) => {
359
+ test ( "Variant #12: Not extract properties on objects with computed accessors", async ( ) => {
360
360
var code = `
361
361
362
362
var TEST_OBJECT = {
@@ -388,7 +388,7 @@ it("should not extract properties on objects with computed accessors", async ()
388
388
eval ( output ) ;
389
389
} ) ;
390
390
391
- it ( "should properly use custom callback to exclude certain names from being changed", async ( ) => {
391
+ test ( "Variant #13: Properly use custom callback to exclude certain names from being changed", async ( ) => {
392
392
var code = `
393
393
394
394
var TEST_OBJECT = {
@@ -424,7 +424,7 @@ it("should properly use custom callback to exclude certain names from being chan
424
424
eval ( output ) ;
425
425
} ) ;
426
426
427
- it ( "should not apply to objects with non-init properties (method, set, get)", async ( ) => {
427
+ test ( "Variant #14: Not apply to objects with non-init properties (method, set, get)", async ( ) => {
428
428
var code = `
429
429
430
430
var realValue = 0;
@@ -448,7 +448,7 @@ it("should not apply to objects with non-init properties (method, set, get)", as
448
448
} ) ;
449
449
450
450
// https://github.com/MichaelXF/js-confuser/issues/78
451
- it ( "should handle objects with spread elements", async ( ) => {
451
+ test ( "Variant #15: Handle objects with spread elements", async ( ) => {
452
452
var output = await JsConfuser (
453
453
`
454
454
var x = { firstName: "John", lastName: "Doe" }
@@ -467,3 +467,23 @@ it("should handle objects with spread elements", async () => {
467
467
468
468
expect ( TEST_OUTPUT ) . toStrictEqual ( { firstName : "John" , lastName : "Doe" } ) ;
469
469
} ) ;
470
+
471
+ // https://github.com/MichaelXF/js-confuser/issues/106
472
+ test ( "Variant #16: Handle const declarations" , async ( ) => {
473
+ var output = await JsConfuser (
474
+ `
475
+ const obj = {prop: 0};
476
+ obj.prop = 1;
477
+ TEST_OUTPUT = obj.prop;
478
+ ` ,
479
+ {
480
+ target : "node" ,
481
+ objectExtraction : true ,
482
+ }
483
+ ) ;
484
+
485
+ var TEST_OUTPUT ;
486
+ eval ( output ) ;
487
+
488
+ expect ( TEST_OUTPUT ) . toStrictEqual ( 1 ) ;
489
+ } ) ;
0 commit comments