From 5b448c78e521f8b54c713fd5e10b94f28a990b40 Mon Sep 17 00:00:00 2001 From: Jani Mikkonen Date: Sun, 11 Mar 2018 10:42:43 +0200 Subject: [PATCH] feat: Add flake.params.iteration Passes flake.params.iteration to protractor This value can then be used to distinquish between each iteration of protractor run. It can then be used to create dynamic files & paths in protractors onprepare or path builder. Also includes tests --- src/index.js | 2 +- test/unit/index.test.js | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/index.js b/src/index.js index 355fda1..dd9b3da 100644 --- a/src/index.js +++ b/src/index.js @@ -47,6 +47,7 @@ export default function (options = {}, callback = function noop () {}) { let output = '' let protractorArgs = [parsedOptions.protractorPath].concat(parsedOptions.protractorArgs) + protractorArgs.push('--params.flake.iteration', testAttempt) if (retry) { protractorArgs.push('--params.flake.retry', true) } @@ -55,7 +56,6 @@ export default function (options = {}, callback = function noop () {}) { protractorArgs = filterArgs(protractorArgs) protractorArgs.push('--specs', specFiles.join(',')) } - let protractor = spawn( parsedOptions.nodeBin, protractorArgs, diff --git a/test/unit/index.test.js b/test/unit/index.test.js index af6992b..291dae4 100644 --- a/test/unit/index.test.js +++ b/test/unit/index.test.js @@ -43,7 +43,7 @@ describe('Protractor Flake', () => { it('uses node to run protractor', () => { protractorFlake() - expect(spawnStub).to.have.been.calledWith('node', [pathToProtractor()]) + expect(spawnStub).to.have.been.calledWith('node', [pathToProtractor(), '--params.flake.iteration', 1]) }) context('failed specs', () => { @@ -91,8 +91,7 @@ describe('Protractor Flake', () => { spawnStub.dataCallback(failedSingleTestOutput) spawnStub.endCallback(1) - - expect(spawnStub).to.have.been.calledWith('node', [pathToProtractor(), '--params.flake.retry', true, '--specs', '/tests/a-flakey.test.js']) + expect(spawnStub).to.have.been.calledWith('node', [pathToProtractor(), '--params.flake.iteration', 2, '--params.flake.retry', true, '--specs', '/tests/a-flakey.test.js']) }) it('isolates individual failed specs from jasmine-spec-reporter output', () => { @@ -101,7 +100,7 @@ describe('Protractor Flake', () => { spawnStub.dataCallback(failedJasmineSpecReporterTestOutput) spawnStub.endCallback(1) - expect(spawnStub).to.have.been.calledWith('node', [pathToProtractor(), '--params.flake.retry', true, '--specs', '/tests/flakey.test.js']) + expect(spawnStub).to.have.been.calledWith('node', [pathToProtractor(), '--params.flake.iteration', 2, '--params.flake.retry', true, '--specs', '/tests/flakey.test.js']) }) it('isolates individual failed specs for sharded jasmine-spec-reporter output', () => { @@ -110,7 +109,7 @@ describe('Protractor Flake', () => { spawnStub.dataCallback(failedShardedJasmineSpecReporterTestOutput) spawnStub.endCallback(1) - expect(spawnStub).to.have.been.calledWith('node', [pathToProtractor(), '--params.flake.retry', true, '--specs', '/tests/flakey.test.js']) + expect(spawnStub).to.have.been.calledWith('node', [pathToProtractor(), '--params.flake.iteration', 2, '--params.flake.retry', true, '--specs', '/tests/flakey.test.js']) }) it('isolates failed specs for sharded protractor output', () => { @@ -119,7 +118,7 @@ describe('Protractor Flake', () => { spawnStub.dataCallback(failedShardedTestOutput) spawnStub.endCallback(1) - expect(spawnStub).to.have.been.calledWith('node', [pathToProtractor(), '--params.flake.retry', true, '--specs', '/tests/a-flakey.test.js,/tests/another-flakey.test.js']) + expect(spawnStub).to.have.been.calledWith('node', [pathToProtractor(), '--params.flake.iteration', 2, '--params.flake.retry', true, '--specs', '/tests/a-flakey.test.js,/tests/another-flakey.test.js']) }) context('with --suite in protractorArgs', function () { @@ -139,6 +138,7 @@ describe('Protractor Flake', () => { expect(spawnStub).to.have.been.calledWith('node', [ pathToProtractor(), '--should-remain=yes', + '--params.flake.iteration', 2, '--params.flake.retry', true, '--specs', '/tests/a-flakey.test.js,/tests/another-flakey.test.js' ]) @@ -150,7 +150,7 @@ describe('Protractor Flake', () => { protractorArgs: ['--suite=fail'] }) - expect(spawnStub).to.have.been.calledWith('node', [pathToProtractor(), '--suite=fail']) + expect(spawnStub).to.have.been.calledWith('node', [ pathToProtractor(), '--suite=fail', '--params.flake.iteration', 1 ]) }) }) @@ -171,6 +171,7 @@ describe('Protractor Flake', () => { expect(spawnStub).to.have.been.calledWith('node', [ pathToProtractor(), '--should-remain=yes', + '--params.flake.iteration', 2, '--params.flake.retry', true, '--specs', '/tests/a-flakey.test.js,/tests/another-flakey.test.js' ]) @@ -182,7 +183,7 @@ describe('Protractor Flake', () => { protractorArgs: ['--specs=specs/fail', '--specs', 'specs/fail'] }) - expect(spawnStub).to.have.been.calledWith('node', [pathToProtractor(), '--specs=specs/fail', '--specs', 'specs/fail']) + expect(spawnStub).to.have.been.calledWith('node', [pathToProtractor(), '--specs=specs/fail', '--specs', 'specs/fail', '--params.flake.iteration', 1]) }) }) }) @@ -191,25 +192,25 @@ describe('Protractor Flake', () => { it('allows a different path for protractor by using protractorPath option', () => { protractorFlake({protractorPath: '/arbitrary/path/to/protractor'}) - expect(spawnStub).to.have.been.calledWith('node', ['/arbitrary/path/to/protractor']) + expect(spawnStub).to.have.been.calledWith('node', ['/arbitrary/path/to/protractor', '--params.flake.iteration', 1]) }) it('allows a different path for node by using nodeBin option', () => { protractorFlake({nodeBin: '/path/node'}) - expect(spawnStub).to.have.been.calledWith('/path/node', [pathToProtractor()]) + expect(spawnStub).to.have.been.calledWith('/path/node', [pathToProtractor(), '--params.flake.iteration', 1]) }) it('passes protractorArgs to spawned protractor process', () => { protractorFlake({protractorArgs: ['--suite=fail']}) - expect(spawnStub).to.have.been.calledWithMatch('node', [pathToProtractor(), '--suite=fail']) + expect(spawnStub).to.have.been.calledWithMatch('node', [pathToProtractor(), '--suite=fail', '--params.flake.iteration', 1]) }) it('uses protractorSpawnOptions for spawned protractor process', () => { protractorFlake({protractorSpawnOptions: { cwd: './' }}) - expect(spawnStub).to.have.been.calledWithMatch('node', [pathToProtractor()], { cwd: './' }) + expect(spawnStub).to.have.been.calledWithMatch('node', [pathToProtractor(), '--params.flake.iteration', 1], { cwd: './' }) }) context('color option', (options) => {