Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"license": "BSD-3-Clause",
"devDependencies": {
"@babel/preset-flow": "^7.0.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"babel-cli": "^6.24.1",
"babel-eslint": "^8.2.6",
"babel-jest": "^22.4.4",
Expand Down Expand Up @@ -36,8 +38,10 @@
"flow-bin": "0.66",
"forever": "^0.15.3",
"is-html": "^1.1.0",
"jest": "^26.6.3",
"lint-staged": "^3.3.0",
"micromatch": "^3.0.4",
"msw": "^0.39.2",
"prettier": "^1.14.3",
"raw-loader": "^0.5.1",
"react-app-rewire-hot-loader": "^1.0.3",
Expand Down Expand Up @@ -129,7 +133,6 @@
"imgix-core-js": "^1.0.6",
"ioredis": "3.2.2",
"isomorphic-fetch": "^2.2.1",
"jest": "22.4.3",
"json-stringify-pretty-compact": "^1.2.0",
"jsonwebtoken": "^8.3.0",
"keygrip": "^1.0.3",
Expand Down
27 changes: 27 additions & 0 deletions regression-tests/button-regression.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// regression-tests/button-regression.test.js
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Button } from '../src/components/button/index.js'; // Use public API

// Test the primary Button export (not the styled button internals)

describe('Button regression', () => {
test('Button renders with provided children and can be clicked', () => {
const handleClick = jest.fn();
render(<Button onClick={handleClick}>Click Me</Button>);
const btn = screen.getByRole('button', { name: 'Click Me' });
expect(btn).toBeInTheDocument();
fireEvent.click(btn);
expect(handleClick).toHaveBeenCalledTimes(1);
});

test('Button supports small size prop', () => {
render(<Button size="small">Small</Button>);
const btn = screen.getByRole('button', { name: 'Small' });
expect(btn).toBeInTheDocument();
// Do not test exact font-size inline, as styled-components injects in a stylesheet.
// Instead, assert presence and correct rendered text.
expect(btn).toHaveTextContent('Small');
});
});
19 changes: 19 additions & 0 deletions regression-tests/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// regression-tests/jest.config.js
const path = require('path');

module.exports = {
rootDir: '..',
setupFilesAfterEnv: ['<rootDir>/regression-tests/setupTests.js'],
moduleDirectories: [
'node_modules',
path.resolve(__dirname, '../shared'),
path.resolve(__dirname, '../src'),
path.resolve(__dirname, '../'),
],
moduleNameMapper: {
'^shared/(.*)$': '<rootDir>/shared/$1',
'^src/(.*)$': '<rootDir>/src/$1',
},
testEnvironment: 'jsdom',
transformIgnorePatterns: ['/node_modules/', '/api/'],
};
13 changes: 13 additions & 0 deletions regression-tests/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// regression-tests/server.js
// This sets up Mock Service Worker in case API mocking is needed later.
import { setupServer } from 'msw/node';
// Example handler; add actual ones as needed
import { rest } from 'msw';

// No handlers for now - infrastructure only
export const server = setupServer();

// Establish API mocking before all tests, and clean up after
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
2 changes: 2 additions & 0 deletions regression-tests/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Regression test setup for React Testing Library + MSW
import '@testing-library/jest-dom';
52 changes: 52 additions & 0 deletions scripts/find_react_components.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
import os
import re
import json
from pathlib import Path

# Directories likely to contain React source files
SEARCH_DIRS = [
"src",
"shared",
"hyperion",
"api"
]

EXTENSIONS = {".js", ".jsx", ".ts", ".tsx"}

# regexes
# Function component (named export or declaration): function MyComponent(...)
FUNC_COMPONENT = re.compile(r"^function\s+([A-Z][A-Za-z0-9_]*)\s*\(", re.MULTILINE)
# Arrow function component: const MyComponent = (...) => or export const MyComponent = ...
ARROW_COMPONENT = re.compile(r"^(?:const|let|var|export\s+const)\s+([A-Z][A-Za-z0-9_]*)\s*=\s*(?:\([^)]+\)|[A-Za-z0-9_]+)?\s*=>", re.MULTILINE)
# Class component: class MyComponent extends React.Component
CLASS_COMPONENT = re.compile(r"^class\s+([A-Z][A-Za-z0-9_]*)\s+extends\s+[A-Za-z0-9_.]+", re.MULTILINE)

def find_react_components(search_dirs):
components = []
for base in search_dirs:
if not os.path.isdir(base):
continue
for root, _, files in os.walk(base):
for file in files:
ext = Path(file).suffix
if ext not in EXTENSIONS:
continue
file_path = os.path.join(root, file)
try:
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
except Exception:
continue # skip unreadable files
for regex in [FUNC_COMPONENT, ARROW_COMPONENT, CLASS_COMPONENT]:
for match in regex.finditer(content):
name = match.group(1)
components.append({"name": name, "file": file_path})
return components

def main():
components = find_react_components(SEARCH_DIRS)
print(json.dumps(components, indent=2))

if __name__ == "__main__":
main()
Loading