sassy-log
Version:
Logging, but with sass, satire, and some serious fun. A developer-first NPM package that replaces boring console.log() statements with snarky, sarcastic, or corporate-smooth one-liners.
134 lines (110 loc) โข 4.59 kB
JavaScript
/**
* Simple test suite for Sassy Log
* Run with: npm test
*/
const sassyLogger = require('../index');
console.log('๐งช Running Sassy Log Tests...\n');
let testsRun = 0;
let testsPassed = 0;
function test(description, testFn) {
testsRun++;
console.log(`Test ${testsRun}: ${description}`);
try {
testFn();
testsPassed++;
console.log('โ
PASSED\n');
} catch (error) {
console.log(`โ FAILED: ${error.message}\n`);
}
}
function assert(condition, message) {
if (!condition) {
throw new Error(message || 'Assertion failed');
}
}
// Test 1: Basic logger creation
test('Create Log with default options', () => {
const log = sassyLogger();
assert(typeof log === 'function', 'Log should be a function');
assert(typeof log.info === 'function', 'Log should have info method');
assert(typeof log.success === 'function', 'Log should have success method');
assert(typeof log.warn === 'function', 'Log should have warn method');
assert(typeof log.error === 'function', 'Log should have error method');
});
// Test 2: Mode switching
test('Mode switching works correctly', () => {
const log = sassyLogger({ mode: 'friendly' });
assert(log.getMode() === 'friendly', 'Initial mode should be friendly');
log.setMode('savage');
assert(log.getMode() === 'savage', 'Mode should switch to savage');
log.setMode('nonexistent');
assert(log.getMode() === 'savage', 'Mode should remain savage for invalid mode');
});
// Test 3: Available modes
test('Available modes are returned correctly', () => {
const log = sassyLogger();
const modes = log.getAvailableModes();
assert(Array.isArray(modes), 'Available modes should be an array');
assert(modes.includes('savage'), 'Should include savage mode');
assert(modes.includes('friendly'), 'Should include friendly mode');
assert(modes.includes('sarcastic'), 'Should include sarcastic mode');
assert(modes.includes('corporate'), 'Should include corporate mode');
});
// Test 4: Chaining works
test('Method chaining works correctly', () => {
const log = sassyLogger({ mode: 'sarcastic' });
const result = log.info('test').success('test').warn('test').error('test');
assert(result === log, 'Chaining should return the same log instance');
});
// Test 5: Custom quotes
test('Custom quotes can be added', () => {
const log = sassyLogger({ mode: 'savage' });
log.addCustomQuotes('savage', 'info', ['Custom test quote']);
// If no error is thrown, the test passes
assert(true, 'Custom quotes should be addable');
});
// Test 6: Configuration options
test('Configuration options work correctly', () => {
const log = sassyLogger({
mode: 'corporate',
colors: false,
timestamps: true,
emojis: false
});
assert(log.getMode() === 'corporate', 'Mode should be set correctly');
// Other options are harder to test without inspecting internals
assert(true, 'Configuration should be accepted');
});
// Test 7: Multiple instances
test('Multiple log instances work independently', () => {
const log1 = sassyLogger({ mode: 'savage' });
const log2 = sassyLogger({ mode: 'friendly' });
assert(log1.getMode() === 'savage', 'First log should be savage');
assert(log2.getMode() === 'friendly', 'Second log should be friendly');
log1.setMode('corporate');
assert(log1.getMode() === 'corporate', 'First log mode should change');
assert(log2.getMode() === 'friendly', 'Second log mode should remain unchanged');
});
// Test 8: Export variations
test('Different export methods work', () => {
const defaultExport = require('../index');
const { SassyLogger, createLogger } = require('../index');
assert(typeof defaultExport === 'function', 'Default export should be a function');
assert(typeof SassyLogger === 'function', 'SassyLogger should be exported');
assert(typeof createLogger === 'function', 'createLogger should be exported');
const log1 = defaultExport();
const log2 = createLogger();
const log3 = new SassyLogger();
assert(typeof log1.info === 'function', 'Default export should create working log');
assert(typeof log2.info === 'function', 'createLogger should create working log');
assert(typeof log3.info === 'function', 'SassyLogger constructor should create working log');
});
// Summary
console.log(`\n๐ Test Results: ${testsPassed}/${testsRun} tests passed`);
if (testsPassed === testsRun) {
console.log('๐ All tests passed! Sassy log is working correctly!');
process.exit(0);
} else {
console.log('๐ Some tests failed. Please check the implementation.');
process.exit(1);
}