Skip to content

Commit 5b6a397

Browse files
committed
fix: unit tests
1 parent 4cafee3 commit 5b6a397

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

lib/http-server/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import fastify from 'fastify';
44
import cfLogs from 'cf-logs';
55

66
import { saveServerAddress } from '../helpers';
7+
8+
// eslint-disable-next-line import/no-unresolved
79
import deprecatedImagesCollector from '../metric/deprecated-images/deprecated-images.collector';
810

911
const logger = cfLogs.Logger('codefresh:containerLogger');

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
"node": ">=16.20.2 <=20"
4848
},
4949
"scripts": {
50-
"lint": "eslint '*/**/*.js'",
51-
"lint-fix": "eslint '*/**/*.js' --fix",
52-
"test": "node ./node_modules/mocha/bin/_mocha './{,!(node_modules)/**/}*.spec.js' --exit",
50+
"lint": "eslint '*/**/*.{j,t}s'",
51+
"lint-fix": "eslint '*/**/*.{j,t}s' --fix",
52+
"test": "node ./node_modules/mocha/bin/_mocha --require ts-node/register 'test/**/*.spec.js' --exit",
5353
"test:ci": "yarn test",
5454
"start": "node dist/index.js",
5555
"version": "exit 0",

test/logger.unit.spec.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ chai.use(sinonChai);
1414

1515
const mockAddress = 'mockAddress';
1616
const stubFastifyPost = sinon.stub();
17+
const stubFastifyGet = sinon.stub();
1718
const stubFastifyListen = sinon.stub().resolves(mockAddress);
1819
const stubFastify = sinon.stub().returns({
1920
listen: stubFastifyListen,
2021
post: stubFastifyPost,
22+
get: stubFastifyGet,
2123
});
2224
const stubSaveServerAddress = sinon.stub().resolves();
2325

@@ -1696,11 +1698,17 @@ describe('Logger tests', () => {
16961698
};
16971699
const TaskLoggerFactory = sinon.spy(async () => taskLogger);
16981700

1701+
const HttpServer = proxyquire('../lib/http-server', {
1702+
'fastify': stubFastify,
1703+
'../helpers': {
1704+
saveServerAddress: stubSaveServerAddress,
1705+
}
1706+
});
1707+
16991708
const Logger = proxyquire('../lib/logger', {
17001709
'@codefresh-io/task-logger': { TaskLogger: TaskLoggerFactory },
1701-
'fastify': stubFastify,
1710+
'./http-server': HttpServer,
17021711
'./helpers': {
1703-
saveServerAddress: stubSaveServerAddress,
17041712
getPromiseWithResolvers,
17051713
},
17061714
});
@@ -1709,6 +1717,8 @@ describe('Logger tests', () => {
17091717
const taskLoggerConfig = { task: {}, opts: {} };
17101718
const findExistingContainers = false;
17111719

1720+
process.env.PORT = 1337;
1721+
process.env.HOST = '127.0.0.1';
17121722
const logger = new Logger({
17131723
loggerId,
17141724
taskLoggerConfig,
@@ -1717,8 +1727,6 @@ describe('Logger tests', () => {
17171727
logger._listenForNewContainers = sinon.spy();
17181728
logger._writeNewState = sinon.spy();
17191729
logger._listenForExistingContainers = sinon.spy();
1720-
process.env.PORT = 1337;
1721-
process.env.HOST = '127.0.0.1';
17221730
await logger.start();
17231731

17241732
expect(stubFastify).to.have.been.calledOnce;
@@ -1739,9 +1747,13 @@ describe('Logger tests', () => {
17391747
};
17401748
const TaskLoggerFactory = sinon.spy(async () => taskLogger);
17411749

1750+
const HttpServer = proxyquire('../lib/http-server', {
1751+
'fastify': stubFastify,
1752+
});
1753+
17421754
const Logger = proxyquire('../lib/logger', {
17431755
'@codefresh-io/task-logger': { TaskLogger: TaskLoggerFactory },
1744-
'fastify': stubFastify,
1756+
'./http-server': HttpServer,
17451757
'./helpers': {
17461758
saveServerAddress: stubSaveServerAddress,
17471759
getPromiseWithResolvers,

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
2626

2727
/* Modules */
28-
"module": "commonjs", /* Specify what module code is generated. */
28+
"module": "node16", /* Specify what module code is generated. */
2929
"rootDir": "./lib", /* Specify the root folder within your source files. */
30-
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
30+
"moduleResolution": "node16", /* Specify how TypeScript looks up a file from a given module specifier. */
3131
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
3232
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
3333
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */

0 commit comments

Comments
 (0)