From b66ba4a9e08d44d78eead7a069cb289cf8421717 Mon Sep 17 00:00:00 2001 From: Steven Willis Date: Thu, 30 Sep 2021 12:01:15 -0400 Subject: [PATCH 1/2] Add vars to interactive repl type definition Fixes #391 --- testDefinition/definition.test.js | 3 ++- .../examplesTS/interactiveChain.fail.ts | 6 ++++++ testDefinition/examplesTS/interactiveChain.ts | 19 +++++++++++++++++++ typeDefinition/InteractiveCommandChain.d.ts | 7 +++++-- 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 testDefinition/examplesTS/interactiveChain.fail.ts create mode 100644 testDefinition/examplesTS/interactiveChain.ts diff --git a/testDefinition/definition.test.js b/testDefinition/definition.test.js index e45888a9..88a147fc 100644 --- a/testDefinition/definition.test.js +++ b/testDefinition/definition.test.js @@ -70,6 +70,7 @@ describe('suitest typescripts declarations tests', () => { 'videoChain', 'playstationVideoChain', 'indexTest', 'runTestChain', 'takeScreenshotChain', 'saveScreenshotChain', 'setScreenOrientation', 'closeAppChain', 'suspendAppChain', + 'interactiveChain', // 'executeBrightScriptChain', 'brightScriptExpressionChain', ].forEach(fileName => { it(`should compile example ${fileName}`, (done) => { @@ -83,7 +84,7 @@ describe('suitest typescripts declarations tests', () => { // should compile files with error [ 'networkRequestChain.fail', 'elementChain.fail', 'videoChain.fail', 'playstationVideoChain.fail', - 'runTestChain.fail', + 'runTestChain.fail', 'interactiveChain.fail', ].forEach(fileName => { it(`should not compile example ${fileName} chain`, (done) => { assert.ok( diff --git a/testDefinition/examplesTS/interactiveChain.fail.ts b/testDefinition/examplesTS/interactiveChain.fail.ts new file mode 100644 index 00000000..a7a5a8f2 --- /dev/null +++ b/testDefinition/examplesTS/interactiveChain.fail.ts @@ -0,0 +1,6 @@ +import * as suitest from '../../index'; + +const {interactive} = suitest; + +const illegalVarsRepl = interactive({vars: "string"}); +illegalVarsRepl.then(); diff --git a/testDefinition/examplesTS/interactiveChain.ts b/testDefinition/examplesTS/interactiveChain.ts new file mode 100644 index 00000000..287eff0d --- /dev/null +++ b/testDefinition/examplesTS/interactiveChain.ts @@ -0,0 +1,19 @@ +import * as suitest from '../../index'; + +const {interactive} = suitest; + +// should have all necessary modifiers +const baseRepl = interactive({}); +baseRepl.then(); + +// can have empty vars +const emptyVarsRepl = interactive({vars: {}}); +emptyVarsRepl.then(); + +// can have vars with values of different types +const a = "foobar"; +const b = 5; +const c = {one: "two"}; + +const varsRepl = interactive({vars: {a, b, c}}); +varsRepl.then(); diff --git a/typeDefinition/InteractiveCommandChain.d.ts b/typeDefinition/InteractiveCommandChain.d.ts index aac71720..b4b87bdc 100644 --- a/typeDefinition/InteractiveCommandChain.d.ts +++ b/typeDefinition/InteractiveCommandChain.d.ts @@ -1,6 +1,9 @@ +import { REPLServer } from "repl"; + export type ReplOptions = { - cwd?:string, + cwd?: string, repeater?: string|Function, watch?: string|Array, - ignored?:string + ignored?: string, + vars?: REPLServer["context"], } From 7cce60bd0e453c9e39c7496309a9139594d358ea Mon Sep 17 00:00:00 2001 From: Steven Willis Date: Thu, 30 Sep 2021 13:37:41 -0400 Subject: [PATCH 2/2] Stop changing directory for the interactive repl Fixes #390 --- lib/testLauncher/repl.js | 13 ------------- test/testLauncher/repl.test.js | 2 +- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/lib/testLauncher/repl.js b/lib/testLauncher/repl.js index 50b7c0b6..a0a11eab 100644 --- a/lib/testLauncher/repl.js +++ b/lib/testLauncher/repl.js @@ -71,8 +71,6 @@ function setupRepl(opts, isTTY) { Object.assign(replInstance.context, vars); - setReplCwd(replInstance, cwd); - return new Promise(resolve => { replInstance.on('exit', () => { watcher.close(); @@ -147,17 +145,6 @@ async function onFileChange(file, cwd, callFile, repeater) { await func(); } -/** - * Sets the current working directory of the repl shell - * @param {REPLServer} replInstance - * @param {String} cwd - the directory to set - */ -function setReplCwd(replInstance, cwd) { - replInstance.eval('', replInstance.context, __filename, () => { - process.chdir(cwd); - }); -} - /** * Clears node require cache for the file and requires this file again * @param {string} f - path to the file to re-require diff --git a/test/testLauncher/repl.test.js b/test/testLauncher/repl.test.js index 5055b445..056f72ba 100644 --- a/test/testLauncher/repl.test.js +++ b/test/testLauncher/repl.test.js @@ -125,7 +125,7 @@ describe('repl', () => { }, false); await new Promise(resolve => { - setInterval(() => chDir.called && resolve(), 10); + setInterval(() => chDir.notCalled && resolve(), 10); }); await new Promise(resolve => {