-
-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added suspending update renderer for task #136
base: master
Are you sure you want to change the base?
Changes from 7 commits
5a1272a
470a8b8
c0317c7
e440c18
7a74f5d
4b2c801
f2e2750
8455f63
6eeb4c4
47fb5a2
1cf0f10
0327ff7
607a7f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import {serial as test} from 'ava'; | ||
import delay from 'delay'; | ||
import Listr from '..'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you edit these files? They're out of the scope of this PR anyways, and the imports were fine the way they were. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes come from |
||
import SimpleRenderer from './fixtures/simple-renderer'; | ||
import {testOutput} from './fixtures/utils'; | ||
import Listr from '..'; | ||
|
||
const tasks = [ | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import {serial as test} from 'ava'; | ||
import sinon from 'sinon'; | ||
|
||
const mockery = require('mockery'); | ||
|
||
const logUpdateApi = { | ||
main(text) { | ||
console.log(text); | ||
} | ||
}; | ||
logUpdateApi.main.clear = function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should create a noop function (e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I imported the |
||
}; | ||
|
||
logUpdateApi.main.done = function () { | ||
}; | ||
|
||
const mock = sinon.mock(logUpdateApi); | ||
|
||
function getTasks() { | ||
// Require is necessary at this position, otherwise mockery is not working correctly | ||
const Listr = require('..'); | ||
const tasks = new Listr([ | ||
{ | ||
title: 'not suspending task', | ||
task: () => { | ||
return new Promise(resolve => { | ||
setTimeout(() => { | ||
resolve('predefined output'); | ||
}, 150); | ||
}); | ||
} | ||
}, | ||
{ | ||
title: 'suspending task', | ||
task: () => { | ||
return new Promise(resolve => { | ||
setTimeout(() => { | ||
resolve('predefined output'); | ||
}, 4000); | ||
}); | ||
}, | ||
options: {suspendUpdateRenderer: true} | ||
} | ||
]); | ||
|
||
return tasks; | ||
} | ||
|
||
test.before(() => { | ||
/* One time for the first task, | ||
one time when both tasks are finished | ||
*/ | ||
mock.expects('main').twice(); | ||
mockery.registerAllowable('..'); | ||
mockery.registerMock('log-update', logUpdateApi.main); | ||
mockery.enable({useCleanCache: true, warnOnUnregistered: false}); | ||
}); | ||
|
||
test('should suspend second task', async t => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't test use-cases where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My intention was to create two task. The first task without the option What tests you thought of? Integration-tests, which ask for user input or tests, which mock There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I thought of is a test case in which the suspension is actually required, meaning that the test won't pass if the task isn't suspended (and only passes if it is). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added now a custom renderer mock, which output is excatly verified. It only passes, if suspension is activated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry to keep bothering you, but this is still not what I meant in my comments above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem isn't, that the task can't receive the user-input from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @itaisteinherz |
||
await getTasks().run(); | ||
|
||
t.true(mock.verify()); | ||
}); | ||
|
||
test.after(() => { | ||
mockery.disable(); | ||
mockery.deregisterAll(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is moot. You can already access it as
this.task.options
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but
this.task
can be just a function.task.options
refers to input-variabletask
given in the constructor and not tothis.task
. We will need here a separate variable to store the options.