- Install dependencies (including sinon for mocking):
npm install- Run all tests:
npm testYou should see output from all test files:
- ✅
test.mjs(existing numFormatter test) - ✅
voting.test.mjs(voting system logic) - ✅
parser.test.mjs(argument parser) - ✅
integration.test.mjs(integration tests)
Voting System Logic
Gong Vote Tracking
✓ should allow first gong from user
✓ should prevent duplicate gong from same user
✓ should trigger gong action when limit reached
✓ should not trigger gong action before limit
Argument Parser
Basic parsing
✓ should parse simple command
✓ should parse command with multiple words
Quote handling
✓ should parse double-quoted strings
✓ should parse single-quoted strings
50 passing (25ms)
Example of test output in the terminal showing all passing tests
Before you push code, run the tests:
npm testIf all tests pass ✅, your changes have not broken existing functionality!
When you add new functionality, add a test first:
// test/myfeature.test.mjs
import { expect } from 'chai';
describe('My New Feature', function() {
it('should work correctly', function() {
const result = myFunction();
expect(result).to.equal('expected');
});
});This is called Test Driven Development (TDD).
✅ Voting logic - Gong/vote counters, limits, immunity ✅ Argument parsing - Quote handling, edge cases ✅ Business logic - Duplicates, state management, URI conversion ✅ Config validation - Number ranges, type checking ✅ Blacklist handling - Add/remove/check users
❌ Actual Spotify API calls ❌ Actual Sonos calls ❌ Slack messages
→ These can be mocked in the future with sinon!
🚀 Fast - Tests run in under 1 second 🔒 Safe - Catch bugs before they reach production 📚 Documentation - Shows how the code should work ♻️ Refactoring - Change code confidently, tests will tell you if something breaks
- Run
npm testbefore every commit - Write a test when you find a bug (regression test)
- Keep tests simple and focused
- One test = one assert (roughly)
Good luck! 🎉