Skip to content

Commit

Permalink
fix ESLint... :eye-rolling-eyes:
Browse files Browse the repository at this point in the history
  • Loading branch information
jerdog committed Nov 29, 2024
1 parent f3c8822 commit b1d9d3b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 55 deletions.
100 changes: 50 additions & 50 deletions tests/bot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,59 @@ import { jest, describe, test, beforeEach, afterEach, expect } from '@jest/globa
import { debug } from '../bot.js';

describe('Bot Utilities', () => {
let consoleLogSpy;
let consoleErrorSpy;
let originalEnv;

beforeEach(() => {
originalEnv = process.env;
process.env = { ...originalEnv }; // Clone the environment
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
let consoleLogSpy;

Check failure on line 5 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 4 spaces but found 2

Check failure on line 5 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 4 spaces but found 2
let consoleErrorSpy;

Check failure on line 6 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 4 spaces but found 2

Check failure on line 6 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 4 spaces but found 2
let originalEnv;

Check failure on line 7 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 4 spaces but found 2

Check failure on line 7 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 4 spaces but found 2

beforeEach(() => {

Check failure on line 9 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 4 spaces but found 2

Check failure on line 9 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 4 spaces but found 2
originalEnv = process.env;

Check failure on line 10 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 8 spaces but found 4

Check failure on line 10 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 8 spaces but found 4
process.env = { ...originalEnv }; // Clone the environment

Check failure on line 11 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 8 spaces but found 4

Check failure on line 11 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 8 spaces but found 4
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {});

Check failure on line 12 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 8 spaces but found 4

Check failure on line 12 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 8 spaces but found 4
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

Check failure on line 13 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 8 spaces but found 4

Check failure on line 13 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 8 spaces but found 4
});

Check failure on line 14 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 4 spaces but found 2

Check failure on line 14 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 4 spaces but found 2

afterEach(() => {

Check failure on line 16 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 4 spaces but found 2

Check failure on line 16 in tests/bot.test.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected indentation of 4 spaces but found 2
process.env = originalEnv; // Restore original environment
consoleLogSpy.mockRestore();
consoleErrorSpy.mockRestore();
jest.resetModules();
});

describe('debug', () => {
test('should log message with verbose level when debug mode is enabled', () => {
process.env.DEBUG_MODE = 'true';
debug('test message', 'verbose');
expect(consoleLogSpy).toHaveBeenCalled();
const call = consoleLogSpy.mock.calls[0][0];
expect(call).toMatch(/\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\] \[VERBOSE\] test message/);
});

afterEach(() => {
process.env = originalEnv; // Restore original environment
consoleLogSpy.mockRestore();
consoleErrorSpy.mockRestore();
jest.resetModules();
test('should not log verbose message when debug mode is disabled', () => {
process.env.DEBUG_MODE = 'false';
debug('test message', 'verbose');
expect(consoleLogSpy).not.toHaveBeenCalled();
});

describe('debug', () => {
test('should log message with verbose level when debug mode is enabled', () => {
process.env.DEBUG_MODE = 'true';
debug('test message', 'verbose');
expect(consoleLogSpy).toHaveBeenCalled();
const call = consoleLogSpy.mock.calls[0][0];
expect(call).toMatch(/\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\] \[VERBOSE\] test message/);
});

test('should not log verbose message when debug mode is disabled', () => {
process.env.DEBUG_MODE = 'false';
debug('test message', 'verbose');
expect(consoleLogSpy).not.toHaveBeenCalled();
});

test('should log info message regardless of debug mode', () => {
process.env.DEBUG_MODE = 'false';
debug('info message', 'info');
expect(consoleLogSpy).toHaveBeenCalled();
const call = consoleLogSpy.mock.calls[0][0];
expect(call).toMatch(/\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\] info message/);
});

test('should log error message with ERROR prefix', () => {
debug('error message', 'error');
expect(consoleLogSpy).toHaveBeenCalled();
const call = consoleLogSpy.mock.calls[0][0];
expect(call).toMatch(/\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\] \[ERROR\] error message/);
});

test('should log additional data when provided', () => {
const data = { key: 'value' };
debug('message with data', 'info', data);
expect(consoleLogSpy).toHaveBeenCalledTimes(2);
expect(consoleLogSpy.mock.calls[1][0]).toBe(data);
});
test('should log info message regardless of debug mode', () => {
process.env.DEBUG_MODE = 'false';
debug('info message', 'info');
expect(consoleLogSpy).toHaveBeenCalled();
const call = consoleLogSpy.mock.calls[0][0];
expect(call).toMatch(/\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\] info message/);
});

test('should log error message with ERROR prefix', () => {
debug('error message', 'error');
expect(consoleLogSpy).toHaveBeenCalled();
const call = consoleLogSpy.mock.calls[0][0];
expect(call).toMatch(/\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\] \[ERROR\] error message/);
});

test('should log additional data when provided', () => {
const data = { key: 'value' };
debug('message with data', 'info', data);
expect(consoleLogSpy).toHaveBeenCalledTimes(2);
expect(consoleLogSpy.mock.calls[1][0]).toBe(data);
});
});
});
4 changes: 2 additions & 2 deletions tests/markov.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { jest, describe, test, beforeEach, expect } from '@jest/globals';
import { describe, test, beforeEach, expect } from '@jest/globals';
import { MarkovChain } from '../bot.js';
import fs from 'fs';
import path from 'path';
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('MarkovChain', () => {
expect(generated.string.length).toBeLessThanOrEqual(options.maxChars);

// Verify the text contains common Twitter elements
const twitterElements = /(https?:\/\/\S+|\@\w+|\#\w+)/;
const twitterElements = /(https?:\/\/\S+|@\w+|#\w+)/;
expect(generated.string).toMatch(twitterElements);
});
});
6 changes: 3 additions & 3 deletions worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Import only the necessary functions
import { debug, main } from './bot.js';
import { debug, generatePost, postToMastodon, postToBluesky, main } from './bot.js';

// Create a global process.env if it doesn't exist
if (typeof process === 'undefined' || typeof process.env === 'undefined') {
Expand All @@ -8,7 +8,7 @@ if (typeof process === 'undefined' || typeof process.env === 'undefined') {

export default {
// Handle HTTP requests
async fetch(request, env, ctx) {
async fetch(request, env, _ctx) {
try {
// Set environment variables
process.env.CLOUDFLARE_WORKER = 'true';
Expand Down Expand Up @@ -36,7 +36,7 @@ export default {
},

// Handle scheduled events
async scheduled(event, env, ctx) {
async scheduled(event, env, _ctx) {
try {
// Set environment variables
process.env.CLOUDFLARE_WORKER = 'true';
Expand Down

0 comments on commit b1d9d3b

Please sign in to comment.