forked from sindresorhus/strip-debug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
39 lines (34 loc) · 2.31 KB
/
test.js
File metadata and controls
39 lines (34 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
var assert = require('assert');
var stripDebug = require('./');
it('should strip debugger statement', function () {
assert.equal(stripDebug('function test(){debugger;}').toString(), 'function test(){}');
assert.equal(stripDebug('"use strict";debugger;foo()').toString(), '"use strict";foo()');
});
it('should strip console statement', function () {
assert.equal(stripDebug('function test(){console.log("foo");}').toString(), 'function test(){void 0;}');
assert.equal(stripDebug('function test(){window.console.log("foo");}').toString(), 'function test(){void 0;}');
assert.equal(stripDebug('var test = () => console.log("foo");').toString(), 'var test = () => void 0;');
assert.equal(stripDebug('"use strict";console.log("foo");foo()').toString(), '"use strict";void 0;foo()');
assert.equal(stripDebug('if(console){console.log("foo", "bar");}').toString(), 'if(console){void 0;}');
assert.equal(stripDebug('foo && console.log("foo");').toString(), 'foo && void 0;');
assert.equal(stripDebug('if (foo) console.log("foo")\nnextLine();').toString(), 'if (foo) void 0\nnextLine();');
});
it('should strip alert statement', function () {
assert.equal(stripDebug('function test(){alert("foo");}').toString(), 'function test(){void 0;}');
assert.equal(stripDebug('function test(){window.alert("foo");}').toString(), 'function test(){void 0;}');
assert.equal(stripDebug('var test = () => alert("foo");').toString(), 'var test = () => void 0;');
assert.equal(stripDebug('"use strict";alert("foo");foo()').toString(), '"use strict";void 0;foo()');
assert.equal(stripDebug('if(alert){alert("foo", "bar");}').toString(), 'if(alert){void 0;}');
assert.equal(stripDebug('foo && alert("foo");').toString(), 'foo && void 0;');
assert.equal(stripDebug('if (foo) alert("foo")\nnextLine();').toString(), 'if (foo) void 0\nnextLine();');
});
it('should never strip away non-debugging code', function () {
var t = 'var test = {\n getReadSections: function(){\n var readSections = window.localStorage.getItem(\'storyReadSections\') || \'[]\';\n return JSON.parse(readSections);\n }\n};';
assert.equal(stripDebug(t).toString(), t);
});
it('shouldn\'t leak memory', function () {
assert.doesNotThrow(function () {
stripDebug('var obj = null; try { obj = \'something\'; } catch (e) { console.warn(\'NOPE!\'); }').toString();
});
});