Debian Codegraph @

test/instrumentation/test-misc.js

raw
1 /*jslint nomen: true */
2 var Instrumenter = require('../../lib/instrumenter'),
3 esprima = require('esprima'),
4 instrumenter;
5
6 module.exports = {
7 "missing type attributes": {
8 setUp: function (cb) {
9 instrumenter = new Instrumenter();
10 cb();
11 },
12 "barfs when a type attr is missing for a general node": function (test) {
13 var ast = esprima.parse('var foo = 1;', { loc: true });
14 delete ast.body[0].type;
15 try {
16 instrumenter.instrumentASTSync(ast);
17 test.fail('instrumentation succeeded when it should not have');
18 } catch (ex) {
19 //ok
20 }
21 test.done();
22 },
23 "but succeeds when a property node in an AST does not have the type attr": function (test) {
24 var ast = esprima.parse('var foo = { a: 1 };', { loc: true });
25 delete ast.body[0].declarations[0].init.properties[0].type;
26 try {
27 instrumenter.instrumentASTSync(ast);
28 } catch (ex) {
29 test.fail('instrumentation should have succeeded but did not');
30 }
31 test.done();
32 }
33 },
34 "sourcemap generation": {
35 setUp: function (cb) {
36 instrumenter = new Instrumenter();
37 cb();
38 },
39 "lastSourceMap returns sourcemap (if available) for last instrumented file": function (test) {
40 var instrumenterOpts = instrumenter.opts.codegenerationoptions;
41 instrumenter.opts.codegenerationoptions = {
42 sourceMap: 'bar',
43 sourceMapWithCode: true
44 };
45 try {
46 instrumenter.instrumentSync('var foo = { a: 1 };');
47 if (typeof instrumenter.lastSourceMap() !== 'object') {
48 test.fail('sourcemap should be available');
49 }
50
51 instrumenter.opts.codegenerationoptions = instrumenterOpts;
52 instrumenter.instrumentSync('var foo = { a: 1 };');
53 if (instrumenter.lastSourceMap() !== null) {
54 test.fail('sourcemap should not be available');
55 }
56 } catch (ex) {
57 test.fail('instrumentation should have succeeded but did not');
58 }
59 test.done();
60 }
61 }
62 };
63