• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

microsoft / botbuilder-js / 10561952840

26 Aug 2024 02:45PM UTC coverage: 84.403%. Remained the same
10561952840

Pull #4731

github

web-flow
Merge d132507ca into 604e190e7
Pull Request #4731: bump: elliptic from 6.5.5 to 6.5.7 in /testing/browser-functional/browser-echo-bot

10011 of 13158 branches covered (76.08%)

Branch coverage included in aggregate %.

20433 of 22912 relevant lines covered (89.18%)

7137.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/libraries/botframework-streaming/src/utilities/createNodeServer.ts
1
/**
2
 * @module botframework-streaming
3
 */
4
/**
5
 * Copyright (c) Microsoft Corporation. All rights reserved.
6
 * Licensed under the MIT License.
7
 */
8

9
import { INodeServer, INodeSocket } from '../interfaces';
10

11
type ConnectionListener = (socket: INodeSocket) => void;
12

13
/**
14
 * Create a Node 'net' server
15
 *
16
 * @param callback Optional connection listener
17
 * @returns a Node 'net' server instance
18
 */
19
export function createNodeServer(callback?: ConnectionListener): INodeServer {
2✔
20
    if (callback && typeof callback !== 'function') {
11✔
21
        throw new TypeError("Invalid callback; callback parameter must be a function to create Node 'net' Server.");
1✔
22
    }
23

24
    const server = getServerFactory()(callback);
10✔
25
    if (!isNetServer(server)) {
10!
26
        throw new Error("Unable to create Node 'net' server");
×
27
    }
28

29
    return server;
10✔
30
}
31

32
/**
33
 * Get a function that creates a Node 'net' server instance
34
 *
35
 * @returns a server factory function
36
 */
37
export function getServerFactory(): (callback?: ConnectionListener) => INodeServer {
2✔
38
    if (typeof require !== undefined) {
13!
39
        // eslint-disable-next-line @typescript-eslint/no-var-requires
40
        return require('net').Server;
13✔
41
    }
42

43
    throw TypeError(
×
44
        "require is undefined. Must be in a Node module to require 'net' dynamically in order to fetch Server factory."
45
    );
46
}
47

48
// eslint-disable-next-line @typescript-eslint/no-explicit-any
49
function isNetServer(o: any): o is INodeServer {
50
    return hasCloseMethod(o) && hasListenMethod(o);
10✔
51
}
52

53
// eslint-disable-next-line @typescript-eslint/no-explicit-any
54
function hasCloseMethod(o: any): o is INodeServer {
55
    return o.close && typeof o.close === 'function';
10✔
56
}
57

58
// eslint-disable-next-line @typescript-eslint/no-explicit-any
59
function hasListenMethod(o: any): o is INodeServer {
60
    return o.listen && typeof o.listen === 'function';
10✔
61
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc