a11yanalyze
Version:
A command-line tool for developers and QA engineers to test web pages and websites for WCAG 2.2 AA accessibility compliance
96 lines • 3.09 kB
JavaScript
;
/**
* Jest test setup and configuration
* Global test utilities and environment setup
*/
Object.defineProperty(exports, "__esModule", { value: true });
// Extend Jest matchers for better assertions
expect.extend({
toBeAccessible(received) {
const pass = received && received.score >= 80;
return {
message: () => pass
? `expected ${received} not to be accessible`
: `expected ${received} to be accessible (score >= 80)`,
pass,
};
},
toHaveViolations(received, expectedCount) {
const violations = received?.issues || [];
const actualCount = violations.length;
const pass = expectedCount !== undefined
? actualCount === expectedCount
: actualCount > 0;
return {
message: () => expectedCount !== undefined
? `expected ${actualCount} violations, got ${actualCount}`
: pass
? `expected no violations, got ${actualCount}`
: `expected violations, got none`,
pass,
};
},
});
// Global test configuration
beforeAll(() => {
// Set test environment timezone
process.env.TZ = 'UTC';
// Suppress console logs during tests unless explicitly needed
if (!process.env.VERBOSE_TESTS) {
jest.spyOn(console, 'log').mockImplementation();
jest.spyOn(console, 'info').mockImplementation();
jest.spyOn(console, 'warn').mockImplementation();
}
});
afterAll(() => {
// Cleanup any global resources
jest.restoreAllMocks();
});
// Global test helpers
global.testHelpers = {
createMockScanResult: (overrides = {}) => ({
url: 'https://example.com',
timestamp: new Date().toISOString(),
score: 85,
issues: [],
metadata: {
scanDuration: 1000,
pageLoadTime: 500,
totalElements: 100,
testedElements: 95,
userAgent: 'test-agent',
viewport: { width: 1280, height: 720 },
url: {
original: 'https://example.com',
final: 'https://example.com',
redirects: 0,
},
},
...overrides,
}),
createMockAccessibilityIssue: (overrides = {}) => ({
id: 'test-rule-1',
wcagReference: '1.1.1',
level: 'AA',
severity: 'serious',
element: 'img',
selector: 'img[src="test.jpg"]',
message: 'Image missing alt text',
remediation: 'Add descriptive alt text to image',
helpUrl: 'https://dequeuniversity.com/rules/axe/4.8/image-alt',
impact: 'serious',
tags: ['wcag2a', 'wcag111'],
...overrides,
}),
wait: (ms) => new Promise(resolve => setTimeout(resolve, ms)),
mockBrowser: {
page: {
goto: jest.fn(),
evaluate: jest.fn(),
close: jest.fn(),
screenshot: jest.fn(),
},
close: jest.fn(),
},
};
//# sourceMappingURL=test-setup.js.map