Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Add more variables tests for other scopes #855

Merged
merged 1 commit into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
253 changes: 248 additions & 5 deletions test/int/featureBasedSuits/variablesScopes.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { TestProjectSpec } from '../framework/frameworkTestSupport';
import { VariablesWizard } from '../wizards/variables/variablesWizard';
import { LaunchProject } from '../fixtures/launchProject';
Expand Down Expand Up @@ -43,4 +38,252 @@ suite('Variables scopes', function () {
xyz = 4 (number)`}
);
});

testUsing('globals', context => LaunchProject.create(context, TestProjectSpec.fromTestPath('variablesScopes/globalScope')), async (launchProject) => {
await launchProject.pausedWizard.waitUntilPausedOnDebuggerStatement();

await new VariablesWizard(launchProject.debugClient).assertNewGlobalVariariablesAre(async () => {
await launchProject.pausedWizard.resume();
await launchProject.pausedWizard.waitUntilPausedOnDebuggerStatement();
},
// The variables declared with const, and let aren't global variables so they won't appear here
`
b = body {text: "", link: "", vLink: "", …} (Object)
bool = true (boolean)
buffer = ArrayBuffer(8) {} (Object)
buffView = Int32Array(2) [234, 0] (Object)
consoleDotLog = function consoleDotLog(m) { … } (Function)
e = Error: hi (Object)
element = p {align: "", title: "", lang: "", …} (Object)
evalVar1 = 16 (number)
evalVar2 = "sdlfk" (string)
evalVar3 = Array(3) [1, 2, 3] (Object)
fn = () => { … } (Function)
fn2 = function () { … } (Function)
globalCode = "page loaded" (string)
i = 101 (number)
inf = Infinity (number)
infStr = "Infinity" (string)
longStr = "this is a\nstring with\nnewlines" (string)
m = Map(1) {} (Object)
manyPropsObj = Object {0: 1, 1: 3, 2: 5, …} (Object)
myVar = Object {num: 1, str: "Global", obj: Object, …} (Object)
nan = NaN (number)
obj = Object {a: 2, thing: <accessor>} (Object)
qqq = undefined (undefined)
r = /^asdf.*$/g {lastIndex: 0} (Object) // TODO: This and other types seems wrong. Investigate
s = Symbol(hi) (symbol)
str = "hello" (string)
xyz = 4 (number)`);
});

testUsing('script', context => LaunchProject.create(context, TestProjectSpec.fromTestPath('variablesScopes/scriptScope')), async (launchProject) => {
await launchProject.pausedWizard.waitUntilPausedOnDebuggerStatement();

await new VariablesWizard(launchProject.debugClient).assertTopFrameVariablesAre({
script: `
this = Window (Object)
b = body {text: "", link: "", vLink: "", …} (Object)
bool = true (boolean)
buffer = ArrayBuffer(8) {} (Object)
buffView = Int32Array(2) [234, 0] (Object)
e = Error: hi (Object)
element = body {text: "", link: "", vLink: "", …} (Object)
fn = () => { … } (Function)
fn2 = function () { … } (Function)
globalCode = "page loaded" (string)
inf = Infinity (number)
infStr = "Infinity" (string)
longStr = "this is a\nstring with\nnewlines" (string)
m = Map(1) {} (Object)
manyPropsObj = Object {0: 1, 1: 3, 2: 5, …} (Object)
myVar = Object {num: 1, str: "Global", obj: Object, …} (Object)
nan = NaN (number)
obj = Object {a: 2, thing: <accessor>} (Object)
qqq = undefined (undefined)
r = /^asdf.*$/g {lastIndex: 0} (Object)
s = Symbol(hi) (symbol)
str = "hello" (string)
xyz = 4 (number)`}
);
});

testUsing('block', context => LaunchProject.create(context, TestProjectSpec.fromTestPath('variablesScopes/blockScope')), async (launchProject) => {
await launchProject.pausedWizard.waitUntilPausedOnDebuggerStatement();

await new VariablesWizard(launchProject.debugClient).assertTopFrameVariablesAre(
{
block: `
this = Window (Object)
b = body {text: "", link: "", vLink: "", …} (Object)
bool = true (boolean)
buffer = ArrayBuffer(8) {} (Object)
buffView = Int32Array(2) [234, 0] (Object)
consoleDotLog = function consoleDotLog(m) { … } (Function)
e = Error: hi (Object)
element = body {text: "", link: "", vLink: "", …} (Object)
fn = () => { … } (Function)
fn2 = function () { … } (Function)
globalCode = "page loaded" (string)
inf = Infinity (number)
infStr = "Infinity" (string)
longStr = "this is a\nstring with\nnewlines" (string)
m = Map(1) {} (Object)
manyPropsObj = Object {0: 1, 1: 3, 2: 5, …} (Object)
myVar = Object {num: 1, str: "Global", obj: Object, …} (Object)
nan = NaN (number)
obj = Object {a: 2, thing: <accessor>} (Object)
qqq = undefined (undefined)
r = /^asdf.*$/g {lastIndex: 0} (Object)
s = Symbol(hi) (symbol)
str = "hello" (string)
xyz = 4 (number)`
}
);
});

testUsing('catch', context => LaunchProject.create(context, TestProjectSpec.fromTestPath('variablesScopes/catchScope')), async (launchProject) => {
await launchProject.pausedWizard.waitUntilPausedOnDebuggerStatement();

await new VariablesWizard(launchProject.debugClient).assertTopFrameVariablesAre({
catch: `
exception = Error: Something went wrong (Object)`}
);
});

testUsing('closure', context => LaunchProject.create(context, TestProjectSpec.fromTestPath('variablesScopes/closureScope')), async (launchProject) => {
await launchProject.pausedWizard.waitUntilPausedOnDebuggerStatement();

await new VariablesWizard(launchProject.debugClient).assertTopFrameVariablesAre({
closure: `
arguments = Arguments(0) [] (Object)
b = body {text: "", link: "", vLink: "", …} (Object)
bool = true (boolean)
buffer = ArrayBuffer(8) {} (Object)
buffView = Int32Array(2) [234, 0] (Object)
consoleDotLog = function consoleDotLog(m) { … } (Function)
e = Error: hi (Object)
element = body {text: "", link: "", vLink: "", …} (Object)
fn = () => { … } (Function)
fn2 = function () { … } (Function)
globalCode = "page loaded" (string)
inf = Infinity (number)
infStr = "Infinity" (string)
longStr = "this is a\nstring with\nnewlines" (string)
m = Map(1) {} (Object)
manyPropsObj = Object {0: 1, 1: 3, 2: 5, …} (Object)
myVar = Object {num: 1, str: "Global", obj: Object, …} (Object)
nan = NaN (number)
obj = Object {a: 2, thing: <accessor>} (Object)
pauseInside = function pauseInside() { … } (Function)
qqq = undefined (undefined)
r = /^asdf.*$/g {lastIndex: 0} (Object)
s = Symbol(hi) (symbol)
str = "hello" (string)
xyz = 4 (number)`}
);
});

testUsing('eval', context => LaunchProject.create(context, TestProjectSpec.fromTestPath('variablesScopes/evalScope')), async (launchProject) => {
await launchProject.pausedWizard.waitUntilPausedOnDebuggerStatement();

await new VariablesWizard(launchProject.debugClient).assertTopFrameVariablesAre({
eval: `
this = Window (Object)
b = body {text: "", link: "", vLink: "", …} (Object)
bool = true (boolean)
buffer = ArrayBuffer(8) {} (Object)
buffView = Int32Array(2) [234, 0] (Object)
e = Error: hi (Object)
element = body {text: "", link: "", vLink: "", …} (Object)
fn = () => { … } (Function)
fn2 = function () { … } (Function)
globalCode = "page loaded" (string)
inf = Infinity (number)
infStr = "Infinity" (string)
longStr = "this is a\nstring with\nnewlines" (string)
m = Map(1) {} (Object)
manyPropsObj = Object {0: 1, 1: 3, 2: 5, …} (Object)
myVar = Object {num: 1, str: "Global", obj: Object, …} (Object)
nan = NaN (number)
obj = Object {a: 2, thing: <accessor>} (Object)
qqq = undefined (undefined)
r = /^asdf.*$/g {lastIndex: 0} (Object)
s = Symbol(hi) (symbol)
str = "hello" (string)
xyz = 4 (number)`}
);
});

testUsing('with', context => LaunchProject.create(context, TestProjectSpec.fromTestPath('variablesScopes/withScope')), async (launchProject) => {
await launchProject.pausedWizard.waitUntilPausedOnDebuggerStatement();

await new VariablesWizard(launchProject.debugClient).assertTopFrameVariablesAre({
with: `
this = Window (Object)
b = body {text: "", link: "", vLink: "", …} (Object)
bool = true (boolean)
buffer = ArrayBuffer(8) {} (Object)
buffView = Int32Array(2) [234, 0] (Object)
consoleDotLog = function (m) { … } (Function)
e = Error: hi (Object)
element = body {text: "", link: "", vLink: "", …} (Object)
evalVar1 = 16 (number)
evalVar2 = "sdlfk" (string)
evalVar3 = Array(3) [1, 2, 3] (Object)
fn = () => { … } (Function)
fn2 = function () { … } (Function)
globalCode = "page loaded" (string)
i = 101 (number)
inf = Infinity (number)
infStr = "Infinity" (string)
longStr = "this is a
string with
newlines" (string)
m = Map(1) {} (Object)
manyPropsObj = Object {0: 1, 1: 3, 2: 5, …} (Object)
myVar = Object {num: 1, str: "Global", obj: Object, …} (Object)
nan = NaN (number)
obj = Object {a: 2, thing: <accessor>} (Object)
r = /^asdf.*$/g {lastIndex: 0} (Object)
s = Symbol(hi) (symbol)
str = "hello" (string)
xyz = 4 (number)
__proto__ = Object {constructor: , __defineGetter__: , __defineSetter__: , …} (Object)`
});
});

testUsing('module', context => LaunchProject.create(context, TestProjectSpec.fromTestPath('variablesScopes/moduleScope')), async (launchProject) => {
await launchProject.pausedWizard.waitUntilPausedOnDebuggerStatement();

await new VariablesWizard(launchProject.debugClient).assertTopFrameVariablesAre({
module: `
this = undefined (undefined)
b = body {text: "", link: "", vLink: "", …} (Object)
bool = true (boolean)
buffer = ArrayBuffer(8) {} (Object)
buffView = Int32Array(2) [234, 0] (Object)
consoleDotLog = function consoleDotLog(m2) { … } (Function)
e = Error: hi (Object)
element = body {text: "", link: "", vLink: "", …} (Object)
fn = () => { … } (Function)
fn2 = function (param) { … } (Function)
globalCode = "page loaded" (string)
inf = Infinity (number)
infStr = "Infinity" (string)
longStr = "this is a
string with
newlines" (string)
m = Map(1) {} (Object)
manyPropsObj = Object {0: 1, 1: 3, 2: 5, …} (Object)
myVar = Object {num: 1, str: "Global", obj: Object, …} (Object)
nan = NaN (number)
obj = Object {a: 2, thing: <accessor>} (Object)
qqq = undefined (undefined)
r = /^asdf.*$/g {lastIndex: 0} (Object)
s = Symbol(hi) (symbol)
str = "hello" (string)
xyz = 4 (number)`
});
});
});
16 changes: 16 additions & 0 deletions testdata/variablesScopes/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}",
// "debugServer": 4712
}
]
}
83 changes: 83 additions & 0 deletions testdata/variablesScopes/blockScope/blockVariablesApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
(function () {
console.log('TestCode: START');
let i;
for (i = 7; i < 10; ++i) {
console.log('TestCode: BEFORE-ADDING-VARIABLES');

// Try to create a variable of each important type, to verify that we can see their contents properly

const globalCode = 'page loaded';

function consoleDotLog(m) {
console.log(m)
}

const manyPropsObj = { prop2: 'abc', prop1: 'def' };
for (let i = 0; i <= 100; i++) manyPropsObj[i] = 2 * i + 1;

let r = /^asdf.*$/g;
let longStr = `this is a
string with
newlines`;
let element = document.body;
const buffer = new ArrayBuffer(8);
let buffView = new Int32Array(buffer);
buffView[0] = 234;
let s = Symbol('hi');
let e = new Error('hi');

let m = new Map();
m.set('a', 1);

let b = document.body;
const nan = NaN;
let inf = 1 / 0;
let infStr = "Infinity";

// These 3 are going to be global variables
eval('let evalVar3 = [1,2,3]');
eval('let evalVar1 = 16');
eval('let evalVar2 = "sdlfk"');

let bool = true;
const fn = () => {
// Some fn
let xyz = 321;
anotherFn();
};
let fn2 = function () {
let zzz = 333;
};
let qqq;
let str = 'hello';
let xyz = 1;
let obj = { a: 2, get thing() { throw 'xyz'; }, set thing(x) { } };
xyz++; xyz++; xyz++;

let myVar = {
num: 1,
str: "Global",

obj: {
obj: {
obj: { num: 10 },
obj2: { obj3: {} },
}
},
obj2: {
obj3: {}
},

}

myVar["self"] = myVar;
myVar.obj["toMyVar"] = myVar;


console.log('TestCode: BEFORE-VERIFYING-VARIABLES');

debugger; // Pause here to verify that we can see the values and types of all the variables
break;
}
console.log('TestCode: END');
})();
10 changes: 10 additions & 0 deletions testdata/variablesScopes/blockScope/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
</head>
<body>
<h1>Hello, world!</h1>
<span id='#pageLoadedSuccesfully'>Page loaded succesfully</span>
<script src="blockVariablesApp.js"></script>
</body>
</html>
15 changes: 15 additions & 0 deletions testdata/variablesScopes/catchScope/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
Loading