codeceptjs 4.0.0-beta.1 → 4.0.0-beta.11.esm-aria

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.
Files changed (207) hide show
  1. package/README.md +133 -120
  2. package/bin/codecept.js +107 -96
  3. package/bin/test-server.js +64 -0
  4. package/docs/webapi/clearCookie.mustache +1 -1
  5. package/docs/webapi/click.mustache +5 -1
  6. package/lib/actor.js +71 -103
  7. package/lib/ai.js +159 -188
  8. package/lib/assert/empty.js +22 -24
  9. package/lib/assert/equal.js +30 -37
  10. package/lib/assert/error.js +14 -14
  11. package/lib/assert/include.js +43 -48
  12. package/lib/assert/throws.js +11 -11
  13. package/lib/assert/truth.js +22 -22
  14. package/lib/assert.js +20 -18
  15. package/lib/codecept.js +238 -162
  16. package/lib/colorUtils.js +50 -52
  17. package/lib/command/check.js +206 -0
  18. package/lib/command/configMigrate.js +56 -51
  19. package/lib/command/definitions.js +96 -109
  20. package/lib/command/dryRun.js +77 -79
  21. package/lib/command/generate.js +234 -194
  22. package/lib/command/gherkin/init.js +42 -33
  23. package/lib/command/gherkin/snippets.js +76 -74
  24. package/lib/command/gherkin/steps.js +20 -17
  25. package/lib/command/info.js +74 -38
  26. package/lib/command/init.js +300 -290
  27. package/lib/command/interactive.js +41 -32
  28. package/lib/command/list.js +28 -27
  29. package/lib/command/run-multiple/chunk.js +51 -48
  30. package/lib/command/run-multiple/collection.js +5 -5
  31. package/lib/command/run-multiple/run.js +5 -1
  32. package/lib/command/run-multiple.js +97 -97
  33. package/lib/command/run-rerun.js +19 -25
  34. package/lib/command/run-workers.js +68 -92
  35. package/lib/command/run.js +39 -27
  36. package/lib/command/utils.js +80 -64
  37. package/lib/command/workers/runTests.js +388 -226
  38. package/lib/config.js +124 -50
  39. package/lib/container.js +765 -260
  40. package/lib/data/context.js +60 -61
  41. package/lib/data/dataScenarioConfig.js +47 -47
  42. package/lib/data/dataTableArgument.js +32 -32
  43. package/lib/data/table.js +22 -22
  44. package/lib/effects.js +307 -0
  45. package/lib/element/WebElement.js +327 -0
  46. package/lib/els.js +160 -0
  47. package/lib/event.js +173 -163
  48. package/lib/globals.js +141 -0
  49. package/lib/heal.js +89 -85
  50. package/lib/helper/AI.js +131 -41
  51. package/lib/helper/ApiDataFactory.js +107 -75
  52. package/lib/helper/Appium.js +542 -404
  53. package/lib/helper/FileSystem.js +100 -79
  54. package/lib/helper/GraphQL.js +44 -43
  55. package/lib/helper/GraphQLDataFactory.js +52 -52
  56. package/lib/helper/JSONResponse.js +126 -88
  57. package/lib/helper/Mochawesome.js +54 -29
  58. package/lib/helper/Playwright.js +2547 -1316
  59. package/lib/helper/Puppeteer.js +1578 -1181
  60. package/lib/helper/REST.js +209 -68
  61. package/lib/helper/WebDriver.js +1482 -1342
  62. package/lib/helper/errors/ConnectionRefused.js +6 -6
  63. package/lib/helper/errors/ElementAssertion.js +11 -16
  64. package/lib/helper/errors/ElementNotFound.js +5 -9
  65. package/lib/helper/errors/RemoteBrowserConnectionRefused.js +5 -5
  66. package/lib/helper/extras/Console.js +11 -11
  67. package/lib/helper/extras/PlaywrightLocator.js +110 -0
  68. package/lib/helper/extras/PlaywrightPropEngine.js +18 -18
  69. package/lib/helper/extras/PlaywrightReactVueLocator.js +17 -8
  70. package/lib/helper/extras/PlaywrightRestartOpts.js +25 -11
  71. package/lib/helper/extras/Popup.js +22 -22
  72. package/lib/helper/extras/React.js +27 -28
  73. package/lib/helper/network/actions.js +36 -42
  74. package/lib/helper/network/utils.js +78 -84
  75. package/lib/helper/scripts/blurElement.js +5 -5
  76. package/lib/helper/scripts/focusElement.js +5 -5
  77. package/lib/helper/scripts/highlightElement.js +8 -8
  78. package/lib/helper/scripts/isElementClickable.js +34 -34
  79. package/lib/helper.js +2 -3
  80. package/lib/history.js +23 -19
  81. package/lib/hooks.js +8 -8
  82. package/lib/html.js +94 -104
  83. package/lib/index.js +38 -27
  84. package/lib/listener/config.js +30 -23
  85. package/lib/listener/emptyRun.js +54 -0
  86. package/lib/listener/enhancedGlobalRetry.js +110 -0
  87. package/lib/listener/exit.js +16 -18
  88. package/lib/listener/globalRetry.js +70 -0
  89. package/lib/listener/globalTimeout.js +181 -0
  90. package/lib/listener/helpers.js +76 -51
  91. package/lib/listener/mocha.js +10 -11
  92. package/lib/listener/result.js +11 -0
  93. package/lib/listener/retryEnhancer.js +85 -0
  94. package/lib/listener/steps.js +71 -59
  95. package/lib/listener/store.js +20 -0
  96. package/lib/locator.js +214 -197
  97. package/lib/mocha/asyncWrapper.js +274 -0
  98. package/lib/mocha/bdd.js +167 -0
  99. package/lib/mocha/cli.js +341 -0
  100. package/lib/mocha/factory.js +163 -0
  101. package/lib/mocha/featureConfig.js +89 -0
  102. package/lib/mocha/gherkin.js +231 -0
  103. package/lib/mocha/hooks.js +121 -0
  104. package/lib/mocha/index.js +21 -0
  105. package/lib/mocha/inject.js +46 -0
  106. package/lib/{interfaces → mocha}/scenarioConfig.js +58 -34
  107. package/lib/mocha/suite.js +89 -0
  108. package/lib/mocha/test.js +184 -0
  109. package/lib/mocha/types.d.ts +42 -0
  110. package/lib/mocha/ui.js +242 -0
  111. package/lib/output.js +141 -71
  112. package/lib/parser.js +47 -44
  113. package/lib/pause.js +173 -145
  114. package/lib/plugin/analyze.js +403 -0
  115. package/lib/plugin/{autoLogin.js → auth.js} +178 -79
  116. package/lib/plugin/autoDelay.js +36 -40
  117. package/lib/plugin/coverage.js +131 -78
  118. package/lib/plugin/customLocator.js +22 -21
  119. package/lib/plugin/customReporter.js +53 -0
  120. package/lib/plugin/enhancedRetryFailedStep.js +99 -0
  121. package/lib/plugin/heal.js +101 -110
  122. package/lib/plugin/htmlReporter.js +3648 -0
  123. package/lib/plugin/pageInfo.js +140 -0
  124. package/lib/plugin/pauseOnFail.js +12 -11
  125. package/lib/plugin/retryFailedStep.js +82 -47
  126. package/lib/plugin/screenshotOnFail.js +111 -92
  127. package/lib/plugin/stepByStepReport.js +159 -101
  128. package/lib/plugin/stepTimeout.js +20 -25
  129. package/lib/plugin/subtitles.js +38 -38
  130. package/lib/recorder.js +193 -130
  131. package/lib/rerun.js +94 -49
  132. package/lib/result.js +238 -0
  133. package/lib/retryCoordinator.js +207 -0
  134. package/lib/secret.js +20 -18
  135. package/lib/session.js +95 -89
  136. package/lib/step/base.js +239 -0
  137. package/lib/step/comment.js +10 -0
  138. package/lib/step/config.js +50 -0
  139. package/lib/step/func.js +46 -0
  140. package/lib/step/helper.js +50 -0
  141. package/lib/step/meta.js +99 -0
  142. package/lib/step/record.js +74 -0
  143. package/lib/step/retry.js +11 -0
  144. package/lib/step/section.js +55 -0
  145. package/lib/step.js +18 -329
  146. package/lib/steps.js +54 -0
  147. package/lib/store.js +38 -7
  148. package/lib/template/heal.js +3 -12
  149. package/lib/template/prompts/generatePageObject.js +31 -0
  150. package/lib/template/prompts/healStep.js +13 -0
  151. package/lib/template/prompts/writeStep.js +9 -0
  152. package/lib/test-server.js +334 -0
  153. package/lib/timeout.js +60 -0
  154. package/lib/transform.js +8 -8
  155. package/lib/translation.js +34 -21
  156. package/lib/utils/mask_data.js +47 -0
  157. package/lib/utils.js +411 -228
  158. package/lib/workerStorage.js +37 -34
  159. package/lib/workers.js +532 -296
  160. package/package.json +115 -95
  161. package/translations/de-DE.js +5 -3
  162. package/translations/fr-FR.js +5 -4
  163. package/translations/index.js +22 -12
  164. package/translations/it-IT.js +4 -3
  165. package/translations/ja-JP.js +4 -3
  166. package/translations/nl-NL.js +76 -0
  167. package/translations/pl-PL.js +4 -3
  168. package/translations/pt-BR.js +4 -3
  169. package/translations/ru-RU.js +4 -3
  170. package/translations/utils.js +10 -0
  171. package/translations/zh-CN.js +4 -3
  172. package/translations/zh-TW.js +4 -3
  173. package/typings/index.d.ts +546 -185
  174. package/typings/promiseBasedTypes.d.ts +150 -879
  175. package/typings/types.d.ts +547 -996
  176. package/lib/cli.js +0 -249
  177. package/lib/dirname.js +0 -5
  178. package/lib/helper/Expect.js +0 -425
  179. package/lib/helper/ExpectHelper.js +0 -399
  180. package/lib/helper/MockServer.js +0 -223
  181. package/lib/helper/Nightmare.js +0 -1411
  182. package/lib/helper/Protractor.js +0 -1835
  183. package/lib/helper/SoftExpectHelper.js +0 -381
  184. package/lib/helper/TestCafe.js +0 -1410
  185. package/lib/helper/clientscripts/nightmare.js +0 -213
  186. package/lib/helper/testcafe/testControllerHolder.js +0 -42
  187. package/lib/helper/testcafe/testcafe-utils.js +0 -63
  188. package/lib/interfaces/bdd.js +0 -98
  189. package/lib/interfaces/featureConfig.js +0 -69
  190. package/lib/interfaces/gherkin.js +0 -195
  191. package/lib/listener/artifacts.js +0 -19
  192. package/lib/listener/retry.js +0 -68
  193. package/lib/listener/timeout.js +0 -109
  194. package/lib/mochaFactory.js +0 -110
  195. package/lib/plugin/allure.js +0 -15
  196. package/lib/plugin/commentStep.js +0 -136
  197. package/lib/plugin/debugErrors.js +0 -67
  198. package/lib/plugin/eachElement.js +0 -127
  199. package/lib/plugin/fakerTransform.js +0 -49
  200. package/lib/plugin/retryTo.js +0 -121
  201. package/lib/plugin/selenoid.js +0 -371
  202. package/lib/plugin/standardActingHelpers.js +0 -9
  203. package/lib/plugin/tryTo.js +0 -105
  204. package/lib/plugin/wdio.js +0 -246
  205. package/lib/scenario.js +0 -222
  206. package/lib/ui.js +0 -238
  207. 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 debug from 'debug';
5
-
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 * as event from './event.js';
12
- import * as output from './output.js';
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
- if (!next) return;
36
- return pauseSession();
37
- });
38
- });
39
- recorder.add('Start new session', () => pauseSession(passedObject));
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('OpenAI is enabled! (experimental)')} Write what you want and make OpenAI run it`));
60
- output.print(colors.blue(' Please note, only HTML fragments with interactive elements are sent to OpenAI'));
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.on('line', parseInput);
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
- return new Promise(((resolve) => {
73
- finish = resolve;
74
- // eslint-disable-next-line
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}'];`); // eslint-disable-line no-eval
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
- // eslint-disable-next-line
109
- const locate = global.locate; // enable locate in this context
110
- // eslint-disable-next-line
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.output.styles.error(' ERROR '), 'Can\'t get HTML context', err.stack);
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
- // aiAssistant.mockResponse("```js\nI.click('Sign in');\n```");
131
- const spinner = ora("Processing OpenAI request...").start();
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.then(async () => {
143
- const cmd = getCmd();
144
- if (!cmd) return;
145
- return eval(cmd); // eslint-disable-line no-eval
146
- }).catch((err) => {
147
- debug(err);
148
- if (isAiCommand) return;
149
- if (!lastError) output.print(output.output.styles.error(' ERROR '), err.message);
150
- debug(err.stack)
151
-
152
- lastError = err.message;
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); // eslint-disable-line
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.output.styles.success(' OK '), cmd);
175
+ output.print(output.styles.success(' OK '), cmd)
164
176
  }
165
177
  if (cmd?.startsWith('I.grab')) {
166
- output.print(output.output.styles.debug(val));
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); // add command to history when successful
186
+ history.push(cmd) // add command to history when successful
170
187
  } catch (err) {
171
- if (!lastError) output.print(output.output.styles.error(' ERROR '), err.message);
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((err) => {
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.output.styles.error(' FAIL '), msg);
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(((resolve) => {
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
- const hits = completions.filter((c) => {
202
- if (c.indexOf(line) === 0) {
203
- return c;
204
- }
205
- return null;
206
- });
207
- return [hits && hits.length ? hits : completions, line];
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 }