browser_dbg-sourcemapped-preview.js (4319B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 "use strict"; 6 7 // Tests for preview through Babel's compile output. 8 requestLongerTimeout(3); 9 10 add_task(async function () { 11 await pushPref("devtools.debugger.map-scopes-enabled", true); 12 const dbg = await initDebugger("doc-sourcemapped.html"); 13 14 await testForOf(dbg); 15 await testShadowing(dbg); 16 await testImportedBindings(dbg); 17 }); 18 19 async function breakpointPreviews( 20 dbg, 21 target, 22 fixture, 23 { line, column }, 24 previews 25 ) { 26 const url = `${target}://./${fixture}/input.js`; 27 const fnName = `${target}-${fixture}`.replace(/-([a-z])/g, (s, c) => 28 c.toUpperCase() 29 ); 30 31 info(`Starting ${fixture} tests`); 32 33 await invokeWithBreakpoint(dbg, fnName, url, { line, column }, async () => { 34 await assertPreviews(dbg, previews); 35 }); 36 37 ok(true, `Ran tests for ${fixture} at line ${line} column ${column}`); 38 } 39 40 function testForOf(dbg) { 41 return breakpointPreviews( 42 dbg, 43 "webpack3-babel6", 44 "for-of", 45 { line: 5, column: 5 }, 46 [ 47 { 48 line: 5, 49 column: 4, 50 expression: "doThing", 51 result: "doThing(arg)", 52 }, 53 { 54 line: 5, 55 column: 13, 56 expression: "x", 57 result: "1", 58 }, 59 { 60 line: 8, 61 column: 12, 62 expression: "doThing", 63 result: "doThing(arg)", 64 }, 65 ] 66 ); 67 } 68 69 function testShadowing(dbg) { 70 return breakpointPreviews( 71 dbg, 72 "webpack3-babel6", 73 "shadowed-vars", 74 { line: 18, column: 7 }, 75 [ 76 // These aren't what the user would expect, but we test them anyway since 77 // they reflect what this actually returns. These shadowed bindings read 78 // the binding closest to the current frame's scope even though their 79 // actual value is different. 80 { 81 line: 2, 82 column: 10, 83 expression: "aVar", 84 result: '"var3"', 85 }, 86 { 87 line: 3, 88 column: 10, 89 expression: "aLet", 90 result: '"let3"', 91 }, 92 { 93 line: 4, 94 column: 12, 95 expression: "aConst", 96 result: '"const3"', 97 }, 98 { 99 line: 10, 100 column: 12, 101 expression: "aVar", 102 result: '"var3"', 103 }, 104 { 105 line: 11, 106 column: 12, 107 expression: "aLet", 108 result: '"let3"', 109 }, 110 { 111 line: 12, 112 column: 14, 113 expression: "aConst", 114 result: '"const3"', 115 }, 116 117 // These actually result in the values the user would expect. 118 { 119 line: 14, 120 column: 14, 121 expression: "aVar", 122 result: '"var3"', 123 }, 124 { 125 line: 15, 126 column: 14, 127 expression: "aLet", 128 result: '"let3"', 129 }, 130 { 131 line: 16, 132 column: 14, 133 expression: "aConst", 134 result: '"const3"', 135 }, 136 ] 137 ); 138 } 139 140 function testImportedBindings(dbg) { 141 return breakpointPreviews( 142 dbg, 143 "webpack3-babel6", 144 "esmodules-cjs", 145 { line: 20, column: 3 }, 146 [ 147 { 148 line: 20, 149 column: 17, 150 expression: "aDefault", 151 result: '"a-default"', 152 }, 153 { 154 line: 21, 155 column: 17, 156 expression: "anAliased", 157 result: '"an-original"', 158 }, 159 { 160 line: 22, 161 column: 17, 162 expression: "aNamed", 163 result: '"a-named"', 164 }, 165 { 166 line: 23, 167 column: 17, 168 expression: "anotherNamed", 169 result: '"a-named"', 170 }, 171 { 172 line: 24, 173 column: 17, 174 expression: "aNamespace", 175 fields: [ 176 ["aNamed", '"a-named"'], 177 ["default", '"a-default"'], 178 ], 179 }, 180 { 181 line: 29, 182 column: 21, 183 expression: "aDefault2", 184 result: '"a-default2"', 185 }, 186 { 187 line: 30, 188 column: 21, 189 expression: "anAliased2", 190 result: '"an-original2"', 191 }, 192 { 193 line: 31, 194 column: 21, 195 expression: "aNamed2", 196 result: '"a-named2"', 197 }, 198 { 199 line: 32, 200 column: 21, 201 expression: "anotherNamed2", 202 result: '"a-named2"', 203 }, 204 ] 205 ); 206 }