Skip to content

Commit 1aa8120

Browse files
authored
fix: fixed an error occurs when a role is applied in a raw API test (#6404)
* fix: added the inheriting of context * test: added test Shouldn't lose context in nested functions with Selector * fix: added returning null while creating execution context if testFile is undefined * fix: removed changes * feat: added the property with the key OPTIONS_KEY in the replacers by default * test: changed the test name * feat: added default value for the context execution
1 parent 81bfdda commit 1aa8120

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

src/api/test-controller/execution-context.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import NODE_MODULES from '../../shared/node-modules-folder-name';
66

77
const OPTIONS_KEY = Symbol('options');
88

9+
export const DEFAULT_CONTEXT_OPTIONS = {
10+
skipVisibilityCheck: false,
11+
collectionMode: false,
12+
};
13+
914
function getModuleBasePaths (currentPath) {
1015
const nodePaths = [];
1116
let parentDir = path.dirname(currentPath);
@@ -81,6 +86,7 @@ export function createExecutionContext (testRun) {
8186
RequestLogger: exportableLib.RequestLogger,
8287
RequestMock: exportableLib.RequestMock,
8388
RequestHook: exportableLib.RequestHook,
89+
[OPTIONS_KEY]: DEFAULT_CONTEXT_OPTIONS,
8490
};
8591

8692
return createContext(new Proxy(replacers, {

src/test-run/execute-js-expression/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '../../errors/runtime';
99

1010
import { UncaughtErrorInCustomScript, UncaughtTestCafeErrorInCustomScript } from '../../errors/test-run';
11-
import { setContextOptions } from '../../api/test-controller/execution-context';
11+
import { setContextOptions, DEFAULT_CONTEXT_OPTIONS } from '../../api/test-controller/execution-context';
1212

1313
import {
1414
ERROR_LINE_COLUMN_REGEXP,
@@ -59,7 +59,7 @@ function createErrorFormattingOptions () {
5959
};
6060
}
6161

62-
function getExecutionContext (testController, options = {}) {
62+
function getExecutionContext (testController, options = DEFAULT_CONTEXT_OPTIONS) {
6363
const context = testController.getExecutionContext();
6464

6565
// TODO: Find a way to avoid this assignment

test/functional/fixtures/api/raw/execute-expression/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ describe('[Raw API] Execute expression action', function () {
1010
it('Should share global variables between different command calls', function () {
1111
return runTests('./testcafe-fixtures/shared-context.testcafe', 'Share variables between commands');
1212
});
13+
14+
it("Shouldn't lose context in nested functions with Selector", function () {
15+
return runTests('./testcafe-fixtures/shared-context.testcafe', "Don't lose context in nested functions");
16+
});
1317
});

test/functional/fixtures/api/raw/execute-expression/testcafe-fixtures/shared-context.testcafe

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"commands": [
4141
{
4242
"type": "execute-expression",
43-
"expression": "shared = 'initial value';"
43+
"expression": "shared = 'initial value';"
4444
},
4545
{
4646
"type": "execute-expression",
@@ -59,6 +59,15 @@
5959
"expected": "initial value"
6060
}
6161
]
62+
},
63+
{
64+
"name": "Don't lose context in nested functions",
65+
"commands": [
66+
{
67+
"type": "execute-async-expression",
68+
"expression": "const role = Role('https://demos.devexpress.com/XAF/MainDemo', async t => {\r\n \r\n await t.typeText('.dxeEditArea_XafTheme.dxeEditAreaSys', 'John', {\r\n replace: true\r\n })\r\n .click(Selector('span').withText('Log In'));\r\n});\r\n\r\nawait t.useRole(role);\r\n"
69+
}
70+
]
6271
}
6372
]
6473
}

0 commit comments

Comments
 (0)