codeceptjs 4.0.0-beta.2 → 4.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -120
- package/bin/codecept.js +107 -96
- package/bin/test-server.js +64 -0
- package/docs/webapi/clearCookie.mustache +1 -1
- package/docs/webapi/click.mustache +5 -1
- package/lib/actor.js +71 -103
- package/lib/ai.js +159 -188
- package/lib/assert/empty.js +22 -24
- package/lib/assert/equal.js +30 -37
- package/lib/assert/error.js +14 -14
- package/lib/assert/include.js +43 -48
- package/lib/assert/throws.js +11 -11
- package/lib/assert/truth.js +22 -22
- package/lib/assert.js +20 -18
- package/lib/codecept.js +262 -162
- package/lib/colorUtils.js +50 -52
- package/lib/command/check.js +206 -0
- package/lib/command/configMigrate.js +56 -51
- package/lib/command/definitions.js +96 -109
- package/lib/command/dryRun.js +77 -79
- package/lib/command/generate.js +234 -194
- package/lib/command/gherkin/init.js +42 -33
- package/lib/command/gherkin/snippets.js +76 -74
- package/lib/command/gherkin/steps.js +20 -17
- package/lib/command/info.js +74 -38
- package/lib/command/init.js +301 -290
- package/lib/command/interactive.js +41 -32
- package/lib/command/list.js +28 -27
- package/lib/command/run-multiple/chunk.js +51 -48
- package/lib/command/run-multiple/collection.js +5 -5
- package/lib/command/run-multiple/run.js +5 -1
- package/lib/command/run-multiple.js +97 -97
- package/lib/command/run-rerun.js +19 -25
- package/lib/command/run-workers.js +68 -92
- package/lib/command/run.js +39 -27
- package/lib/command/utils.js +80 -64
- package/lib/command/workers/runTests.js +388 -226
- package/lib/config.js +109 -50
- package/lib/container.js +641 -261
- package/lib/data/context.js +60 -61
- package/lib/data/dataScenarioConfig.js +47 -47
- package/lib/data/dataTableArgument.js +32 -32
- package/lib/data/table.js +22 -22
- package/lib/effects.js +307 -0
- package/lib/element/WebElement.js +327 -0
- package/lib/els.js +160 -0
- package/lib/event.js +173 -163
- package/lib/globals.js +141 -0
- package/lib/heal.js +89 -85
- package/lib/helper/AI.js +131 -41
- package/lib/helper/ApiDataFactory.js +107 -75
- package/lib/helper/Appium.js +542 -404
- package/lib/helper/FileSystem.js +100 -79
- package/lib/helper/GraphQL.js +44 -43
- package/lib/helper/GraphQLDataFactory.js +52 -52
- package/lib/helper/JSONResponse.js +126 -88
- package/lib/helper/Mochawesome.js +54 -29
- package/lib/helper/Playwright.js +2547 -1316
- package/lib/helper/Puppeteer.js +1578 -1181
- package/lib/helper/REST.js +209 -68
- package/lib/helper/WebDriver.js +1482 -1342
- package/lib/helper/errors/ConnectionRefused.js +6 -6
- package/lib/helper/errors/ElementAssertion.js +11 -16
- package/lib/helper/errors/ElementNotFound.js +5 -9
- package/lib/helper/errors/RemoteBrowserConnectionRefused.js +5 -5
- package/lib/helper/extras/Console.js +11 -11
- package/lib/helper/extras/PlaywrightLocator.js +110 -0
- package/lib/helper/extras/PlaywrightPropEngine.js +18 -18
- package/lib/helper/extras/PlaywrightReactVueLocator.js +17 -8
- package/lib/helper/extras/PlaywrightRestartOpts.js +25 -11
- package/lib/helper/extras/Popup.js +22 -22
- package/lib/helper/extras/React.js +27 -28
- package/lib/helper/network/actions.js +36 -42
- package/lib/helper/network/utils.js +78 -84
- package/lib/helper/scripts/blurElement.js +5 -5
- package/lib/helper/scripts/focusElement.js +5 -5
- package/lib/helper/scripts/highlightElement.js +8 -8
- package/lib/helper/scripts/isElementClickable.js +34 -34
- package/lib/helper.js +2 -3
- package/lib/history.js +23 -19
- package/lib/hooks.js +8 -8
- package/lib/html.js +94 -104
- package/lib/index.js +38 -27
- package/lib/listener/config.js +30 -23
- package/lib/listener/emptyRun.js +54 -0
- package/lib/listener/enhancedGlobalRetry.js +110 -0
- package/lib/listener/exit.js +16 -18
- package/lib/listener/globalRetry.js +70 -0
- package/lib/listener/globalTimeout.js +181 -0
- package/lib/listener/helpers.js +76 -51
- package/lib/listener/mocha.js +10 -11
- package/lib/listener/result.js +11 -0
- package/lib/listener/retryEnhancer.js +85 -0
- package/lib/listener/steps.js +71 -59
- package/lib/listener/store.js +20 -0
- package/lib/locator.js +214 -197
- package/lib/mocha/asyncWrapper.js +274 -0
- package/lib/mocha/bdd.js +167 -0
- package/lib/mocha/cli.js +341 -0
- package/lib/mocha/factory.js +163 -0
- package/lib/mocha/featureConfig.js +89 -0
- package/lib/mocha/gherkin.js +231 -0
- package/lib/mocha/hooks.js +121 -0
- package/lib/mocha/index.js +21 -0
- package/lib/mocha/inject.js +46 -0
- package/lib/{interfaces → mocha}/scenarioConfig.js +58 -34
- package/lib/mocha/suite.js +89 -0
- package/lib/mocha/test.js +184 -0
- package/lib/mocha/types.d.ts +42 -0
- package/lib/mocha/ui.js +242 -0
- package/lib/output.js +141 -71
- package/lib/parser.js +47 -44
- package/lib/pause.js +173 -145
- package/lib/plugin/analyze.js +403 -0
- package/lib/plugin/{autoLogin.js → auth.js} +178 -79
- package/lib/plugin/autoDelay.js +36 -40
- package/lib/plugin/coverage.js +131 -78
- package/lib/plugin/customLocator.js +22 -21
- package/lib/plugin/customReporter.js +53 -0
- package/lib/plugin/enhancedRetryFailedStep.js +99 -0
- package/lib/plugin/heal.js +101 -110
- package/lib/plugin/htmlReporter.js +3648 -0
- package/lib/plugin/pageInfo.js +140 -0
- package/lib/plugin/pauseOnFail.js +12 -11
- package/lib/plugin/retryFailedStep.js +82 -47
- package/lib/plugin/screenshotOnFail.js +111 -92
- package/lib/plugin/stepByStepReport.js +159 -101
- package/lib/plugin/stepTimeout.js +20 -25
- package/lib/plugin/subtitles.js +38 -38
- package/lib/recorder.js +193 -130
- package/lib/rerun.js +94 -49
- package/lib/result.js +238 -0
- package/lib/retryCoordinator.js +207 -0
- package/lib/secret.js +20 -18
- package/lib/session.js +95 -89
- package/lib/step/base.js +239 -0
- package/lib/step/comment.js +10 -0
- package/lib/step/config.js +50 -0
- package/lib/step/func.js +46 -0
- package/lib/step/helper.js +50 -0
- package/lib/step/meta.js +99 -0
- package/lib/step/record.js +74 -0
- package/lib/step/retry.js +11 -0
- package/lib/step/section.js +55 -0
- package/lib/step.js +18 -329
- package/lib/steps.js +54 -0
- package/lib/store.js +38 -7
- package/lib/template/heal.js +3 -12
- package/lib/template/prompts/generatePageObject.js +31 -0
- package/lib/template/prompts/healStep.js +13 -0
- package/lib/template/prompts/writeStep.js +9 -0
- package/lib/test-server.js +334 -0
- package/lib/timeout.js +60 -0
- package/lib/transform.js +8 -8
- package/lib/translation.js +34 -21
- package/lib/utils/loaderCheck.js +124 -0
- package/lib/utils/mask_data.js +47 -0
- package/lib/utils/typescript.js +237 -0
- package/lib/utils.js +411 -228
- package/lib/workerStorage.js +37 -34
- package/lib/workers.js +532 -296
- package/package.json +124 -95
- package/translations/de-DE.js +5 -3
- package/translations/fr-FR.js +5 -4
- package/translations/index.js +22 -12
- package/translations/it-IT.js +4 -3
- package/translations/ja-JP.js +4 -3
- package/translations/nl-NL.js +76 -0
- package/translations/pl-PL.js +4 -3
- package/translations/pt-BR.js +4 -3
- package/translations/ru-RU.js +4 -3
- package/translations/utils.js +10 -0
- package/translations/zh-CN.js +4 -3
- package/translations/zh-TW.js +4 -3
- package/typings/index.d.ts +546 -185
- package/typings/promiseBasedTypes.d.ts +150 -875
- package/typings/types.d.ts +547 -992
- package/lib/cli.js +0 -249
- package/lib/dirname.js +0 -5
- package/lib/helper/Expect.js +0 -425
- package/lib/helper/ExpectHelper.js +0 -399
- package/lib/helper/MockServer.js +0 -223
- package/lib/helper/Nightmare.js +0 -1411
- package/lib/helper/Protractor.js +0 -1835
- package/lib/helper/SoftExpectHelper.js +0 -381
- package/lib/helper/TestCafe.js +0 -1410
- package/lib/helper/clientscripts/nightmare.js +0 -213
- package/lib/helper/testcafe/testControllerHolder.js +0 -42
- package/lib/helper/testcafe/testcafe-utils.js +0 -63
- package/lib/interfaces/bdd.js +0 -98
- package/lib/interfaces/featureConfig.js +0 -69
- package/lib/interfaces/gherkin.js +0 -195
- package/lib/listener/artifacts.js +0 -19
- package/lib/listener/retry.js +0 -68
- package/lib/listener/timeout.js +0 -109
- package/lib/mochaFactory.js +0 -110
- package/lib/plugin/allure.js +0 -15
- package/lib/plugin/commentStep.js +0 -136
- package/lib/plugin/debugErrors.js +0 -67
- package/lib/plugin/eachElement.js +0 -127
- package/lib/plugin/fakerTransform.js +0 -49
- package/lib/plugin/retryTo.js +0 -121
- package/lib/plugin/selenoid.js +0 -371
- package/lib/plugin/standardActingHelpers.js +0 -9
- package/lib/plugin/tryTo.js +0 -105
- package/lib/plugin/wdio.js +0 -246
- package/lib/scenario.js +0 -222
- package/lib/ui.js +0 -238
- package/lib/within.js +0 -70
package/lib/pause.js
CHANGED
|
@@ -1,210 +1,238 @@
|
|
|
1
|
-
import colors from 'chalk'
|
|
2
|
-
import readline from 'readline'
|
|
3
|
-
import ora from 'ora-classic'
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import container from './container.js'
|
|
7
|
-
import history from './history.js'
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import recorder from './recorder.js'
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import { methodsOfObject } from './utils.js'
|
|
14
|
-
|
|
15
|
-
debug('codeceptjs:pause');
|
|
1
|
+
import colors from 'chalk'
|
|
2
|
+
import readline from 'readline'
|
|
3
|
+
import ora from 'ora-classic'
|
|
4
|
+
import debugModule from 'debug'
|
|
5
|
+
const debug = debugModule('codeceptjs:pause')
|
|
6
|
+
import container from './container.js'
|
|
7
|
+
import history from './history.js'
|
|
8
|
+
import store from './store.js'
|
|
9
|
+
import aiAssistant from './ai.js'
|
|
10
|
+
import recorder from './recorder.js'
|
|
11
|
+
import event from './event.js'
|
|
12
|
+
import output from './output.js'
|
|
13
|
+
import { methodsOfObject, searchWithFusejs } from './utils.js'
|
|
16
14
|
|
|
17
15
|
// npm install colors
|
|
18
|
-
let rl
|
|
19
|
-
let nextStep
|
|
20
|
-
let finish
|
|
21
|
-
let next
|
|
22
|
-
let registeredVariables = {}
|
|
23
|
-
let aiAssistant;
|
|
16
|
+
let rl
|
|
17
|
+
let nextStep
|
|
18
|
+
let finish
|
|
19
|
+
let next
|
|
20
|
+
let registeredVariables = {}
|
|
24
21
|
/**
|
|
25
22
|
* Pauses test execution and starts interactive shell
|
|
26
23
|
* @param {Object<string, *>} [passedObject]
|
|
27
24
|
*/
|
|
28
25
|
const pause = function (passedObject = {}) {
|
|
29
|
-
if (store.dryRun) return
|
|
26
|
+
if (store.dryRun) return
|
|
30
27
|
|
|
31
|
-
next = false
|
|
28
|
+
next = false
|
|
32
29
|
// add listener to all next steps to provide next() functionality
|
|
33
30
|
event.dispatcher.on(event.step.after, () => {
|
|
34
31
|
recorder.add('Start next pause session', () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
32
|
+
// test already finished, nothing to pause
|
|
33
|
+
if (!store.currentTest) return
|
|
34
|
+
if (!next) return
|
|
35
|
+
return pauseSession()
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
event.dispatcher.on(event.test.finished, () => {
|
|
40
|
+
finish()
|
|
41
|
+
recorder.session.restore('pause')
|
|
42
|
+
rl.close()
|
|
43
|
+
history.save()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
recorder.add('Start new session', () => pauseSession(passedObject))
|
|
47
|
+
}
|
|
41
48
|
|
|
42
49
|
function pauseSession(passedObject = {}) {
|
|
43
|
-
registeredVariables = passedObject
|
|
44
|
-
recorder.session.start('pause')
|
|
50
|
+
registeredVariables = passedObject
|
|
51
|
+
recorder.session.start('pause')
|
|
45
52
|
if (!next) {
|
|
46
|
-
let vars = Object.keys(registeredVariables).join(', ')
|
|
47
|
-
if (vars) vars = `(vars: ${vars})
|
|
48
|
-
|
|
49
|
-
aiAssistant = AiAssistant.getInstance();
|
|
53
|
+
let vars = Object.keys(registeredVariables).join(', ')
|
|
54
|
+
if (vars) vars = `(vars: ${vars})`
|
|
50
55
|
|
|
51
|
-
output.print(colors.yellow(' Interactive shell started'))
|
|
52
|
-
output.print(colors.yellow(' Use JavaScript syntax to try steps in action'))
|
|
53
|
-
output.print(colors.yellow(` - Press ${colors.bold('ENTER')} to run the next step`))
|
|
54
|
-
output.print(colors.yellow(` - Press ${colors.bold('TAB')} twice to see all available commands`))
|
|
55
|
-
output.print(colors.yellow(` - Type ${colors.bold('exit')} + Enter to exit the interactive shell`))
|
|
56
|
-
output.print(colors.yellow(` - Prefix ${colors.bold('=>')} to run js commands ${colors.bold(vars)}`))
|
|
56
|
+
output.print(colors.yellow(' Interactive shell started'))
|
|
57
|
+
output.print(colors.yellow(' Use JavaScript syntax to try steps in action'))
|
|
58
|
+
output.print(colors.yellow(` - Press ${colors.bold('ENTER')} to run the next step`))
|
|
59
|
+
output.print(colors.yellow(` - Press ${colors.bold('TAB')} twice to see all available commands`))
|
|
60
|
+
output.print(colors.yellow(` - Type ${colors.bold('exit')} + Enter to exit the interactive shell`))
|
|
61
|
+
output.print(colors.yellow(` - Prefix ${colors.bold('=>')} to run js commands ${colors.bold(vars)}`))
|
|
57
62
|
|
|
58
63
|
if (aiAssistant.isEnabled) {
|
|
59
|
-
output.print(colors.blue(` ${colors.bold('
|
|
60
|
-
output.print(colors.blue(' Please note, only HTML fragments with interactive elements are sent to
|
|
61
|
-
output.print(colors.blue(' Ideas: ask it to fill forms for you or to click'))
|
|
62
|
-
} else {
|
|
63
|
-
output.print(colors.blue(` Enable OpenAI assistant by setting ${colors.bold('OPENAI_API_KEY')} env variable`));
|
|
64
|
+
output.print(colors.blue(` ${colors.bold('AI is enabled! (experimental)')} Write what you want and make AI run it`))
|
|
65
|
+
output.print(colors.blue(' Please note, only HTML fragments with interactive elements are sent to AI provider'))
|
|
66
|
+
output.print(colors.blue(' Ideas: ask it to fill forms for you or to click'))
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
|
-
rl = readline.createInterface(process.stdin, process.stdout, completer);
|
|
67
69
|
|
|
68
|
-
rl.
|
|
70
|
+
rl = readline.createInterface({
|
|
71
|
+
input: process.stdin,
|
|
72
|
+
output: process.stdout,
|
|
73
|
+
terminal: true,
|
|
74
|
+
completer,
|
|
75
|
+
history: history.load(),
|
|
76
|
+
historySize: 50, // Adjust the history size as needed
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
store.onPause = true
|
|
80
|
+
rl.on('line', parseInput)
|
|
69
81
|
rl.on('close', () => {
|
|
70
|
-
if (!next) console.log('Exiting interactive shell....')
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return askForStep()
|
|
76
|
-
})
|
|
82
|
+
if (!next) console.log('Exiting interactive shell....')
|
|
83
|
+
store.onPause = false
|
|
84
|
+
})
|
|
85
|
+
return new Promise(resolve => {
|
|
86
|
+
finish = resolve
|
|
87
|
+
return askForStep()
|
|
88
|
+
})
|
|
77
89
|
}
|
|
78
90
|
|
|
79
|
-
/* eslint-disable */
|
|
80
91
|
async function parseInput(cmd) {
|
|
81
|
-
rl.pause()
|
|
82
|
-
next = false
|
|
83
|
-
recorder.session.start('pause')
|
|
84
|
-
if (cmd === '') next = true
|
|
92
|
+
rl.pause()
|
|
93
|
+
next = false
|
|
94
|
+
recorder.session.start('pause')
|
|
95
|
+
if (cmd === '') next = true
|
|
85
96
|
if (!cmd || cmd === 'resume' || cmd === 'exit') {
|
|
86
|
-
finish()
|
|
87
|
-
recorder.session.restore()
|
|
88
|
-
rl.close()
|
|
89
|
-
history.save()
|
|
90
|
-
return nextStep()
|
|
97
|
+
finish()
|
|
98
|
+
recorder.session.restore('pause')
|
|
99
|
+
rl.close()
|
|
100
|
+
history.save()
|
|
101
|
+
return nextStep()
|
|
91
102
|
}
|
|
92
103
|
for (const k of Object.keys(registeredVariables)) {
|
|
93
|
-
eval(`var ${k} = registeredVariables['${k}'];`)
|
|
104
|
+
eval(`var ${k} = registeredVariables['${k}'];`)
|
|
94
105
|
}
|
|
95
106
|
|
|
96
|
-
let executeCommand = Promise.resolve()
|
|
107
|
+
let executeCommand = Promise.resolve()
|
|
97
108
|
|
|
98
109
|
const getCmd = () => {
|
|
99
110
|
debug('Command:', cmd)
|
|
100
|
-
return cmd
|
|
101
|
-
}
|
|
111
|
+
return cmd
|
|
112
|
+
}
|
|
102
113
|
|
|
103
|
-
let isCustomCommand = false
|
|
104
|
-
let lastError = null
|
|
105
|
-
let isAiCommand = false
|
|
106
|
-
let $res
|
|
114
|
+
let isCustomCommand = false
|
|
115
|
+
let lastError = null
|
|
116
|
+
let isAiCommand = false
|
|
117
|
+
let $res
|
|
107
118
|
try {
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const I = container.support('I');
|
|
119
|
+
const locate = global.locate // enable locate in this context
|
|
120
|
+
|
|
121
|
+
const I = container.support('I')
|
|
112
122
|
if (cmd.trim().startsWith('=>')) {
|
|
113
|
-
isCustomCommand = true
|
|
114
|
-
cmd = cmd.trim().substring(2, cmd.length)
|
|
115
|
-
} else if (aiAssistant.isEnabled && !cmd.match(/^\w+\(/) && cmd.includes(' ')) {
|
|
116
|
-
const currentOutputLevel = output.level()
|
|
117
|
-
output.level(0)
|
|
118
|
-
const res = I.grabSource()
|
|
119
|
-
isAiCommand = true
|
|
123
|
+
isCustomCommand = true
|
|
124
|
+
cmd = cmd.trim().substring(2, cmd.length)
|
|
125
|
+
} else if (aiAssistant.isEnabled && cmd.trim() && !cmd.match(/^\w+\(/) && cmd.includes(' ')) {
|
|
126
|
+
const currentOutputLevel = output.level()
|
|
127
|
+
output.level(0)
|
|
128
|
+
const res = I.grabSource()
|
|
129
|
+
isAiCommand = true
|
|
120
130
|
executeCommand = executeCommand.then(async () => {
|
|
121
131
|
try {
|
|
122
|
-
const html = await res
|
|
123
|
-
await aiAssistant.setHtmlContext(html)
|
|
132
|
+
const html = await res
|
|
133
|
+
await aiAssistant.setHtmlContext(html)
|
|
124
134
|
} catch (err) {
|
|
125
|
-
output.print(output.
|
|
126
|
-
return
|
|
135
|
+
output.print(output.styles.error(' ERROR '), "Can't get HTML context", err.stack)
|
|
136
|
+
return
|
|
127
137
|
} finally {
|
|
128
|
-
output.level(currentOutputLevel)
|
|
138
|
+
output.level(currentOutputLevel)
|
|
129
139
|
}
|
|
130
|
-
|
|
131
|
-
const spinner = ora(
|
|
132
|
-
cmd = await aiAssistant.writeSteps(cmd)
|
|
133
|
-
spinner.stop()
|
|
134
|
-
output.print('')
|
|
135
|
-
output.print(colors.blue(aiAssistant.getResponse()))
|
|
136
|
-
output.print('')
|
|
137
|
-
return cmd
|
|
140
|
+
|
|
141
|
+
const spinner = ora('Processing AI request...').start()
|
|
142
|
+
cmd = await aiAssistant.writeSteps(cmd)
|
|
143
|
+
spinner.stop()
|
|
144
|
+
output.print('')
|
|
145
|
+
output.print(colors.blue(aiAssistant.getResponse()))
|
|
146
|
+
output.print('')
|
|
147
|
+
return cmd
|
|
138
148
|
})
|
|
139
149
|
} else {
|
|
140
|
-
cmd = `I.${cmd}
|
|
150
|
+
cmd = `I.${cmd}`
|
|
141
151
|
}
|
|
142
|
-
executeCommand = executeCommand
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
executeCommand = executeCommand
|
|
153
|
+
.then(async () => {
|
|
154
|
+
const cmd = getCmd()
|
|
155
|
+
if (!cmd) return
|
|
156
|
+
return eval(cmd)
|
|
157
|
+
})
|
|
158
|
+
.catch(err => {
|
|
159
|
+
debug(err)
|
|
160
|
+
if (isAiCommand) return
|
|
161
|
+
if (!lastError) output.print(output.styles.error(' ERROR '), err.message)
|
|
162
|
+
debug(err.stack)
|
|
163
|
+
|
|
164
|
+
lastError = err.message
|
|
165
|
+
})
|
|
154
166
|
|
|
155
|
-
const val = await executeCommand
|
|
167
|
+
const val = await executeCommand
|
|
156
168
|
|
|
157
169
|
if (isCustomCommand) {
|
|
158
|
-
if (val !== undefined) console.log('Result', '$res=', val)
|
|
159
|
-
$res = val
|
|
170
|
+
if (val !== undefined) console.log('Result', '$res=', val)
|
|
171
|
+
$res = val
|
|
160
172
|
}
|
|
161
173
|
|
|
162
174
|
if (cmd?.startsWith('I.see') || cmd?.startsWith('I.dontSee')) {
|
|
163
|
-
output.print(output.
|
|
175
|
+
output.print(output.styles.success(' OK '), cmd)
|
|
164
176
|
}
|
|
165
177
|
if (cmd?.startsWith('I.grab')) {
|
|
166
|
-
|
|
178
|
+
try {
|
|
179
|
+
output.print(output.styles.debug(JSON.stringify(val, null, 2)))
|
|
180
|
+
} catch (err) {
|
|
181
|
+
output.print(output.styles.error(' ERROR '), 'Failed to stringify result:', err.message)
|
|
182
|
+
output.print(output.styles.error(' RAW VALUE '), String(val))
|
|
183
|
+
}
|
|
167
184
|
}
|
|
168
185
|
|
|
169
|
-
history.push(cmd)
|
|
186
|
+
history.push(cmd) // add command to history when successful
|
|
170
187
|
} catch (err) {
|
|
171
|
-
if (!lastError) output.print(output.
|
|
172
|
-
lastError = err.message
|
|
188
|
+
if (!lastError) output.print(output.styles.error(' ERROR '), err.message)
|
|
189
|
+
lastError = err.message
|
|
173
190
|
}
|
|
174
|
-
recorder.session.catch(
|
|
175
|
-
const msg = err.cliMessage ? err.cliMessage() : err.message
|
|
191
|
+
recorder.session.catch(err => {
|
|
192
|
+
const msg = err.cliMessage ? err.cliMessage() : err.message
|
|
176
193
|
|
|
177
194
|
// pop latest command from history because it failed
|
|
178
|
-
history.pop()
|
|
179
|
-
|
|
180
|
-
if (isAiCommand) return
|
|
181
|
-
if (!lastError) output.print(output.
|
|
182
|
-
lastError = err.message
|
|
183
|
-
})
|
|
184
|
-
recorder.add('ask for next step', askForStep)
|
|
185
|
-
nextStep()
|
|
195
|
+
history.pop()
|
|
196
|
+
|
|
197
|
+
if (isAiCommand) return
|
|
198
|
+
if (!lastError) output.print(output.styles.error(' FAIL '), msg)
|
|
199
|
+
lastError = err.message
|
|
200
|
+
})
|
|
201
|
+
recorder.add('ask for next step', askForStep)
|
|
202
|
+
nextStep()
|
|
186
203
|
}
|
|
187
|
-
/* eslint-enable */
|
|
188
204
|
|
|
189
205
|
function askForStep() {
|
|
190
|
-
return new Promise(
|
|
191
|
-
nextStep = resolve
|
|
192
|
-
rl.setPrompt(' I.', 3)
|
|
193
|
-
rl.resume()
|
|
194
|
-
rl.prompt([false])
|
|
195
|
-
})
|
|
206
|
+
return new Promise(resolve => {
|
|
207
|
+
nextStep = resolve
|
|
208
|
+
rl.setPrompt(' I.', 3)
|
|
209
|
+
rl.resume()
|
|
210
|
+
rl.prompt([false])
|
|
211
|
+
})
|
|
196
212
|
}
|
|
197
213
|
|
|
198
214
|
function completer(line) {
|
|
199
|
-
const I = container.support('I')
|
|
200
|
-
const completions = methodsOfObject(I)
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
215
|
+
const I = container.support('I')
|
|
216
|
+
const completions = methodsOfObject(I)
|
|
217
|
+
// If no input, return all completions
|
|
218
|
+
if (!line) {
|
|
219
|
+
return [completions, line]
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Search using Fuse.js
|
|
223
|
+
const searchResults = searchWithFusejs(completions, line, {
|
|
224
|
+
threshold: 0.3,
|
|
225
|
+
distance: 100,
|
|
226
|
+
minMatchCharLength: 1,
|
|
227
|
+
})
|
|
228
|
+
const hits = searchResults.map(result => result.item)
|
|
229
|
+
|
|
230
|
+
return [hits, line]
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function registerVariable(name, value) {
|
|
234
|
+
registeredVariables[name] = value
|
|
208
235
|
}
|
|
209
236
|
|
|
210
|
-
export default pause
|
|
237
|
+
export default pause
|
|
238
|
+
export { registerVariable }
|