-
Notifications
You must be signed in to change notification settings - Fork 4
Local Testing Strategies
This guide provides structured approaches to testing your jsPsych experiment before deployment, helping you catch issues early and ensure your experiment works correctly.
A comprehensive testing approach follows these stages:
- Component Testing: Testing individual experiment components
- Integration Testing: Testing how components work together
- End-to-End Testing: Running through the entire experiment
- Cross-Browser Testing: Verifying compatibility across browsers
- Performance Testing: Checking timing and resource usage
Before starting your testing, ensure your environment is properly configured:
-
Start with a clean development environment:
yarn dev
-
Open your browser's developer tools (F12 or Cmd+Option+I):
- Keep the Console tab open to catch errors
- Use the Network tab to monitor data transfers
- Use the Performance tab to check timing issues
-
Consider using the following URL parameters for testing:
-
?debug=trueto enable verbose logging -
?mock=trueto use the mock database
-
Test individual parts of your experiment in isolation to ensure each functions correctly.
-
Verify that all visual stimuli display correctly:
- Images load and appear at the expected size
- Text is readable and properly formatted
- HTML elements are positioned correctly
-
For audio stimuli:
- Ensure audio files play correctly
- Check volume levels are appropriate
- Verify timing of audio playback
-
Test all response mechanisms:
- Keyboard inputs register correctly
- Button clicks and touch interactions work
- Response timing is recorded accurately
-
Validate input constraints:
- Required inputs cannot be skipped
- Invalid inputs are handled gracefully
- Timeout mechanisms work as expected
Test how different parts of your experiment work together.
-
Test transitions between trials:
- Trials advance correctly
- Conditional logic works as expected
- Randomization produces appropriate variations
-
Check data flow between trials:
- Data from one trial correctly influences later trials
- Variables are properly passed through the timeline
- Cumulative data (like scores) update correctly
-
Test with the mock database:
- Data is saved correctly after each trial
- Check the Debug Panel to verify data structure
- Confirm incremental saves work during the experiment
-
When ready, test with Firestore:
- Switch to
simulateMockDatabase = false - Verify authentication works
- Check data appears in Firestore with correct structure
- Switch to
Perform complete run-throughs of your experiment as if you were a participant.
- Start from the welcome page and complete all trials
- Follow all instructions as a participant would
- Check the final data summary and completion message
-
Test with unusual inputs:
- Very fast or very slow responses
- Skipping trials where allowed
- Refreshing the page mid-experiment
- Closing and reopening the browser
-
Test error recovery:
- What happens if a participant loses internet connection?
- Does the experiment handle browser back/forward navigation?
- Test window resize and device orientation changes
Ensure your experiment works consistently across different browsers and devices.
Test your experiment in multiple browsers:
- Google Chrome (primary development browser)
- Mozilla Firefox
- Apple Safari
- Microsoft Edge
Look for any differences in:
- Visual appearance
- Timing and performance
- Keyboard and mouse interactions
- Console errors or warnings
Test on different devices and screen sizes:
- Desktop computer with large screen
- Laptop with medium screen
- Tablet (if targeting tablet users)
- Mobile phone (if targeting mobile users)
Adjust your experiment design if necessary:
- Use responsive Tailwind CSS classes
- Test different input methods (touch vs. keyboard)
- Ensure text is readable on all screen sizes
Check that your experiment runs smoothly and efficiently.
For experiments where timing is critical:
- Use external timing verification when possible (e.g., photodiode for visual stimuli)
- Test under different system loads
- Check consistency of inter-trial intervals
- Verify stimulus duration matches specifications
Monitor system resources during your experiment:
- Check memory usage in browser task manager
- Monitor CPU usage, especially for complex stimuli
- Watch network activity for data transfers
- Test on lower-end devices to ensure accessibility
Before deploying your experiment, complete this final checklist:
- All stimuli display correctly
- All response mechanisms work
- Timeline progresses as expected
- Conditional logic works correctly
- Randomization works as designed
- Error handling functions properly
- All required data is collected
- Data format matches expectations
- Incremental data saving works
- Final data summary is accurate
- Firestore connection works correctly
- Participant IDs are correctly recorded
- Instructions are clear and accurate
- Loading times are reasonable
- Visual design is consistent
- Text is readable on all screen sizes
- Completion/redirect works correctly
- Overall flow feels smooth and professional
- No console errors or warnings
- Build completes without errors:
yarn build:prod - Version and git hash are correctly included
- All assets are properly included in the build
- Lint and type checks pass:
yarn lint
While not included in the template by default, consider adding automated testing for complex experiments:
- Jest for JavaScript unit testing
- Testing Library for component testing
-
Install Jest:
yarn add --dev jest ts-jest @types/jest
-
Create a test configuration in
jest.config.js -
Write simple tests for critical functionality:
// example-test.js describe('Stimulus timing', () => { test('stimulus duration is correct', () => { // Test code here }) })
-
Add a test script to
package.json:"scripts": { "test": "jest" }
Keep track of your testing process:
- Document any issues found during testing
- Note browser-specific quirks or workarounds
- Record performance benchmarks for different devices
- Update your testing plan based on findings
This documentation will be valuable for future updates and for understanding participant experiences.