-
Notifications
You must be signed in to change notification settings - Fork 65
/
inspectPrimordialAssignments.spec.js
84 lines (73 loc) · 2.35 KB
/
inspectPrimordialAssignments.spec.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const test = require('ava')
const { parse, inspectPrimordialAssignments } = require('../src/index')
function inspectPrimordialAssignmentsTest(code) {
return inspectPrimordialAssignments(parse(code))
}
test('inspectPrimordialAssignments - basic', (t) => {
const results = inspectPrimordialAssignmentsTest(`
'hello world'
`)
t.deepEqual(results, [])
})
test('inspectPrimordialAssignments - assignment to toString on prototype', (t) => {
const results = inspectPrimordialAssignmentsTest(`
MyClass.prototype.toString = () => 'hello'
`)
t.deepEqual(results, [])
})
test('inspectPrimordialAssignments - assignment to toString', (t) => {
const results = inspectPrimordialAssignmentsTest(`
exports.toString = () => 'hello'
`)
t.deepEqual(results, [])
})
test('inspectPrimordialAssignments - assignment to frozen primordial', (t) => {
const results = inspectPrimordialAssignmentsTest(`
Array.prototype.bogoSort = () => 'hello'
`)
t.is(results.length, 1)
})
test('inspectPrimordialAssignments - primordial potential false positive - instrinsic', (t) => {
const results = inspectPrimordialAssignmentsTest(`
window.Array === Array
`)
t.deepEqual(results, [])
})
test('inspectPrimordialAssignments - primordial potential false positive - keyword', (t) => {
const results = inspectPrimordialAssignmentsTest(`
const args = Array.prototype.slice.call(arguments)
`)
t.deepEqual(results, [])
})
test('inspectPrimordialAssignments - primordial modify property', (t) => {
const results = inspectPrimordialAssignmentsTest(`
Object.keys.extra = 'hello'
`)
t.is(results.length, 1)
})
test('inspectPrimordialAssignments - primordial Error modify property', (t) => {
const results = inspectPrimordialAssignmentsTest(`
Error.prepareStackTrace = () => {}
`)
t.is(results.length, 1)
})
test('inspectPrimordialAssignments - ensure shadowed references not counted - simple', (t) => {
const results = inspectPrimordialAssignmentsTest(`
function Promise () {}
Promise.all = () => {}
`)
t.is(results.length, 0)
})
test('inspectPrimordialAssignments - ensure shadowed references not counted - complex', (t) => {
const results = inspectPrimordialAssignmentsTest(`
Array.abc = true
;(function(){
const Array = {}
Array.xyz = true
;(function(){
Array.ijk = true
})()
})()
`)
t.is(results.length, 1)
})