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

Commit bf9ec5c

Browse files
Kerry Changstarpit
authored andcommitted
Bug fixes: wskflow drops user options when refreshes, and incorrectly passed in system options, causing a crash
removed a typo
1 parent 1eb1971 commit bf9ec5c

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

app/plugins/modules/composer/lib/composer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ const optionsToString = options => {
678678

679679
return str
680680
}
681-
681+
exports.optionsToString = optionsToString
682682
/**
683683
* Entity view modes
684684
*

app/plugins/modules/composer/lib/viz.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
const debug = require('debug')('app preview')
1818
debug('loading')
1919

20-
const { isValidFSM, wskflow, zoomToFitButtons, vizAndfsmViewModes, codeViewMode, handleError } = require('./composer'),
20+
const { isValidFSM, wskflow, zoomToFitButtons, vizAndfsmViewModes, codeViewMode, handleError, optionsToString } = require('./composer'),
2121
badges = require('./badges'),
2222
{ readFSMFromDisk, compileToFSM } = require('./create-from-source'),
2323
messages = require('./messages'),
@@ -111,14 +111,19 @@ module.exports = (commandTree, prequire) => {
111111
entity.type = 'actions'
112112
}
113113

114-
if(options.alreadyWatching && entity.type === 'custom'){
114+
if(execOptions.alreadyWatching){
115115
// in filewatch mode (alreadyWatching), command echo is set to false
116-
// calling ui.showCustom as the main repl does not do anything for custom type entity when echo is false
117-
ui.showCustom(entity);
118-
}
116+
// calling ui.showCustom as the main repl does not do anything for custom type entity when echo is false
117+
if(entity.type === 'custom'){
118+
ui.showCustom(entity);
119+
}
120+
else{
121+
ui.showEntity(entity, { show: 'fsm' })
122+
}
123+
}
119124
else{
120-
resolve(entity);
121-
}
125+
resolve(entity)
126+
}
122127

123128
}
124129
fsmPromise.then(formatForUser(defaultMode))
@@ -127,14 +132,13 @@ module.exports = (commandTree, prequire) => {
127132
// start rendering an empty JSON
128133
formatForUser(defaultMode)({})
129134

130-
} else if (options.alreadyWatching) {
135+
} else if (execOptions.alreadyWatching) {
131136
// we already have the sidecar open to this file,
132137
// so we can report the error in the sidecar
133138

134139
// createFromSource returns error as either an object that's {fsm:errMsg, code:originalCode}, or just the errMsg string
135140
// here we check the error format and send the correct input to formatForUser/handleError
136141
// in sidecar, error message shows in the fsm (JSON) tab. code tab shows the user's js code (if existed).
137-
138142
if(err.fsm)
139143
formatForUser('fsm')(err);
140144
else
@@ -176,18 +180,14 @@ module.exports = (commandTree, prequire) => {
176180
delete options.e
177181

178182
debug('environment', environment)
179-
}
180-
181-
if(execOptions.alreadyWatching){
182-
options.alreadyWatching = execOptions.alreadyWatching;
183-
}
183+
}
184184

185185
render(input, options, execOptions).then(resolve, reject)
186186

187187
// and set up a file watcher to re-render upon change of the file
188188
if (!execOptions || !execOptions.alreadyWatching) {
189189
chokidar.watch(expandHomeDir(input)).on('change', path => {
190-
repl.pexec(`preview ${path}`, { echo: false, alreadyWatching: true })
190+
repl.pexec(`preview ${path} ${optionsToString(options)}`, { echo: false, alreadyWatching: true, noHistory: true })
191191
})
192192
}
193193
})

tests/tests/passes/07/wskflow-tests.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,28 @@ describe('app preview should actively watching an external file', function() {
118118
.then(verifyNodeExists('c'))
119119
.catch(common.oops(this)))
120120

121+
// should be able to switch JSON tab and switch back
122+
it('should switch to the JSON tab', () => this.app.client.click(ui.selectors.SIDECAR_MODE_BUTTON('fsm'))
123+
.then(() => this.app.client.click(ui.selectors.SIDECAR_MODE_BUTTON('visualization')))
124+
.then(() => verifyNodeExists('a')(this.app))
125+
.then(verifyNodeExists('c'))
126+
.catch(common.oops(this)))
127+
// update file again, and verify that preview updates too
128+
it('should update the temp file to composer.sequence("a", "b")', () => {
129+
return new Promise((resolve, reject) => {
130+
fs.writeFile(tempFileName, `composer.sequence("a", "b")`, (err) => {
131+
if(err)
132+
reject(err);
133+
else
134+
resolve(true);
135+
});
136+
});
137+
});
138+
it('should update preview', () => this.app.client.waitForVisible(ui.selectors.SIDECAR_CUSTOM_CONTENT)
139+
.then(() => verifyNodeExists('a')(this.app))
140+
.then(verifyNodeExists('b'))
141+
.catch(common.oops(this)))
142+
121143
it('should delete the temp file', () => {
122144
return new Promise((resolve, reject) => {
123145
fs.unlink(tempFileName, (err) => {

0 commit comments

Comments
 (0)