Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 8544392

Browse files
committed
fix for glitchy tab completion test
Fixes #699
1 parent 6ef6443 commit 8544392

File tree

4 files changed

+53
-36
lines changed

4 files changed

+53
-36
lines changed

app/content/js/repl.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corporation
2+
* Copyright 2017-18 IBM Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -514,6 +514,23 @@ const emptyPromise = () => {
514514
return emptyPromise
515515
}
516516

517+
/**
518+
* Remove any .repl-temporary structures from the given dom
519+
*
520+
*/
521+
const removeAnyTemps = block => {
522+
const temps = block.querySelectorAll('.repl-temporary')
523+
524+
for (let idx = 0; idx < temps.length; idx++) {
525+
const temp = temps[idx]
526+
if (temp.parentNode) {
527+
temp.parentNode.removeChild(temp)
528+
}
529+
}
530+
531+
return block
532+
}
533+
517534
/** turn --foo into foo and -f into f */
518535
const unflag = opt => opt.replace(/^[-]+/,'')
519536

@@ -561,6 +578,12 @@ self.exec = (commandUntrimmed, execOptions) => {
561578
nextBlock = execOptions && execOptions.nextBlock
562579
}
563580

581+
if (nextBlock) {
582+
// remove any .repl-temporary that might've come along for the
583+
// ride when we cloned the current block
584+
removeAnyTemps(nextBlock)
585+
}
586+
564587
// blank line, after removing comments?
565588
const command = commandUntrimmed.trim().replace(patterns.commentLine, '')
566589
if (!command) {
@@ -973,7 +996,7 @@ self.paste = event => {
973996
self.doCancel = () => {
974997
debug('doCancel')
975998

976-
const block = ui.getCurrentProcessingBlock() || ui.getCurrentBlock(),
999+
const block = removeAnyTemps(ui.getCurrentProcessingBlock() || ui.getCurrentBlock()),
9771000
nextBlock = block.cloneNode(true),
9781001
nextBlockPrompt = ui.getPrompt(nextBlock)
9791002

app/plugins/ui/commands/tab-completion.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,17 @@ const listenForUpDown = prompt => {
107107

108108
const previousKeyDown = prompt.onkeydown
109109
prompt.onkeydown = evt => { // keydown is necessary for evt.preventDefault() to work; keyup would otherwise also work
110-
if (evt.keyCode === ui.keys.DOWN) {
110+
const char = evt.keyCode
111+
112+
if (char === ui.keys.DOWN) {
111113
moveTo('nextSibling', evt)
112-
} else if (evt.keyCode === ui.keys.UP) {
114+
115+
} else if (char === ui.keys.UP) {
113116
moveTo('previousSibling', evt)
117+
118+
} else if (char === ui.keys.C && event.ctrlKey) {
119+
// Ctrl+C, cancel
120+
repl.doCancel()
114121
}
115122
}
116123

@@ -143,22 +150,6 @@ const listenForEscape = prompt => {
143150
return cleanup
144151
}
145152

146-
/** safeguard: only one tab completion temporary at a time, please */
147-
const cleaner = () => {
148-
const safeguard = document.querySelectorAll('.tab-completion-temporary')
149-
for (let idx = 0; idx < safeguard.length; idx++) {
150-
try {
151-
console.error('removing glitch')
152-
const old = safeguard[idx]
153-
if (old.parentNode) {
154-
old.parentNode.removeChid(safeguard)
155-
}
156-
} catch (err) {
157-
console.error('error removing glitch', err)
158-
}
159-
}
160-
}
161-
162153
/**
163154
* Make a container UI for tab completions
164155
*
@@ -167,7 +158,13 @@ const makeCompletionContainer = (block, prompt, partial, dirname, lastIdx) => {
167158
const input = block.querySelector('input')
168159

169160
const temporaryContainer = document.createElement('div')
170-
temporaryContainer.className = 'tab-completion-temporary scrollable fade-in'
161+
temporaryContainer.className = 'tab-completion-temporary scrollable repl-temporary'
162+
163+
if (!process.env.RUNNING_SHELL_TEST) {
164+
// see shell issue #699; chrome seems not to play the fade-in
165+
// animation when the window is offscreen
166+
temporaryContainer.classList.add('fade-in')
167+
}
171168

172169
// determine pixel width of current input value
173170
const tmp = document.createElement('div')

tests/lib/ui.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ exports.expectSubset = struct1 => string => {
298298
}
299299

300300
/** is the given actual array the same as the given expected array? */
301-
exports.expectArray = expected => actual => {
301+
exports.expectArray = (expected, failFast=true) => actual => {
302302
if (!Array.isArray(actual)) {
303303
// webdriver.io's getText will return a singleton if there is only one match
304304
actual = [actual]
@@ -313,7 +313,11 @@ exports.expectArray = expected => actual => {
313313
console.error(`array mismatch; expected=${expected} actual=${actual}`)
314314
}
315315

316-
assert.ok(ok)
316+
if (failFast) {
317+
assert.ok(ok)
318+
} else {
319+
return ok
320+
}
317321
}
318322

319323
/**

tests/tests/passes/02/tab-completion.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,7 @@ describe('Tab completion', function() {
104104
}
105105
})
106106
.catch(err => this.app.client.execute('repl.doCancel()') // clear the line
107-
.then(() => {
108-
if (iter < 5) {
109-
console.error('retry', iter)
110-
return tabbyWithOptions(app, partial, expected, full, { click, nTabs, expectOK, iter: iter + 1 })
111-
} else {
112-
return common.oops(this)(err)
113-
}
114-
}))
107+
.then(() => common.oops(this)(err)))
115108
}
116109

117110
const tabbyWithOptionsThenCancel = (app, partial, expected) => app.client.waitForExist(ui.selectors.CURRENT_PROMPT_BLOCK)
@@ -131,11 +124,11 @@ describe('Tab completion', function() {
131124
it('should have an active repl', () => cli.waitForRepl(this.app))
132125

133126
// tab completion with options, then click on the second (idx=1) entry of the expected cmpletion list
134-
it('should tab complete local file path', () => tabbyWithOptions(this.app,
135-
'lls data/com',
136-
options,
137-
'lls data/composer-source/',
138-
{ click: 1 }))
127+
it('should tab complete local file path with options', () => tabbyWithOptions(this.app,
128+
'lls data/com',
129+
options,
130+
'lls data/composer-source/',
131+
{ click: 1 }))
139132

140133
it('should tab complete the data directory', () => tabby(this.app, 'lls da', 'lls data/'))
141134
it('should tab complete the data/fsm.js file', () => tabby(this.app, 'lls data/fsm.js', 'lls data/fsm.json'))

0 commit comments

Comments
 (0)