Skip to content

Commit 4cafee3

Browse files
committed
Revert "fix: move tests to lib directory"
This reverts commit 90caf09.
1 parent c51e9e9 commit 4cafee3

9 files changed

+75
-75
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ logs/*.log
66
lib/state.json
77
*.md
88
.eslintrc.json
9-
lib/test
9+
test
1010
.eslintignore
1111
dist

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"scripts": {
5050
"lint": "eslint '*/**/*.js'",
5151
"lint-fix": "eslint '*/**/*.js' --fix",
52-
"test": "node ./node_modules/mocha/bin/_mocha 'dist/**/*.spec.js' --exit",
52+
"test": "node ./node_modules/mocha/bin/_mocha './{,!(node_modules)/**/}*.spec.js' --exit",
5353
"test:ci": "yarn test",
5454
"start": "node dist/index.js",
5555
"version": "exit 0",

lib/test/ContainerLogger.unit.spec.js renamed to test/ContainerLogger.unit.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const sinon = require('sinon');
66
const proxyquire = require('proxyquire');
77
const promiseRetry = require('promise-retry');
88
const sinonChai = require('sinon-chai');
9-
const LoggerStrategy = require('../enums').LoggerStrategy;
9+
const LoggerStrategy = require('../lib/enums').LoggerStrategy;
1010
const { EventEmitter } = require('events');
1111
const { Writable, Readable, PassThrough } = require('stream');
1212

@@ -15,7 +15,7 @@ chai.use(sinonChai);
1515

1616
const promiseRetrySpy = sinon.spy((err) => Q.reject(err));
1717

18-
const ContainerLogger = proxyquire('../ContainerLogger', {
18+
const ContainerLogger = proxyquire('../lib/ContainerLogger', {
1919
'promise-retry': (cb) => cb(promiseRetrySpy, 1),
2020
});
2121

lib/test/addNewMask.unit.spec.js renamed to test/addNewMask.unit.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('addNewMask', () => {
5757
stubGetServerAddress.resolves(serverAddress);
5858
stubGot.post.resolves({ statusCode: 201 });
5959

60-
const { updateMasks, exitHandler } = proxyquire('../addNewMask', {
60+
const { updateMasks, exitHandler } = proxyquire('../lib/addNewMask', {
6161
'./helpers': { getServerAddress: stubGetServerAddress },
6262
});
6363
process.listeners('exit').forEach((listener) => {
@@ -77,7 +77,7 @@ describe('addNewMask', () => {
7777
describe('negative', () => {
7878
it('should fail if the server address is not available', async () => {
7979
stubGetServerAddress.rejects('could not get server address');
80-
const { updateMasks, exitHandler } = proxyquire('../addNewMask', {
80+
const { updateMasks, exitHandler } = proxyquire('../lib/addNewMask', {
8181
'./helpers': {
8282
getServerAddress: stubGetServerAddress,
8383
},
@@ -94,7 +94,7 @@ describe('addNewMask', () => {
9494

9595
it('should fail if the server address is not valid URL', async () => {
9696
stubGetServerAddress.resolves('foo');
97-
const { updateMasks, exitHandler } = proxyquire('../addNewMask', {
97+
const { updateMasks, exitHandler } = proxyquire('../lib/addNewMask', {
9898
'./helpers': {
9999
getServerAddress: stubGetServerAddress,
100100
},
@@ -116,7 +116,7 @@ describe('addNewMask', () => {
116116
statusCode: 500,
117117
body: 'Internal Server Error',
118118
});
119-
const { updateMasks, exitHandler } = proxyquire('../addNewMask', {
119+
const { updateMasks, exitHandler } = proxyquire('../lib/addNewMask', {
120120
'./helpers': { getServerAddress: stubGetServerAddress },
121121
});
122122
process.listeners('exit').forEach((listener) => {
@@ -132,7 +132,7 @@ describe('addNewMask', () => {
132132

133133
describe('exitHandler', () => {
134134
it('should set exit code to 3 if the original exit code is 0 and variable was not masked', () => {
135-
const { exitHandler } = proxyquire('../addNewMask', {});
135+
const { exitHandler } = proxyquire('../lib/addNewMask', {});
136136
process.listeners('exit').forEach((listener) => {
137137
if (listener === exitHandler) {
138138
process.removeListener('exit', listener);
@@ -145,7 +145,7 @@ describe('addNewMask', () => {
145145
});
146146

147147
it('should set exit code to 3 if the original exit code is 0 and variable was not masked', () => {
148-
const { exitHandler } = proxyquire('../addNewMask', {});
148+
const { exitHandler } = proxyquire('../lib/addNewMask', {});
149149
process.listeners('exit').forEach((listener) => {
150150
if (listener === exitHandler) {
151151
process.removeListener('exit', listener);
@@ -165,7 +165,7 @@ describe('addNewMask', () => {
165165
const serverAddress = 'https://xkcd.com/605/'
166166
stubGetServerAddress.resolves(serverAddress);
167167
stubGot.post.resolves({ statusCode: 201 });
168-
const { updateMasks, exitHandler } = proxyquire('../addNewMask', {
168+
const { updateMasks, exitHandler } = proxyquire('../lib/addNewMask', {
169169
'./helpers': { getServerAddress: stubGetServerAddress },
170170
});
171171
process.listeners('exit').forEach((listener) => {

lib/test/helpers.unit.spec.js renamed to test/helpers.unit.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ describe('helpers', () => {
2828
it('should write the server address to the file', async () => {
2929
const SERVER_ADDRESS_PATH = 'little/bobby/tables/we/call/him';
3030
const serverAddress = 'foo';
31-
const { saveServerAddress } = proxyquire('../helpers.js', {
31+
const { saveServerAddress } = proxyquire('../lib/helpers.js', {
3232
'node:fs/promises': stubFsPromises,
3333
'cf-logs': { Logger: () => stubLogger },
3434
'./const': { SERVER_ADDRESS_PATH },
3535
});
3636
await saveServerAddress(serverAddress);
3737
expect(stubFsPromises.writeFile).to.have.been.calledOnceWithExactly(SERVER_ADDRESS_PATH, serverAddress, { encoding: 'utf8' });
3838
});
39-
39+
4040
it('should fail if the file cannot be written', async () => {
41-
const { saveServerAddress } = proxyquire('../helpers.js', {
41+
const { saveServerAddress } = proxyquire('../lib/helpers.js', {
4242
'node:fs/promises': stubFsPromises,
4343
'cf-logs': { Logger: () => stubLogger },
4444
});
@@ -53,12 +53,12 @@ describe('helpers', () => {
5353
}
5454
});
5555
});
56-
56+
5757
describe('getServerAddress()', () => {
5858
it('should read the server address from the file', async () => {
5959
const SERVER_ADDRESS_PATH = 'little/bobby/tables/we/call/him';
6060
const serverAddress = 'foo';
61-
const { getServerAddress } = proxyquire('../helpers.js', {
61+
const { getServerAddress } = proxyquire('../lib/helpers.js', {
6262
'node:fs/promises': stubFsPromises,
6363
'cf-logs': { Logger: () => stubLogger },
6464
'./const': { SERVER_ADDRESS_PATH },
@@ -68,9 +68,9 @@ describe('helpers', () => {
6868
expect(result).to.be.equal(serverAddress);
6969
expect(stubFsPromises.readFile).to.have.been.calledOnceWithExactly(SERVER_ADDRESS_PATH, { encoding: 'utf8' });
7070
});
71-
71+
7272
it('should fail if the file cannot be read', async () => {
73-
const { getServerAddress } = proxyquire('../helpers.js', {
73+
const { getServerAddress } = proxyquire('../lib/helpers.js', {
7474
'node:fs/promises': stubFsPromises,
7575
'cf-logs': { Logger: () => stubLogger },
7676
});
@@ -87,7 +87,7 @@ describe('helpers', () => {
8787
});
8888

8989
it('should write/read to/from the same location', async () => {
90-
const { saveServerAddress, getServerAddress } = require('../helpers.js');
90+
const { saveServerAddress, getServerAddress } = require('../lib/helpers.js');
9191
const serverAddress = 'http://g.codefresh.io';
9292
await saveServerAddress(serverAddress);
9393
const result = await getServerAddress();

lib/test/isReady.unit.spec.js renamed to test/isReady.unit.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const chai = require('chai');
22
const sinon = require('sinon');
3-
const { ContainerHandlingStatus } = require('../enums');
3+
const { ContainerHandlingStatus } = require('../lib/enums');
44
const proxyquire = require('proxyquire');
55

66
const expect = chai.expect;
@@ -21,7 +21,7 @@ describe('isReady script', () => {
2121
it('Should check exit with 0 code if container logger is ready', () => {
2222
const state = JSON.stringify({ status: 'ready', containers: {} })
2323
process.argv = [];
24-
proxyquire('../isReady.js', {
24+
proxyquire('../lib/isReady.js', {
2525
'fs': {
2626
readFileSync: () => Buffer.from(state),
2727
},
@@ -31,7 +31,7 @@ describe('isReady script', () => {
3131
it('Should check exit with 1 code if container logger is not ready', () => {
3232
const state = JSON.stringify({ status: 'notReady', containers: {} })
3333
process.argv = [];
34-
proxyquire('../isReady.js', {
34+
proxyquire('../lib/isReady.js', {
3535
'fs': {
3636
readFileSync: () => Buffer.from(state),
3737
},
@@ -43,7 +43,7 @@ describe('isReady script', () => {
4343
it('Should check exit with 0 code if container is ready', () => {
4444
const state = JSON.stringify({ status: 'ready', containers: { 'container-id': { status: ContainerHandlingStatus.LISTENING } } })
4545
process.argv = ['foo', 'bar', 'container-id'];
46-
proxyquire('../isReady.js', {
46+
proxyquire('../lib/isReady.js', {
4747
'fs': {
4848
readFileSync: () => Buffer.from(state),
4949
},
@@ -53,7 +53,7 @@ describe('isReady script', () => {
5353
it('Should check exit with 0 code if container is waiting for start status', () => {
5454
const state = JSON.stringify({ status: 'ready', containers: { 'container-id': { status: ContainerHandlingStatus.WAITING_FOR_START } } })
5555
process.argv = ['foo', 'bar', 'container-id'];
56-
proxyquire('../isReady.js', {
56+
proxyquire('../lib/isReady.js', {
5757
'fs': {
5858
readFileSync: () => Buffer.from(state),
5959
},
@@ -63,7 +63,7 @@ describe('isReady script', () => {
6363
it('Should check exit with 0 code if container is finished status', () => {
6464
const state = JSON.stringify({ status: 'ready', containers: { 'container-id': { status: ContainerHandlingStatus.FINISHED } } })
6565
process.argv = ['foo', 'bar', 'container-id'];
66-
proxyquire('../isReady.js', {
66+
proxyquire('../lib/isReady.js', {
6767
'fs': {
6868
readFileSync: () => Buffer.from(state),
6969
},
@@ -73,12 +73,12 @@ describe('isReady script', () => {
7373
it('Should check exit with 1 code if container is not ready', () => {
7474
const state = JSON.stringify({ status: 'ready', containers: { 'container-id': { status: ContainerHandlingStatus.INITIALIZING } } })
7575
process.argv = ['foo', 'bar', 'container-id'];
76-
proxyquire('../isReady.js', {
76+
proxyquire('../lib/isReady.js', {
7777
'fs': {
7878
readFileSync: () => Buffer.from(state),
7979
},
8080
});
8181
expect(process.exit).to.have.been.calledOnceWith(1);
8282
});
8383
});
84-
});
84+
});

0 commit comments

Comments
 (0)