Skip to content

Commit 0d2f785

Browse files
tests(): fix integration tests
1 parent 0fb20e1 commit 0d2f785

2 files changed

Lines changed: 35 additions & 19 deletions

File tree

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { Injectable, OnApplicationShutdown } from '@nestjs/common';
12
import { Test } from '@nestjs/testing';
23
import { expect } from 'chai';
3-
import * as Sinon from 'sinon';
4-
import { Injectable, OnApplicationShutdown, ShutdownSignal } from '@nestjs/common';
5-
import { spawn, spawnSync } from 'child_process';
4+
import { spawnSync } from 'child_process';
65
import { join } from 'path';
6+
import * as Sinon from 'sinon';
77

88
@Injectable()
99
class TestInjectable implements OnApplicationShutdown {
@@ -23,26 +23,41 @@ describe('OnApplicationShutdown', () => {
2323
});
2424

2525
it('should call onApplicationShutdown if any shutdown signal gets invoked', done => {
26-
const result = spawnSync('ts-node', [join(__dirname, '../src/main.ts'), 'SIGHUP']);
27-
expect(result.stdout.toString().trim()).to.be.eq('Signal SIGHUP');
26+
const result = spawnSync('ts-node', [
27+
join(__dirname, '../src/main.ts'),
28+
'SIGHUP',
29+
]);
30+
expect(result.stdout.toString().trim() === 'Signal SIGHUP').to.be.true;
2831
done();
29-
});
32+
}).timeout(5000);
3033

3134
it('should call onApplicationShutdown if a specific shutdown signal gets invoked', done => {
32-
const result = spawnSync('ts-node', [join(__dirname, '../src/main.ts'), 'SIGINT', 'SIGINT']);
35+
const result = spawnSync('ts-node', [
36+
join(__dirname, '../src/main.ts'),
37+
'SIGINT',
38+
'SIGINT',
39+
]);
3340
expect(result.stdout.toString().trim()).to.be.eq('Signal SIGINT');
3441
done();
35-
});
42+
}).timeout(5000);
3643

3744
it('should ignore system signals which are not specified', done => {
38-
const result = spawnSync('ts-node', [join(__dirname, '../src/main.ts'), 'SIGINT', 'SIGHUP']);
45+
const result = spawnSync('ts-node', [
46+
join(__dirname, '../src/main.ts'),
47+
'SIGINT',
48+
'SIGHUP',
49+
]);
3950
expect(result.stdout.toString().trim()).to.be.eq('');
4051
done();
41-
});
52+
}).timeout(5000);
4253

4354
it('should ignore system signals if "enableShutdownHooks" was not called', done => {
44-
const result = spawnSync('ts-node', [join(__dirname, '../src/main.ts'), 'SIGINT', 'NONE']);
55+
const result = spawnSync('ts-node', [
56+
join(__dirname, '../src/main.ts'),
57+
'SIGINT',
58+
'NONE',
59+
]);
4560
expect(result.stdout.toString().trim()).to.be.eq('');
4661
done();
47-
});
62+
}).timeout(5000);
4863
});

integration/microservices/src/disconnected.controller.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ export class DisconnectedClientController {
1616
const client = ClientProxyFactory.create(options);
1717
return client.send<number, number[]>({ cmd: 'none' }, [1, 2, 3]).pipe(
1818
/*tap(
19-
console.log.bind(console, 'data'),
20-
console.error.bind(console, 'error'),
21-
),*/
22-
catchError(({ code }) =>
23-
throwError(
19+
console.log.bind(console, 'data'),
20+
console.error.bind(console, 'error'),
21+
),*/
22+
catchError(error => {
23+
const { code } = error || { code: 'CONN_ERR' };
24+
return throwError(
2425
code === 'ECONNREFUSED' || code === 'CONN_ERR'
2526
? new RequestTimeoutException('ECONNREFUSED')
2627
: new InternalServerErrorException(),
27-
),
28-
),
28+
);
29+
}),
2930
);
3031
}
3132
}

0 commit comments

Comments
 (0)