Skip to content
This repository has been archived by the owner on Nov 3, 2019. It is now read-only.

Commit

Permalink
fix(plugin-example): fix multiline output parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed Apr 2, 2016
1 parent 3552a3b commit 991de84
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions plugins/mos-plugin-example/lib/hook-console-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ function hookConsoleLog (filePath) {
console.log = function () {
const site = callsiteForFile(filePath)

originalLog({
originalLog('\n$\n' + JSON.stringify({
message: getRealConsoleOutput.apply(null, arguments),
line: site.line - 1,
column: site.column,
})
}))
}
}

Expand Down
6 changes: 4 additions & 2 deletions plugins/mos-plugin-example/lib/stdout-to-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ function stdoutToComments (filePath) {
cp.stderr.setEncoding('utf8')
cp.stdout.on('data', data => {
try {
splitIntoLines(data)
.forEach(line => eval(`outputs.push(${line})`)) // eslint-disable-line no-eval
data.split('\n$\n')
.filter(outputJSON => !!outputJSON)
.map(outputJSON => JSON.parse(outputJSON))
.forEach(outputInfo => outputs.push(outputInfo))
} catch (err) {
failed = true
reject(err)
Expand Down
15 changes: 15 additions & 0 deletions plugins/mos-plugin-example/lib/stdout-to-comments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,19 @@ describe('stdoutToComments', () => {
].join('\n'))
)
})

it('should output multiline results', () => {
return inlineStdoutToComments([
'console.log(JSON.stringify({ foo: 1, bar: 2 }, null, 2))',
].join('\n'))
.then(actual =>
expect(actual).to.eq([
'console.log(JSON.stringify({ foo: 1, bar: 2 }, null, 2))',
'//> {',
'// "foo": 1,',
'// "bar": 2',
'// }',
].join('\n'))
)
})
})

0 comments on commit 991de84

Please sign in to comment.