8000 Slightly changed tests structure · sec-js/javascript-obfuscator@0014173 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0014173

Browse files
author
sanex3339
committed
Slightly changed tests structure
1 parent f67b619 commit 0014173

File tree

11 files changed

+366
-356
lines changed

11 files changed

+366
-356
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { assert } from 'chai';
2+
3+
import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade';
4+
5+
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
6+
7+
import { ObfuscationTarget } from '../../../../src/enums/ObfuscationTarget';
8+
9+
describe('`domainLock` validation', () => {
10+
describe('IsAllowedForObfuscationTarget', () => {
11+
describe('Variant #1: positive validation', () => {
12+
describe('Variant #1: obfuscation target: `browser`', () => {
13+
let testFunc: () => string;
14+
15+
beforeEach(() => {
16+
testFunc = () => JavaScriptObfuscator.obfuscate(
17+
'',
18+
{
19+
...NO_ADDITIONAL_NODES_PRESET,
20+
domainLock: ['www.example.com'],
21+
target: ObfuscationTarget.Browser
22+
}
23+
).getObfuscatedCode();
24+
});
25+
26+
it('should pass validation when obfuscation target is `browser`', () => {
27+
assert.doesNotThrow(testFunc);
28+
});
29+
});
30+
31+
describe('Variant #2: obfuscation target: `node` and default value', () => {
32+
let testFunc: () => string;
33+
34+
beforeEach(() => {
35+
testFunc = () => JavaScriptObfuscator.obfuscate(
36+
'',
37+
{
38+
...NO_ADDITIONAL_NODES_PRESET,
39+
domainLock: [],
40+
target: ObfuscationTarget.Node
41+
}
42+
).getObfuscatedCode();
43+
});
44+
45+
it('should pass validation when obfuscation target is `node` and value is default', () => {
46+
assert.doesNotThrow(testFunc);
47+
});
48+
});
49+
});
50+
51+
describe('Variant #2: negative validation', () => {
52+
const expectedError: string = 'This option allowed only for obfuscation targets';
53+
54+
let testFunc: () => string;
55+
56+
beforeEach(() => {
57+
testFunc = () => JavaScriptObfuscator.obfuscate(
58+
'',
59+
{
60+
...NO_ADDITIONAL_NODES_PRESET,
61+
domainLock: ['www.example.com'],
62+
target: ObfuscationTarget.Node
63+
}
64+
).getObfuscatedCode();
65+
});
66+
67+
it('should not pass validation when obfuscation target is `node` and value is not default', () => {
68+
assert.throws(testFunc, expectedError);
69+
});
70+
});
71+
});
72+
});

test/functional-tests/options/domain-lock/validators/IsAllowedForObfuscationTarget.spec.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { assert } from 'chai';
2+
3+
import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade';
4+
5+
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
6+
7+
import { ObfuscationTarget } from '../../../../src/enums/ObfuscationTarget';
8+
9+
describe('`sourceMapBaseUrl` validation', () => {
10+
describe('IsAllowedForObfuscationTarget', () => {
11+
describe('Variant #1: positive validation', () => {
12+
describe('Variant #1: obfuscation target: `browser`', () => {
13+
let testFunc: () => string;
14+
15+
beforeEach(() => {
16+
testFunc = () => JavaScriptObfuscator.obfuscate(
17+
'',
18+
{
19+
...NO_ADDITIONAL_NODES_PRESET,
20+
sourceMapBaseUrl: 'http://www.example.com',
21+
target: ObfuscationTarget.Browser
22+
}
23+
).getObfuscatedCode();
24+
});
25+
26+
it('should pass validation when obfuscation target is `browser`', () => {
27+
assert.doesNotThrow(testFunc);
28+
});
29+
});
30+
31+
describe('Variant #2: obfuscation target: `node` and default value', () => {
32+
let testFunc: () => string;
33+
34+
beforeEach(() => {
35+
testFunc = () => JavaScriptObfuscator.obfuscate(
36+
'',
37+
{
38+
...NO_ADDITIONAL_NODES_PRESET,
39+
sourceMapBaseUrl: '',
40+
target: ObfuscationTarget.Node
41+
}
42+
).getObfuscatedCode();
43+
});
44+
45+
it('should pass validation when obfuscation target is `node` and value is default', () => {
46+
assert.doesNotThrow(testFunc);
47+
});
48+
});
49+
});
50+
51+
describe('Variant #2: negative validation', () => {
52+
const expectedError: string = 'This option allowed only for obfuscation targets';
53+
54+
let testFunc: () => string;
55+
56+
beforeEach(() => {
57+
testFunc = () => JavaScriptObfuscator.obfuscate(
58+
'',
59+
{
60+
...NO_ADDITIONAL_NODES_PRESET,
61+
sourceMapBaseUrl: 'http://www.example.com',
62+
target: ObfuscationTarget.Node
63+
}
64+
).getObfuscatedCode();
65+
});
66+
67+
it('should not pass validation when obfuscation target is `node` and value is not default', () => {
68+
assert.throws(testFunc, expectedError);
69+
});
70+
});
71+
});
72+
});

test/functional-tests/options/source-map-base-url/validators/IsAllowedForObfuscationTarget.spec.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { assert } from 'chai';
2+
3+
import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade';
4+
5+
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
6+
7+
import { ObfuscationTarget } from '../../../../src/enums/ObfuscationTarget';
8+
9+
describe('`sourceMapFileName` validation', () => {
10+
describe('IsAllowedForObfuscationTarget', () => {
11+
describe('Variant #1: positive validation', () => {
12+
describe('Variant #1: obfuscation target: `browser`', () => {
13+
let testFunc: () => string;
14+
15+
beforeEach(() => {
16+
testFunc = () => JavaScriptObfuscator.obfuscate(
17+
'',
18+
{
19+
...NO_ADDITIONAL_NODES_PRESET,
20+
sourceMapFileName: 'foo',
21+
target: ObfuscationTarget.Browser
22+
}
23+
).getObfuscatedCode();
24+
});
25+
26+
it('should pass validation when obfuscation target is `browser`', () => {
27+
assert.doesNotThrow(testFunc);
28+
});
29+
});
30+
31+
describe('Variant #2: obfuscation target: `node` and default value', () => {
32+
let testFunc: () => string;
33+
34+
beforeEach(() => {
35+
testFunc = () => JavaScriptObfuscator.obfuscate(
36+
'',
37+
{
38+
...NO_ADDITIONAL_NODES_PRESET,
39+
sourceMapFileName: '',
40+
target: ObfuscationTarget.Node
41+
}
42+
).getObfuscatedCode();
43+
});
44+
45+
it('should pass validation when obfuscation target is `node` and value is default', () => {
46+
assert.doesNotThrow(testFunc);
47+
});
48+
});
49+
});
50+
51+
describe('Variant #2: negative validation', () => {
52+
const expectedError: string = 'This option allowed only for obfuscation targets';
53+
54+
let testFunc: () => string;
55+
56+
beforeEach(() => {
57+
testFunc = () => JavaScriptObfuscator.obfuscate(
58+
'',
59+
{
60+
...NO_ADDITIONAL_NODES_PRESET,
61+
sourceMapFileName: 'foo',
62+
target: ObfuscationTarget.Node
63+
}
64+
).getObfuscatedCode();
65+
});
66+
67+
it('should not pass validation when obfuscation target is `node` and value is not default', () => {
68+
assert.throws(testFunc, expectedError);
69+
});
70+
});
71+
});
72+
});

0 commit comments

Comments
 (0)
0