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
feat: wrap tests running in command #241
Conversation
package.json
Outdated
@@ -35,7 +35,7 @@ | |||
"bluebird-q": "^2.1.1", | |||
"chalk": "^1.1.1", | |||
"clear-require": "^1.0.1", | |||
"commander": "^2.12.2", | |||
"commander": "gemini-testing/commander.js", |
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.
Сидим на форке, пока не вольется PR tj/commander.js#778
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.
лучше сидеть на какой-то конкретной ветке, а не на мастере. Мало ли - решим еще чего-то поправить
lib/cli/index.js
Outdated
logger.error(err.stack || err); | ||
process.exit(1); | ||
}) | ||
.done(); |
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.
Зачем здесь done
?
package.json
Outdated
@@ -35,7 +35,7 @@ | |||
"bluebird-q": "^2.1.1", | |||
"chalk": "^1.1.1", | |||
"clear-require": "^1.0.1", | |||
"commander": "^2.12.2", | |||
"commander": "gemini-testing/commander.js", |
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.
лучше сидеть на какой-то конкретной ветке, а не на мастере. Мало ли - решим еще чего-то поправить
test/lib/cli/index.js
Outdated
}); | ||
|
||
afterEach(() => sandbox.restore()); | ||
|
||
it('should show information about config overriding on "--help"', () => { | ||
onParse((parser) => parser.emit('--help')); | ||
process.argv.push('--help'); | ||
hermioneCli.run(); |
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.
hermioneCli.run()
возвращает промис. Ты его здесь не дожидаешься
test/lib/cli/index.js
Outdated
onParse((parser) => parser.emit('--help')); | ||
process.argv.push('--help'); | ||
hermioneCli.run(); | ||
process.argv.pop(); |
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.
если на строчке выше тест упадет, то этого не случится, и будет у тебя process.argv
модифицированный
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.
Да, тебе нужно это разруливать на уровне хуков в тестах или добавить try {} finally {}
lib/cli/index.js
Outdated
grep: program.grep, | ||
updateRefs: program.updateRefs | ||
}) | ||
.then((success) => process.exit(success ? 0 : 1)) |
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.
.then((success) => process.exit(Number(!success)))
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.
@tormozz48 ты реально считаешь что так будет понятнее? о.О
test/lib/cli/index.js
Outdated
onParse((parser) => parser.emit('--help')); | ||
process.argv.push('--help'); | ||
hermioneCli.run(); | ||
process.argv.pop(); |
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.
Да, тебе нужно это разруливать на уровне хуков в тестах или добавить try {} finally {}
test/lib/cli/index.js
Outdated
onParse((parser) => parser.config = '.conf.hermione.js'); | ||
process.argv.push('--config', '.conf.hermione.js'); | ||
hermioneCli.run(); | ||
process.argv = process.argv.slice(0, -2); |
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.
См. замечание выше
438f773
to
20e21c9
Compare
test/lib/cli/index.js
Outdated
fn(this); | ||
parser = fn(this); | ||
|
||
actionFn && actionFn(_.get(parser, 'args')); |
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.
const actionFn = Command.prototype.action.lastCall.args[0];
actionFn && actionFn(parser.args);
test/lib/cli/index.js
Outdated
Command.prototype.action.callsFake((fn) => actionFn = fn); | ||
}; | ||
|
||
const run_ = async (promise = q(true)) => { |
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.
этот дефолтный аргумент будет шариться между всеми вызовами run_
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.
async
, но внутри нет await
. Забыл await promise;
? Вообще надо бы проверить, что это будет работать
test/lib/cli/index.js
Outdated
@@ -12,16 +13,22 @@ const any = sinon.match.any; | |||
|
|||
describe('cli', () => { | |||
const sandbox = sinon.sandbox.create(); | |||
let parser; |
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.
parser
можно объявить внутри onParse
. В дискрайбе он не используется
test/lib/cli/index.js
Outdated
sandbox.stub(Command.prototype, 'action'); | ||
sandbox.stub(Hermione.prototype, 'run').resolves(); | ||
|
||
onParse(); |
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.
Меня выше fn = _.noop
и _.get(parser, 'args')
сильно запутали. Может лучше написатьonParse(() => ({}))
, и ниже по коду везде _.set
использовать?
Немного муторно, конечно, но функция выше легче для восприятия станет, как по мне. Но это не критично, я просто предлагаю варианты)
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.
А вообще, onParse()
здесь нужен?
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.
Нужен, в каждом тесте нужно застабать парсер, в beforeEach это для тех тестов, которым не нужна специфичная функция парсинга
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.
Он же и так застабан будет. Просто нужно ли специфицировать, что именно будет при парсинге происходить?
it('should create Hermione instance', () => { | ||
return hermioneCli.run() | ||
.then(() => assert.calledOnce(Hermione.create)); | ||
it('should create Hermione instance', async () => { |
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.
async
тут не используется
и ниже в нескольких местах тоже не используется
test/lib/cli/index.js
Outdated
it('should not pass any grep rule if it was not specified from cli', async () => { | ||
hermioneCli.run(); | ||
|
||
assert.calledWithMatch(Hermione.prototype.run, any, {grep: undefined}); |
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.
await actionPromise
?
test/lib/cli/index.js
Outdated
it('should not pass any browsers if they were not specified from cli', async () => { | ||
hermioneCli.run(); | ||
|
||
assert.calledWithMatch(Hermione.prototype.run, any, {browsers: undefined}); |
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.
await actionPromise
?
test/lib/cli/index.js
Outdated
}); | ||
|
||
it('should exit with code 1 if tests fail', () => { | ||
it('should exit with code 1 if tests fail', async () => { | ||
Hermione.prototype.run.returns(q(false)); |
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.
Забыл на resolves
поменять или специально?
}); | ||
|
||
it('should log an error on reject if stack does not exist', () => { | ||
it('should log an error on reject if stack does not exist', async () => { | ||
Hermione.prototype.run.returns(q.reject('some-error')); |
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.
Забыл на rejects
поменять или специально?
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.
Обсудили голосом
@@ -12,16 +13,22 @@ const any = sinon.match.any; | |||
|
|||
describe('cli', () => { | |||
const sandbox = sinon.sandbox.create(); |
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.
sinon.sandboxCreate()
побыстрее работает )
test/lib/cli/index.js
Outdated
@@ -30,137 +37,163 @@ describe('cli', () => { | |||
sandbox.stub(process, 'exit'); | |||
|
|||
sandbox.stub(Command.prototype, 'parse'); | |||
sandbox.stub(Command.prototype, 'action'); | |||
sandbox.stub(Hermione.prototype, 'run').resolves(); |
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.
а чего ты перенес этот стаб сюда? Удобно же было, что все методы гермионы стабаются рядышком.
test/lib/cli/index.js
Outdated
|
||
if (Command.prototype.action.lastCall) { | ||
const actionFn = Command.prototype.action.lastCall.args[0]; | ||
actionPromise = actionFn(_.get(parser, 'args')); |
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.
выше parser = fn(this) || {};
и здесь не нужен будет _.get
test/lib/cli/index.js
Outdated
@@ -12,16 +13,22 @@ const any = sinon.match.any; | |||
|
|||
describe('cli', () => { | |||
const sandbox = sinon.sandbox.create(); | |||
let parser; |
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.
переменную нужно ниже объявить, в onParse
f9d8cb4
to
b247f10
Compare
b247f10
to
fcbd8bf
Compare
/cc @j0tunn @sipayRT @DudaGod @eGavr