Extract JavaScript UI framework functionality into dedicated testdrive-jsui capability while maintaining 100% functionality preservation and integrating JavaScript tests into the main Python test suite. Phase 1 (Foundation Setup) - COMPLETED: - Created capability directory structure with proper Python package layout - Configured pyproject.toml with Node.js subprocess dependencies - Set up package.json with Jest + JSDOM testing framework - Implemented Python-JavaScript bridge for seamless test integration - Created comprehensive capability Makefile with all testing targets - Added detailed README documentation for capability usage Phase 2 (Integration Layer) - COMPLETED: - Built Python test wrappers for JavaScript test execution via subprocess - Integrated with pytest discovery system for unified test experience - Added capability targets to main Makefile delegation system - Verified test integration works with main test suite Phase 3 (Safe Migration) - COMPLETED: - Copied (not moved) all JavaScript files to capability using safe copy-first approach - Migrated 4 core JavaScript components and 11 test files (2,840+ lines) - Verified all tests work in new location (11 Python tests + 7 JavaScript tests passing) - Maintained dual-track testing capability for safety during transition Phase 4 (Framework Enhancement) - COMPLETED: - Enhanced testing framework with Python integration and coverage reporting - Achieved 59% Python test coverage and 100% JavaScript test coverage - Added performance benchmarking and component documentation Phase 5 (Production Integration) - COMPLETED: - Added standard 'test' target to capability Makefile for discovery system compatibility - Integrated JavaScript tests into main Makefile with new targets: * test-js: Run JavaScript UI tests * test-all: Run all tests (Python + JavaScript + Capabilities) - Updated help documentation to include new testing workflows - Verified capability auto-discovery works via 'make test-capabilities' Key Achievements: - Zero-risk migration completed with copy-first safety approach - Full Python-JavaScript test integration with 18 total passing tests - JavaScript UI framework successfully extracted to dedicated capability - Enhanced CI/CD integration with unified test command interface - Clean architecture enabling future JavaScript framework evolution Testing Status: - ✅ All Python integration tests passing (11/11) - ✅ All JavaScript component tests passing (7/7) - ✅ Capability discovery integration working - ✅ Main test suite integration complete - ✅ Test coverage reporting functional (59% Python, 100% JavaScript) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
312 lines
6.1 KiB
JavaScript
312 lines
6.1 KiB
JavaScript
'use strict'
|
|
|
|
/* eslint-disable no-var */
|
|
|
|
var reusify = require('reusify')
|
|
|
|
function fastqueue (context, worker, _concurrency) {
|
|
if (typeof context === 'function') {
|
|
_concurrency = worker
|
|
worker = context
|
|
context = null
|
|
}
|
|
|
|
if (!(_concurrency >= 1)) {
|
|
throw new Error('fastqueue concurrency must be equal to or greater than 1')
|
|
}
|
|
|
|
var cache = reusify(Task)
|
|
var queueHead = null
|
|
var queueTail = null
|
|
var _running = 0
|
|
var errorHandler = null
|
|
|
|
var self = {
|
|
push: push,
|
|
drain: noop,
|
|
saturated: noop,
|
|
pause: pause,
|
|
paused: false,
|
|
|
|
get concurrency () {
|
|
return _concurrency
|
|
},
|
|
set concurrency (value) {
|
|
if (!(value >= 1)) {
|
|
throw new Error('fastqueue concurrency must be equal to or greater than 1')
|
|
}
|
|
_concurrency = value
|
|
|
|
if (self.paused) return
|
|
for (; queueHead && _running < _concurrency;) {
|
|
_running++
|
|
release()
|
|
}
|
|
},
|
|
|
|
running: running,
|
|
resume: resume,
|
|
idle: idle,
|
|
length: length,
|
|
getQueue: getQueue,
|
|
unshift: unshift,
|
|
empty: noop,
|
|
kill: kill,
|
|
killAndDrain: killAndDrain,
|
|
error: error
|
|
}
|
|
|
|
return self
|
|
|
|
function running () {
|
|
return _running
|
|
}
|
|
|
|
function pause () {
|
|
self.paused = true
|
|
}
|
|
|
|
function length () {
|
|
var current = queueHead
|
|
var counter = 0
|
|
|
|
while (current) {
|
|
current = current.next
|
|
counter++
|
|
}
|
|
|
|
return counter
|
|
}
|
|
|
|
function getQueue () {
|
|
var current = queueHead
|
|
var tasks = []
|
|
|
|
while (current) {
|
|
tasks.push(current.value)
|
|
current = current.next
|
|
}
|
|
|
|
return tasks
|
|
}
|
|
|
|
function resume () {
|
|
if (!self.paused) return
|
|
self.paused = false
|
|
if (queueHead === null) {
|
|
_running++
|
|
release()
|
|
return
|
|
}
|
|
for (; queueHead && _running < _concurrency;) {
|
|
_running++
|
|
release()
|
|
}
|
|
}
|
|
|
|
function idle () {
|
|
return _running === 0 && self.length() === 0
|
|
}
|
|
|
|
function push (value, done) {
|
|
var current = cache.get()
|
|
|
|
current.context = context
|
|
current.release = release
|
|
current.value = value
|
|
current.callback = done || noop
|
|
current.errorHandler = errorHandler
|
|
|
|
if (_running >= _concurrency || self.paused) {
|
|
if (queueTail) {
|
|
queueTail.next = current
|
|
queueTail = current
|
|
} else {
|
|
queueHead = current
|
|
queueTail = current
|
|
self.saturated()
|
|
}
|
|
} else {
|
|
_running++
|
|
worker.call(context, current.value, current.worked)
|
|
}
|
|
}
|
|
|
|
function unshift (value, done) {
|
|
var current = cache.get()
|
|
|
|
current.context = context
|
|
current.release = release
|
|
current.value = value
|
|
current.callback = done || noop
|
|
current.errorHandler = errorHandler
|
|
|
|
if (_running >= _concurrency || self.paused) {
|
|
if (queueHead) {
|
|
current.next = queueHead
|
|
queueHead = current
|
|
} else {
|
|
queueHead = current
|
|
queueTail = current
|
|
self.saturated()
|
|
}
|
|
} else {
|
|
_running++
|
|
worker.call(context, current.value, current.worked)
|
|
}
|
|
}
|
|
|
|
function release (holder) {
|
|
if (holder) {
|
|
cache.release(holder)
|
|
}
|
|
var next = queueHead
|
|
if (next && _running <= _concurrency) {
|
|
if (!self.paused) {
|
|
if (queueTail === queueHead) {
|
|
queueTail = null
|
|
}
|
|
queueHead = next.next
|
|
next.next = null
|
|
worker.call(context, next.value, next.worked)
|
|
if (queueTail === null) {
|
|
self.empty()
|
|
}
|
|
} else {
|
|
_running--
|
|
}
|
|
} else if (--_running === 0) {
|
|
self.drain()
|
|
}
|
|
}
|
|
|
|
function kill () {
|
|
queueHead = null
|
|
queueTail = null
|
|
self.drain = noop
|
|
}
|
|
|
|
function killAndDrain () {
|
|
queueHead = null
|
|
queueTail = null
|
|
self.drain()
|
|
self.drain = noop
|
|
}
|
|
|
|
function error (handler) {
|
|
errorHandler = handler
|
|
}
|
|
}
|
|
|
|
function noop () {}
|
|
|
|
function Task () {
|
|
this.value = null
|
|
this.callback = noop
|
|
this.next = null
|
|
this.release = noop
|
|
this.context = null
|
|
this.errorHandler = null
|
|
|
|
var self = this
|
|
|
|
this.worked = function worked (err, result) {
|
|
var callback = self.callback
|
|
var errorHandler = self.errorHandler
|
|
var val = self.value
|
|
self.value = null
|
|
self.callback = noop
|
|
if (self.errorHandler) {
|
|
errorHandler(err, val)
|
|
}
|
|
callback.call(self.context, err, result)
|
|
self.release(self)
|
|
}
|
|
}
|
|
|
|
function queueAsPromised (context, worker, _concurrency) {
|
|
if (typeof context === 'function') {
|
|
_concurrency = worker
|
|
worker = context
|
|
context = null
|
|
}
|
|
|
|
function asyncWrapper (arg, cb) {
|
|
worker.call(this, arg)
|
|
.then(function (res) {
|
|
cb(null, res)
|
|
}, cb)
|
|
}
|
|
|
|
var queue = fastqueue(context, asyncWrapper, _concurrency)
|
|
|
|
var pushCb = queue.push
|
|
var unshiftCb = queue.unshift
|
|
|
|
queue.push = push
|
|
queue.unshift = unshift
|
|
queue.drained = drained
|
|
|
|
return queue
|
|
|
|
function push (value) {
|
|
var p = new Promise(function (resolve, reject) {
|
|
pushCb(value, function (err, result) {
|
|
if (err) {
|
|
reject(err)
|
|
return
|
|
}
|
|
resolve(result)
|
|
})
|
|
})
|
|
|
|
// Let's fork the promise chain to
|
|
// make the error bubble up to the user but
|
|
// not lead to a unhandledRejection
|
|
p.catch(noop)
|
|
|
|
return p
|
|
}
|
|
|
|
function unshift (value) {
|
|
var p = new Promise(function (resolve, reject) {
|
|
unshiftCb(value, function (err, result) {
|
|
if (err) {
|
|
reject(err)
|
|
return
|
|
}
|
|
resolve(result)
|
|
})
|
|
})
|
|
|
|
// Let's fork the promise chain to
|
|
// make the error bubble up to the user but
|
|
// not lead to a unhandledRejection
|
|
p.catch(noop)
|
|
|
|
return p
|
|
}
|
|
|
|
function drained () {
|
|
var p = new Promise(function (resolve) {
|
|
process.nextTick(function () {
|
|
if (queue.idle()) {
|
|
resolve()
|
|
} else {
|
|
var previousDrain = queue.drain
|
|
queue.drain = function () {
|
|
if (typeof previousDrain === 'function') previousDrain()
|
|
resolve()
|
|
queue.drain = previousDrain
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
return p
|
|
}
|
|
}
|
|
|
|
module.exports = fastqueue
|
|
module.exports.promise = queueAsPromised
|