Debian Codegraph @

test/instrumentation/test-strict.js

raw
1 /*jslint nomen: true */
2 var helper = require('../helper'),
3 code,
4 verifier;
5
6 module.exports = {
7 "with a function expression that uses strict": {
8 setUp: function (cb) {
9 code = [
10 '(function () {',
11 ' "use strict";',
12 ' var x = Object.freeze({ foo: 1 });',
13 ' try {',
14 ' x.foo = 2;',
15 ' output = "fail";',
16 ' } catch (ex) {',
17 ' output = "pass";',
18 ' }',
19 '}());'
20 ];
21 verifier = helper.verifier(__filename, code);
22 cb();
23 },
24
25 "should cover one statement less": function (test) {
26 verifier.verify(test, [], "pass", {
27 statements: { 1: 1, 2: 1, 3: 1, 4: 1, 5: 0, 6: 1 },
28 lines: { 1: 1, 3: 1, 4: 1, 5: 1, 6: 0, 8: 1 },
29 branches: {},
30 functions: { 1: 1}
31 });
32 test.done();
33 }
34 },
35 "with a function declaration that uses strict": {
36 setUp: function (cb) {
37 code = [
38 'function foo() {',
39 ' "use strict";',
40 ' var x = Object.freeze({ foo: 1 });',
41 ' try {',
42 ' x.foo = 2;',
43 ' output = "fail";',
44 ' } catch (ex) {',
45 ' output = "pass";',
46 ' }',
47 '}',
48 'foo();'
49 ];
50 verifier = helper.verifier(__filename, code);
51 cb();
52 },
53
54 "should cover one statement less": function (test) {
55 verifier.verify(test, [], "pass", {
56 statements: { 1: 1, 2: 1, 3: 1, 4: 1, 5: 0, 6: 1, 7: 1 },
57 lines: { 1: 1, 3: 1, 4: 1, 5: 1, 6: 0, 8: 1, 11: 1 },
58 branches: {},
59 functions: { 1: 1}
60 });
61 test.done();
62 }
63 },
64 "with a function declaration that looks like strict but is not": {
65 setUp: function (cb) {
66 code = [
67 'function foo() {',
68 ' 1;',
69 ' "use strict";',
70 ' var x = Object.freeze({ foo: 1 });',
71 ' try {',
72 ' x.foo = 2;',
73 ' output = "fail";',
74 ' } catch (ex) {',
75 ' output = "pass";',
76 ' }',
77 '}',
78 'foo();'
79 ];
80 verifier = helper.verifier(__filename, code);
81 cb();
82 },
83
84 "should cover all statements as usual": function (test) {
85 verifier.verify(test, [], "fail", {
86 statements: { 1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 0, 9: 1 },
87 lines: { 1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 9: 0, 12: 1 },
88 branches: {},
89 functions: { 1: 1}
90 });
91 test.done();
92 }
93 },
94 "with a file-level strict declaration": {
95 setUp: function (cb) {
96 code = [
97 ' "use strict";',
98 ' var x = Object.freeze({ foo: 1 });',
99 ' try {',
100 ' x.foo = 2;',
101 ' output = "fail";',
102 ' } catch (ex) {',
103 ' output = "pass";',
104 ' }'
105 ];
106 verifier = helper.verifier(__filename, code);
107 cb();
108 },
109
110 "should correctly interpret the strict statement": function (test) {
111 // use strict semantics still do not work since it is not top-level but called from vm.runInThisContext
112 verifier.verify(test, [], "fail", {
113 //however statements and lines should line up
114 statements: { 1: 1, 2: 1, 3: 1, 4: 1, 5: 0 },
115 lines: { 2: 1, 3: 1, 4: 1, 5: 1, 7: 0 },
116 branches: {},
117 functions: {}
118 });
119 test.done();
120 }
121 }
122 };
123