Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: read tests sequentially in worker
- Loading branch information
Showing
7 changed files
with
283 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
const {EventEmitter} = require('events'); | ||
const {passthroughEvent} = require('../../core/events/utils'); | ||
const SimpleTestParser = require('./simple-test-parser'); | ||
const RunnerEvents = require('../constants/runner-events'); | ||
const fastq = require('fastq'); | ||
|
||
module.exports = class SequenceTestParser extends EventEmitter { | ||
static create(...args) { | ||
return new this(...args); | ||
} | ||
|
||
constructor(config) { | ||
super(); | ||
|
||
this._parser = SimpleTestParser.create(config); | ||
passthroughEvent(this._parser, this, [ | ||
RunnerEvents.BEFORE_FILE_READ, | ||
RunnerEvents.AFTER_FILE_READ | ||
]); | ||
|
||
this._queue = fastq.promise((fn) => fn(), 1); | ||
} | ||
|
||
async parse({file, browserId}) { | ||
return this._queue.push(() => this._parser.parse({file, browserId})); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const {EventEmitter} = require('events'); | ||
const {passthroughEvent} = require('../../core/events/utils'); | ||
const TestParser = require('../../test-reader/mocha-test-parser'); | ||
const RunnerEvents = require('../constants/runner-events'); | ||
|
||
module.exports = class SimpleTestParser extends EventEmitter { | ||
static create(...args) { | ||
return new this(...args); | ||
} | ||
|
||
constructor(config) { | ||
super(); | ||
|
||
this._config = config; | ||
|
||
TestParser.prepare(); | ||
} | ||
|
||
async parse({file, browserId}) { | ||
const parser = TestParser.create(browserId, this._config); | ||
|
||
passthroughEvent(parser, this, [ | ||
RunnerEvents.BEFORE_FILE_READ, | ||
RunnerEvents.AFTER_FILE_READ | ||
]); | ||
|
||
parser.applyConfigController(); | ||
|
||
await parser.loadFiles(file); | ||
|
||
return parser.parse(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
'use strict'; | ||
|
||
const SequenceTestParser = require('lib/worker/runner/sequence-test-parser'); | ||
const SimpleTestParser = require('lib/worker/runner/simple-test-parser'); | ||
const RunnerEvents = require('lib/worker/constants/runner-events'); | ||
const {makeConfigStub, makeTest} = require('../../../utils'); | ||
const Promise = require('bluebird'); | ||
|
||
describe('worker/runner/sequence-test-parser', () => { | ||
const sandbox = sinon.sandbox.create(); | ||
|
||
const mkSequenceParser_ = (opts = {}) => { | ||
const config = opts.config || makeConfigStub(); | ||
return SequenceTestParser.create(config); | ||
}; | ||
|
||
beforeEach(() => { | ||
sandbox.stub(SimpleTestParser, 'create').returns(Object.create(SimpleTestParser.prototype)); | ||
sandbox.stub(SimpleTestParser.prototype, 'parse').resolves([]); | ||
}); | ||
|
||
afterEach(() => sandbox.restore()); | ||
|
||
describe('constructor', () => { | ||
it('should create simple test parser', () => { | ||
const config = makeConfigStub(); | ||
|
||
mkSequenceParser_({config}); | ||
|
||
assert.calledOnceWith(SimpleTestParser.create, config); | ||
}); | ||
}); | ||
|
||
describe('parse', () => { | ||
[ | ||
'BEFORE_FILE_READ', | ||
'AFTER_FILE_READ' | ||
].forEach((event) => { | ||
it(`should passthrough ${event} event from inner test parser`, async () => { | ||
const onEvent = sinon.spy().named(`on${event}`); | ||
const sequenceParser = mkSequenceParser_() | ||
.on(RunnerEvents[event], onEvent); | ||
|
||
SimpleTestParser.prototype.parse.callsFake(function() { | ||
this.emit(RunnerEvents[event], {foo: 'bar'}); | ||
return Promise.resolve([]); | ||
}); | ||
|
||
await sequenceParser.parse({}); | ||
|
||
assert.calledOnceWith(onEvent, {foo: 'bar'}); | ||
}); | ||
}); | ||
|
||
it('should return parsed tests', async () => { | ||
const sequenceParser = mkSequenceParser_(); | ||
const tests = [makeTest(), makeTest()]; | ||
SimpleTestParser.prototype.parse.resolves(tests); | ||
|
||
const result = await sequenceParser.parse({}); | ||
|
||
assert.deepEqual(result, tests); | ||
}); | ||
|
||
it('should parse tests sequentially', async () => { | ||
const calls = []; | ||
|
||
SimpleTestParser.prototype.parse.callsFake(async () => { | ||
calls.push('parse'); | ||
await Promise.delay(1); | ||
calls.push('afterParse'); | ||
|
||
return []; | ||
}); | ||
|
||
const sequenceParser = mkSequenceParser_(); | ||
|
||
await Promise.all([sequenceParser.parse({}), sequenceParser.parse({})]); | ||
|
||
assert.deepEqual(calls, ['parse', 'afterParse', 'parse', 'afterParse']); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.