Skip to content
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

Merged
merged 1 commit into from Mar 15, 2018
Merged

feat: wrap tests running in command #241

merged 1 commit into from Mar 15, 2018

Conversation

rostik404
Copy link
Contributor

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",
Copy link
Contributor Author

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

Copy link
Contributor

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();
Copy link
Contributor

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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше сидеть на какой-то конкретной ветке, а не на мастере. Мало ли - решим еще чего-то поправить

});

afterEach(() => sandbox.restore());

it('should show information about config overriding on "--help"', () => {
onParse((parser) => parser.emit('--help'));
process.argv.push('--help');
hermioneCli.run();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hermioneCli.run() возвращает промис. Ты его здесь не дожидаешься

onParse((parser) => parser.emit('--help'));
process.argv.push('--help');
hermioneCli.run();
process.argv.pop();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

если на строчке выше тест упадет, то этого не случится, и будет у тебя process.argv модифицированный

Copy link
Contributor

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))
Copy link
Contributor

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)))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tormozz48 ты реально считаешь что так будет понятнее? о.О

onParse((parser) => parser.emit('--help'));
process.argv.push('--help');
hermioneCli.run();
process.argv.pop();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, тебе нужно это разруливать на уровне хуков в тестах или добавить try {} finally {}

onParse((parser) => parser.config = '.conf.hermione.js');
process.argv.push('--config', '.conf.hermione.js');
hermioneCli.run();
process.argv = process.argv.slice(0, -2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

См. замечание выше

@rostik404 rostik404 force-pushed the run-test-command branch 2 times, most recently from 438f773 to 20e21c9 Compare March 14, 2018 22:18
fn(this);
parser = fn(this);

actionFn && actionFn(_.get(parser, 'args'));
Copy link
Contributor

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);

Command.prototype.action.callsFake((fn) => actionFn = fn);
};

const run_ = async (promise = q(true)) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

этот дефолтный аргумент будет шариться между всеми вызовами run_

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async, но внутри нет await. Забыл await promise;? Вообще надо бы проверить, что это будет работать

@@ -12,16 +13,22 @@ const any = sinon.match.any;

describe('cli', () => {
const sandbox = sinon.sandbox.create();
let parser;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parser можно объявить внутри onParse. В дискрайбе он не используется

sandbox.stub(Command.prototype, 'action');
sandbox.stub(Hermione.prototype, 'run').resolves();

onParse();
Copy link
Contributor

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 использовать?

Немного муторно, конечно, но функция выше легче для восприятия станет, как по мне. Но это не критично, я просто предлагаю варианты)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А вообще, onParse() здесь нужен?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужен, в каждом тесте нужно застабать парсер, в beforeEach это для тех тестов, которым не нужна специфичная функция парсинга

Copy link
Contributor

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 () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async тут не используется
и ниже в нескольких местах тоже не используется

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});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await actionPromise?

it('should not pass any browsers if they were not specified from cli', async () => {
hermioneCli.run();

assert.calledWithMatch(Hermione.prototype.run, any, {browsers: undefined});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await actionPromise?

});

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));
Copy link
Contributor

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'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Забыл на rejects поменять или специально?

Copy link
Contributor Author

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sinon.sandboxCreate() побыстрее работает )

@@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а чего ты перенес этот стаб сюда? Удобно же было, что все методы гермионы стабаются рядышком.


if (Command.prototype.action.lastCall) {
const actionFn = Command.prototype.action.lastCall.args[0];
actionPromise = actionFn(_.get(parser, 'args'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выше parser = fn(this) || {}; и здесь не нужен будет _.get

@@ -12,16 +13,22 @@ const any = sinon.match.any;

describe('cli', () => {
const sandbox = sinon.sandbox.create();
let parser;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

переменную нужно ниже объявить, в onParse

@rostik404 rostik404 merged commit 735097a into master Mar 15, 2018
@rostik404 rostik404 deleted the run-test-command branch March 15, 2018 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants