Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/pull-request-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,33 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- run: npm clean-install

- run: npm run prepublishOnly

- run: npm pack

- name: Upload tarball artifact
uses: actions/[email protected]
with:
name: bundle
path: ./dist
- run: npm pack

- name: Upload tarball artifact
uses: actions/[email protected]
with:
name: tarball
path: ./*.tgz

- run: npm test
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

- Bumped dependencies, by [@compulim](https://github.com/compulim), in PR [#426](https://github.com/microsoft/BotFramework-DirectLineJS/pull/426)
- Production dependencies
- [`[email protected]`](https://npmjs.com/package/botframework-streaming)

## [0.15.5] - 2023-10-10

### Added
Expand Down
13 changes: 6 additions & 7 deletions __tests__/directLineStreaming/connect.fail.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import fetch from 'node-fetch';

import { ConnectionStatus } from '../../src/directLine';
import { DirectLineStreaming } from '../../src/directLineStreaming';
import waitFor from './__setup__/external/testing-library/waitFor';
import mockObserver from './__setup__/mockObserver';
import setupBotProxy from './__setup__/setupBotProxy';
import waitFor from './__setup__/external/testing-library/waitFor';

const MOCKBOT3_URL = 'https://webchat-mockbot3.azurewebsites.net/';
const TOKEN_URL = 'https://webchat-mockbot3.azurewebsites.net/api/token/directlinease';
const TOKEN_URL =
'https://hawo-mockbot4-token-app.blueriver-ce85e8f0.westus.azurecontainerapps.io/api/token/directlinease?bot=echo%20bot';

afterEach(() => jest.useRealTimers());

Expand All @@ -23,10 +23,9 @@ test('connect fail should signal properly', async () => {
return Date.now();
});

const [{ directLineStreamingURL }, { token }] = await Promise.all([
setupBotProxy({ onUpgrade, streamingBotURL: MOCKBOT3_URL }),
fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json())
]);
const { domain, token } = await fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json());

const { directLineStreamingURL } = await setupBotProxy({ onUpgrade, streamingBotURL: new URL('/', domain).href });

// GIVEN: A Direct Line Streaming chat adapter.
const activityObserver = mockObserver();
Expand Down
13 changes: 6 additions & 7 deletions __tests__/directLineStreaming/connect.success.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ import fetch from 'node-fetch';

import { ConnectionStatus } from '../../src/directLine';
import { DirectLineStreaming } from '../../src/directLineStreaming';
import waitFor from './__setup__/external/testing-library/waitFor';
import mockObserver from './__setup__/mockObserver';
import setupBotProxy from './__setup__/setupBotProxy';
import waitFor from './__setup__/external/testing-library/waitFor';

const MOCKBOT3_URL = 'https://webchat-mockbot3.azurewebsites.net/';
const TOKEN_URL = 'https://webchat-mockbot3.azurewebsites.net/api/token/directlinease';
const TOKEN_URL =
'https://hawo-mockbot4-token-app.blueriver-ce85e8f0.westus.azurecontainerapps.io/api/token/directlinease?bot=echo%20bot';

afterEach(() => jest.useRealTimers());

test('should connect', async () => {
jest.useFakeTimers({ now: 0 });

const [{ directLineStreamingURL }, { token }] = await Promise.all([
setupBotProxy({ streamingBotURL: MOCKBOT3_URL }),
fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json())
]);
const { domain, token } = await fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json());

const { directLineStreamingURL } = await setupBotProxy({ streamingBotURL: new URL('/', domain).href });

// GIVEN: A Direct Line Streaming chat adapter.
const activityObserver = mockObserver();
Expand Down
13 changes: 6 additions & 7 deletions __tests__/directLineStreaming/end.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ import fetch from 'node-fetch';

import { ConnectionStatus } from '../../src/directLine';
import { DirectLineStreaming } from '../../src/directLineStreaming';
import waitFor from './__setup__/external/testing-library/waitFor';
import mockObserver from './__setup__/mockObserver';
import setupBotProxy from './__setup__/setupBotProxy';
import waitFor from './__setup__/external/testing-library/waitFor';

const MOCKBOT3_URL = 'https://webchat-mockbot3.azurewebsites.net/';
const TOKEN_URL = 'https://webchat-mockbot3.azurewebsites.net/api/token/directlinease';
const TOKEN_URL =
'https://hawo-mockbot4-token-app.blueriver-ce85e8f0.westus.azurecontainerapps.io/api/token/directlinease?bot=echo%20bot';

afterEach(() => jest.useRealTimers());

test('should connect', async () => {
jest.useFakeTimers({ now: 0 });

const [{ directLineStreamingURL }, { token }] = await Promise.all([
setupBotProxy({ streamingBotURL: MOCKBOT3_URL }),
fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json())
]);
const { domain, token } = await fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json());

const { directLineStreamingURL } = await setupBotProxy({ streamingBotURL: new URL('/', domain).href });

// GIVEN: A Direct Line Streaming chat adapter.
const activityObserver = mockObserver();
Expand Down
28 changes: 13 additions & 15 deletions __tests__/directLineStreaming/options.networkInformation.story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import fetch from 'node-fetch';

import { ConnectionStatus } from '../../src/directLine';
import { DirectLineStreaming } from '../../src/directLineStreaming';
import waitFor from './__setup__/external/testing-library/waitFor';
import mockObserver from './__setup__/mockObserver';
import setupBotProxy from './__setup__/setupBotProxy';
import waitFor from './__setup__/external/testing-library/waitFor';

type MockObserver<T> = ReturnType<typeof mockObserver>;
type ResultOfPromise<T> = T extends PromiseLike<infer P> ? P : never;

const MOCKBOT3_URL = 'https://webchat-mockbot3.azurewebsites.net/';
const TOKEN_URL = 'https://webchat-mockbot3.azurewebsites.net/api/token/directlinease';
const TOKEN_URL =
'https://hawo-mockbot4-token-app.blueriver-ce85e8f0.westus.azurecontainerapps.io/api/token/directlinease?bot=echo%20bot';

jest.setTimeout(10_000);

Expand Down Expand Up @@ -41,24 +41,22 @@ describe('Direct Line Streaming chat adapter with Network Information API', () =
}
});

(global as any).navigator = {
get connection() {
return networkInformation;
}
};
// Node.js 22.x has global.navigator, but Node.js 18.x and 20.x don't.
if (!global.navigator) {
(global as any).navigator = {};
}

(global as any).navigator.connection = networkInformation;

let token: string;
const { domain, token } = await fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json());

[botProxy, { token }] = await Promise.all([
setupBotProxy({ streamingBotURL: MOCKBOT3_URL }),
fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json())
]);
const botProxy = await setupBotProxy({ streamingBotURL: new URL('/', domain).href });

activityObserver = mockObserver();
connectionStatusObserver = mockObserver();
directLine = new DirectLineStreaming({
domain: botProxy.directLineStreamingURL,
networkInformation: navigator.connection,
networkInformation: (navigator as any).connection,
token
});

Expand Down Expand Up @@ -114,7 +112,7 @@ describe('Direct Line Streaming chat adapter with Network Information API', () =
// WHEN: "change" event is received.
describe('when "change" event is received', () => {
beforeEach(() => {
(navigator.connection as any).type = 'bluetooth';
(navigator as any).connection.type = 'bluetooth';
});

// THEN: Should observe "Connecting" -> "Online" again.
Expand Down
10 changes: 4 additions & 6 deletions __tests__/directLineStreaming/postActivity.fail.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import mockObserver from './__setup__/mockObserver';
import setupBotProxy from './__setup__/setupBotProxy';
import waitFor from './__setup__/external/testing-library/waitFor';

const MOCKBOT3_URL = 'https://webchat-mockbot3.azurewebsites.net/';
const TOKEN_URL = 'https://webchat-mockbot3.azurewebsites.net/api/token/directlinease';
const TOKEN_URL = 'https://hawo-mockbot4-token-app.blueriver-ce85e8f0.westus.azurecontainerapps.io/api/token/directlinease?bot=echo%20bot';

afterEach(() => jest.useRealTimers());

Expand All @@ -18,10 +17,9 @@ test('should send activity', async () => {

onWebSocketSendMessage.mockImplementation((data, socket, req, next) => next(data, socket, req));

const [{ directLineStreamingURL }, { token }] = await Promise.all([
setupBotProxy({ onWebSocketSendMessage, streamingBotURL: MOCKBOT3_URL }),
fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json())
]);
const { domain, token } = await fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json());

const { directLineStreamingURL } = await setupBotProxy({ onWebSocketSendMessage, streamingBotURL: new URL('/', domain).href });

// GIVEN: A Direct Line Streaming chat adapter.
const activityObserver = mockObserver();
Expand Down
10 changes: 4 additions & 6 deletions __tests__/directLineStreaming/postActivity.success.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ import mockObserver from './__setup__/mockObserver';
import setupBotProxy from './__setup__/setupBotProxy';
import waitFor from './__setup__/external/testing-library/waitFor';

const MOCKBOT3_URL = 'https://webchat-mockbot3.azurewebsites.net/';
const TOKEN_URL = 'https://webchat-mockbot3.azurewebsites.net/api/token/directlinease';
const TOKEN_URL = 'https://hawo-mockbot4-token-app.blueriver-ce85e8f0.westus.azurecontainerapps.io/api/token/directlinease?bot=echo%20bot';

afterEach(() => jest.useRealTimers());

test('should send activity', async () => {
jest.useFakeTimers({ now: 0 });

const [{ directLineStreamingURL }, { token }] = await Promise.all([
setupBotProxy({ streamingBotURL: MOCKBOT3_URL }),
fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json())
]);
const { domain, token } = await fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json());

const { directLineStreamingURL } = await setupBotProxy({ streamingBotURL: new URL('/', domain).href });

// GIVEN: A Direct Line Streaming chat adapter.
const activityObserver = mockObserver();
Expand Down
16 changes: 9 additions & 7 deletions __tests__/directLineStreaming/retryConnect.fail.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import fetch from 'node-fetch';

import { ConnectionStatus } from '../../src/directLine';
import { DirectLineStreaming } from '../../src/directLineStreaming';
import waitFor from './__setup__/external/testing-library/waitFor';
import mockObserver from './__setup__/mockObserver';
import setupBotProxy from './__setup__/setupBotProxy';
import waitFor from './__setup__/external/testing-library/waitFor';

const MOCKBOT3_URL = 'https://webchat-mockbot3.azurewebsites.net/';
const TOKEN_URL = 'https://webchat-mockbot3.azurewebsites.net/api/token/directlinease';
const TOKEN_URL =
'https://hawo-mockbot4-token-app.blueriver-ce85e8f0.westus.azurecontainerapps.io/api/token/directlinease?bot=echo%20bot';

jest.setTimeout(15000);

Expand All @@ -20,10 +20,12 @@ test('reconnect fail should stop', async () => {

onUpgrade.mockImplementation((req, socket, head, next) => next(req, socket, head));

const [{ closeAllWebSocketConnections, directLineStreamingURL }, { token }] = await Promise.all([
setupBotProxy({ onUpgrade, streamingBotURL: MOCKBOT3_URL }),
fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json())
]);
const { domain, token } = await fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json());

const { closeAllWebSocketConnections, directLineStreamingURL } = await setupBotProxy({
onUpgrade,
streamingBotURL: new URL('/', domain).href
});

// GIVEN: A Direct Line Streaming chat adapter.
const activityObserver = mockObserver();
Expand Down
44 changes: 24 additions & 20 deletions __tests__/directLineStreaming/retryConnect.success.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import fetch from 'node-fetch';
import { ConnectionStatus } from '../../src/directLine';
import { DirectLineStreaming } from '../../src/directLineStreaming';
import activityTimestampComparer from './__setup__/activityTimestampComparer';
import waitFor from './__setup__/external/testing-library/waitFor';
import mockObserver from './__setup__/mockObserver';
import setupBotProxy from './__setup__/setupBotProxy';
import waitFor from './__setup__/external/testing-library/waitFor';

const MOCKBOT3_URL = 'https://webchat-mockbot3.azurewebsites.net/';
const TOKEN_URL = 'https://webchat-mockbot3.azurewebsites.net/api/token/directlinease';
const TOKEN_URL =
'https://hawo-mockbot4-token-app.blueriver-ce85e8f0.westus.azurecontainerapps.io/api/token/directlinease?bot=echo%20bot';

afterEach(() => jest.useRealTimers());

Expand All @@ -24,10 +24,12 @@ test.each([['with stable connection'], ['without stable connection']])(
return Date.now();
});

const [{ closeAllWebSocketConnections, directLineStreamingURL }, { token }] = await Promise.all([
setupBotProxy({ onUpgrade, streamingBotURL: MOCKBOT3_URL }),
fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json())
]);
const { domain, token } = await fetch(TOKEN_URL, { method: 'POST' }).then(res => res.json());

const { closeAllWebSocketConnections, directLineStreamingURL } = await setupBotProxy({
onUpgrade,
streamingBotURL: new URL('/', domain).href
});

// GIVEN: A Direct Line Streaming chat adapter.
const activityObserver = mockObserver();
Expand Down Expand Up @@ -119,19 +121,21 @@ test.each([['with stable connection'], ['without stable connection']])(
);

// THEN: Bot should reply and the activity should echo back.
await waitFor(() => {
expect([...activityObserver.observations].sort(([, , x], [, , y]) => activityTimestampComparer(x, y))).toEqual([
[expect.any(Number), 'next', expect.activityContaining('Hello and welcome!')],
[expect.any(Number), 'next', expect.activityContaining('Hello and welcome!')],
[
expect.any(Number),
'next',
expect.activityContaining('Hello, World!', { id: postActivityObserver.observations[0][2] })
],
[expect.any(Number), 'next', expect.activityContaining('Echo: Hello, World!')]
]),
{ timeout: 5000 };
});
await waitFor(
() => {
expect([...activityObserver.observations].sort(([, , x], [, , y]) => activityTimestampComparer(x, y))).toEqual([
[expect.any(Number), 'next', expect.activityContaining('Hello and welcome!')],
[expect.any(Number), 'next', expect.activityContaining('Hello and welcome!')],
[
expect.any(Number),
'next',
expect.activityContaining('Hello, World!', { id: postActivityObserver.observations[0][2] })
],
[expect.any(Number), 'next', expect.activityContaining('Echo: Hello, World!')]
]);
},
{ timeout: 5000 }
);
},
15000
);
Loading