Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roma2023 committed Sep 5, 2024
1 parent 0b3315b commit cfa9d11
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 45 deletions.
8 changes: 2 additions & 6 deletions src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,12 @@ Logger.open = function (value) {
};

Logger.close = function (stream) {
// Check if stream.f is a valid stream and has the 'end' method
if (stream.f !== process.stdout && stream.f && typeof stream.f.end === 'function') {
stream.f.end(); // Close the stream
} else if (stream.f !== process.stdout) {
winston.warn('Logger stream is invalid or already closed.');
if (stream.f !== process.stdout && stream.f) {
stream.end();
}
stream.f = null;
};


Logger.monitorConfig = function (socket, data) {
/*
* This monitor's when a user clicks "save" in the Logger section of the admin panel
Expand Down
17 changes: 1 addition & 16 deletions src/webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,28 +218,13 @@ function setupHelmet(app) {


function setupFavicon(app) {
// Ensure 'brand:favicon' is available or use a default 'favicon.ico'
let faviconPath = meta.config['brand:favicon'] || 'favicon.ico';

// Ensure 'base_dir' is available, log an error if not
const baseDir = nconf.get('base_dir');
if (!baseDir) {
winston.error('Base directory is not defined in configuration.');
return;
}

// Construct the full path for the favicon
faviconPath = path.join(baseDir, 'public', faviconPath.replace(/assets\/uploads/, 'uploads'));

// Check if the favicon file exists before setting it up
faviconPath = path.join(nconf.get('base_dir'), 'public', faviconPath.replace(/assets\/uploads/, 'uploads'));
if (file.existsSync(faviconPath)) {
app.use(nconf.get('relative_path'), favicon(faviconPath));
} else {
winston.warn(`Favicon not found at ${faviconPath}, skipping favicon setup.`);
}
}


function configureBodyParser(app) {
const urlencodedOpts = nconf.get('bodyParser:urlencoded') || {};
if (!urlencodedOpts.hasOwnProperty('extended')) {
Expand Down
23 changes: 0 additions & 23 deletions test/mocks/databasemock.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,29 +180,6 @@ before(async function () {
await setupMockDefaults();
});
});
describe('webserver.listen - handleArrayPort', () => {
it('should handle an array of ports and select the first one', async () => {
sinon.stub(nconf, 'get').withArgs('port').returns([3000, 3001, 3002]);

const webserver = require('../../src/webserver');
const selectedPort = await webserver.listen();
expect(selectedPort).to.equal(3000);
sinon.restore();
});

it('should throw an error if the ports array is empty', async () => {
sinon.stub(nconf, 'get').withArgs('port').returns([]); // Empty array

const webserver = require('../../src/webserver');

try {
await webserver.listen();
} catch (err) {
expect(err.message).to.include('[startup] empty ports array in config.json');
}
sinon.restore();
});
});
});

async function setupMockDefaults() {
Expand Down

0 comments on commit cfa9d11

Please sign in to comment.