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>
179 lines
5.6 KiB
JavaScript
179 lines
5.6 KiB
JavaScript
'use strict';
|
|
|
|
var acorn = require('acorn');
|
|
var walk = require('acorn-walk');
|
|
|
|
function isScope(node) {
|
|
return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'ArrowFunctionExpression' || node.type === 'Program';
|
|
}
|
|
function isBlockScope(node) {
|
|
// The body of switch statement is a block.
|
|
return node.type === 'BlockStatement' || node.type === 'SwitchStatement' || isScope(node);
|
|
}
|
|
|
|
function declaresArguments(node) {
|
|
return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration';
|
|
}
|
|
|
|
function reallyParse(source, options) {
|
|
var parseOptions = Object.assign(
|
|
{
|
|
allowReturnOutsideFunction: true,
|
|
allowImportExportEverywhere: true,
|
|
allowHashBang: true,
|
|
ecmaVersion: "latest"
|
|
},
|
|
options
|
|
);
|
|
return acorn.parse(source, parseOptions);
|
|
}
|
|
module.exports = findGlobals;
|
|
module.exports.parse = reallyParse;
|
|
function findGlobals(source, options) {
|
|
options = options || {};
|
|
var globals = [];
|
|
var ast;
|
|
// istanbul ignore else
|
|
if (typeof source === 'string') {
|
|
ast = reallyParse(source, options);
|
|
} else {
|
|
ast = source;
|
|
}
|
|
// istanbul ignore if
|
|
if (!(ast && typeof ast === 'object' && ast.type === 'Program')) {
|
|
throw new TypeError('Source must be either a string of JavaScript or an acorn AST');
|
|
}
|
|
var declareFunction = function (node) {
|
|
var fn = node;
|
|
fn.locals = fn.locals || Object.create(null);
|
|
node.params.forEach(function (node) {
|
|
declarePattern(node, fn);
|
|
});
|
|
if (node.id) {
|
|
fn.locals[node.id.name] = true;
|
|
}
|
|
};
|
|
var declareClass = function (node) {
|
|
node.locals = node.locals || Object.create(null);
|
|
if (node.id) {
|
|
node.locals[node.id.name] = true;
|
|
}
|
|
};
|
|
var declarePattern = function (node, parent) {
|
|
switch (node.type) {
|
|
case 'Identifier':
|
|
parent.locals[node.name] = true;
|
|
break;
|
|
case 'ObjectPattern':
|
|
node.properties.forEach(function (node) {
|
|
declarePattern(node.value || node.argument, parent);
|
|
});
|
|
break;
|
|
case 'ArrayPattern':
|
|
node.elements.forEach(function (node) {
|
|
if (node) declarePattern(node, parent);
|
|
});
|
|
break;
|
|
case 'RestElement':
|
|
declarePattern(node.argument, parent);
|
|
break;
|
|
case 'AssignmentPattern':
|
|
declarePattern(node.left, parent);
|
|
break;
|
|
// istanbul ignore next
|
|
default:
|
|
throw new Error('Unrecognized pattern type: ' + node.type);
|
|
}
|
|
};
|
|
var declareModuleSpecifier = function (node, parents) {
|
|
ast.locals = ast.locals || Object.create(null);
|
|
ast.locals[node.local.name] = true;
|
|
};
|
|
walk.ancestor(ast, {
|
|
'VariableDeclaration': function (node, parents) {
|
|
var parent = null;
|
|
for (var i = parents.length - 1; i >= 0 && parent === null; i--) {
|
|
if (node.kind === 'var' ? isScope(parents[i]) : isBlockScope(parents[i])) {
|
|
parent = parents[i];
|
|
}
|
|
}
|
|
parent.locals = parent.locals || Object.create(null);
|
|
node.declarations.forEach(function (declaration) {
|
|
declarePattern(declaration.id, parent);
|
|
});
|
|
},
|
|
'FunctionDeclaration': function (node, parents) {
|
|
var parent = null;
|
|
for (var i = parents.length - 2; i >= 0 && parent === null; i--) {
|
|
if (isScope(parents[i])) {
|
|
parent = parents[i];
|
|
}
|
|
}
|
|
parent.locals = parent.locals || Object.create(null);
|
|
if (node.id) {
|
|
parent.locals[node.id.name] = true;
|
|
}
|
|
declareFunction(node);
|
|
},
|
|
'Function': declareFunction,
|
|
'ClassDeclaration': function (node, parents) {
|
|
var parent = null;
|
|
for (var i = parents.length - 2; i >= 0 && parent === null; i--) {
|
|
if (isBlockScope(parents[i])) {
|
|
parent = parents[i];
|
|
}
|
|
}
|
|
parent.locals = parent.locals || Object.create(null);
|
|
if (node.id) {
|
|
parent.locals[node.id.name] = true;
|
|
}
|
|
declareClass(node);
|
|
},
|
|
'Class': declareClass,
|
|
'TryStatement': function (node) {
|
|
if (node.handler === null || node.handler.param === null) return;
|
|
node.handler.locals = node.handler.locals || Object.create(null);
|
|
declarePattern(node.handler.param, node.handler);
|
|
},
|
|
'ImportDefaultSpecifier': declareModuleSpecifier,
|
|
'ImportSpecifier': declareModuleSpecifier,
|
|
'ImportNamespaceSpecifier': declareModuleSpecifier
|
|
});
|
|
function identifier(node, parents) {
|
|
var name = node.name;
|
|
if (name === 'undefined') return;
|
|
for (var i = 0; i < parents.length; i++) {
|
|
if (name === 'arguments' && declaresArguments(parents[i])) {
|
|
return;
|
|
}
|
|
if (parents[i].locals && name in parents[i].locals) {
|
|
return;
|
|
}
|
|
}
|
|
node.parents = parents.slice();
|
|
globals.push(node);
|
|
}
|
|
walk.ancestor(ast, {
|
|
'VariablePattern': identifier,
|
|
'Identifier': identifier,
|
|
'ThisExpression': function (node, parents) {
|
|
for (var i = 0; i < parents.length; i++) {
|
|
var parent = parents[i];
|
|
if ( parent.type === 'FunctionExpression' || parent.type === 'FunctionDeclaration' ) { return; }
|
|
if ( parent.type === 'PropertyDefinition' && parents[i+1]===parent.value ) { return; }
|
|
}
|
|
node.parents = parents.slice();
|
|
globals.push(node);
|
|
}
|
|
});
|
|
var groupedGlobals = Object.create(null);
|
|
globals.forEach(function (node) {
|
|
var name = node.type === 'ThisExpression' ? 'this' : node.name;
|
|
groupedGlobals[name] = (groupedGlobals[name] || []);
|
|
groupedGlobals[name].push(node);
|
|
});
|
|
return Object.keys(groupedGlobals).sort().map(function (name) {
|
|
return {name: name, nodes: groupedGlobals[name]};
|
|
});
|
|
}
|