-
Notifications
You must be signed in to change notification settings - Fork 128
Add tests and update build scripts #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
1f7d64c
Initial commit for tests
compulim 8712825
Add proxy to Web Socket
compulim 45b30ee
Use global agent
compulim 4b28aa6
Fix reliability
compulim 7c76df7
Add upload attachment test
compulim f8f5622
Add airplane mode test
compulim 7e69ceb
Clean up
compulim 3a874fa
Add fatal test
compulim 6f61a48
Refactor
compulim c6b2ecf
Fix build script
compulim f427673
Update build script
compulim 5d9bbb9
Fix tests
compulim 0c25b29
Update bundle folder
compulim 44ec9a4
Update clean scripts
compulim fc2b46d
Update bundle name
compulim f9a8fcc
Add entry
compulim f7e00bf
Skip all transforms for tests
compulim 1625407
Removing unnecessary lines
compulim 4fedcf8
Rename cres to res
compulim d14b3be
Rename equalityFn to predicate
compulim c616b33
Apply suggestions from code review
compulim 9f9488e
Rename to createPromiseStack
compulim 5f22593
Merge branch 'feat-tests' of https://github.com/compulim/BotFramework…
compulim 04cd248
Use ConnectionStatus.Online
compulim 4c37f71
Typo
compulim 37c46a2
Rename `sendingActivity` to `activityFromUser`
compulim 6e80f46
Clean up
compulim 2b88728
Use dl_* user ID
compulim 1e349f2
Rename back to .babelrc.js because babel-jest
compulim f94c5c0
Use dl_*
compulim 12ee071
Clean up
compulim 974c63a
Reuse waitForActivity
compulim dbe74c8
Rename
compulim 15a01cd
Skip test using secret if DIRECT_LINE_SECRET is not set
compulim 4abe413
Apply PR review changes
compulim a37dafa
Fix tests
compulim 7d9f5d0
Fix tests
compulim 6507ae6
Apply PR changes
compulim 9485875
Stack -> queue and using a single queue
compulim e10ba2d
Remove promise-race-map
compulim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| module.exports = { | ||
| env: { | ||
| test: { | ||
| plugins: [ | ||
| 'babel-plugin-istanbul' | ||
| ] | ||
| } | ||
| }, | ||
| overrides: [{ | ||
| include: ['./__tests__'], | ||
| presets: [ | ||
| ['@babel/preset-env', { | ||
| targets: { | ||
| node: 12 | ||
| } | ||
| }], | ||
| '@babel/preset-typescript' | ||
| ] | ||
| }], | ||
| plugins: [ | ||
| '@babel/plugin-proposal-class-properties', | ||
| '@babel/plugin-proposal-object-rest-spread', | ||
| '@babel/plugin-transform-runtime', | ||
| 'babel-plugin-transform-inline-environment-variables' | ||
| ], | ||
| presets: [ | ||
| ['@babel/preset-env', { | ||
compulim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| forceAllTransforms: true, | ||
| modules: 'commonjs' | ||
| }], | ||
| '@babel/preset-typescript' | ||
| ], | ||
| sourceMaps: 'inline' | ||
| }; | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,4 @@ | ||
| /.idea | ||
| /built | ||
| /.env | ||
| /dist | ||
| /lib | ||
| /node_modules | ||
|
|
||
| /directLine.js | ||
| /directLine-instrumented.js | ||
| /stats.html |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "userId": "dl_12345", | ||
| "timeouts": { | ||
| "default": 5000, | ||
| "rest": 10000, | ||
| "streamingExtensions": 10000, | ||
| "webSocket": 10000 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import 'dotenv/config'; | ||
|
|
||
| import onErrorResumeNext from 'on-error-resume-next'; | ||
|
|
||
| import { timeouts } from './constants.json'; | ||
| import * as createDirectLine from './setup/createDirectLine'; | ||
| import postActivity from './setup/postActivity'; | ||
| import waitForBotToEcho from './setup/waitForBotToEcho'; | ||
| import waitForConnected from './setup/waitForConnected'; | ||
|
|
||
| describe('Happy path', () => { | ||
| let unsubscribes; | ||
|
|
||
| beforeEach(() => unsubscribes = []); | ||
| afterEach(() => unsubscribes.forEach(fn => onErrorResumeNext(fn))); | ||
|
|
||
| describe('should connect, send message, and receive echo from bot', () => { | ||
| let directLine; | ||
|
|
||
| describe('using REST', () => { | ||
| beforeEach(() => jest.setTimeout(timeouts.rest)); | ||
|
|
||
| test('with secret', async () => { | ||
| directLine = await createDirectLine.forREST({ token: false }); | ||
| }); | ||
|
|
||
| test('with token', async () => { | ||
| directLine = await createDirectLine.forREST({ token: true }); | ||
| }); | ||
| }); | ||
|
|
||
| // test('using Streaming Extensions', async () => { | ||
corinagum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // jest.setTimeout(timeouts.webSocket); | ||
| // directLine = await createDirectLine.forStreamingExtensions(); | ||
| // }); | ||
|
|
||
| describe('using Web Socket', () => { | ||
| beforeEach(() => jest.setTimeout(timeouts.webSocket)); | ||
|
|
||
| test('with secret', async () => { | ||
| directLine = await createDirectLine.forWebSocket({ token: false }); | ||
| }); | ||
|
|
||
| test('with token', async () => { | ||
| directLine = await createDirectLine.forWebSocket({ token: false }); | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| // If directLine object is undefined, that means the test is failing. | ||
| if (!directLine) { return; } | ||
|
|
||
| unsubscribes.push(directLine.end.bind(directLine)); | ||
| unsubscribes.push(await waitForConnected(directLine)); | ||
|
|
||
| await Promise.all([ | ||
| postActivity(directLine, { text: 'Hello, World!', type: 'message' }), | ||
| waitForBotToEcho(directLine, ({ text }) => text === 'Hello, World!') | ||
| ]); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import 'dotenv/config'; | ||
|
|
||
| import onErrorResumeNext from 'on-error-resume-next'; | ||
|
|
||
| import { timeouts } from './constants.json'; | ||
| import * as createDirectLine from './setup/createDirectLine'; | ||
| import fetchAsBase64 from './setup/fetchAsBase64'; | ||
| import postActivity from './setup/postActivity'; | ||
| import waitForBotToEcho from './setup/waitForBotToEcho'; | ||
| import waitForConnected from './setup/waitForConnected'; | ||
|
|
||
| describe('Happy path', () => { | ||
| let unsubscribes; | ||
|
|
||
| beforeEach(() => unsubscribes = []); | ||
| afterEach(() => unsubscribes.forEach(fn => onErrorResumeNext(fn))); | ||
|
|
||
| describe('upload 2 attachments with text messages', () => { | ||
| let directLine; | ||
|
|
||
| describe('using REST', () => { | ||
| beforeEach(() => jest.setTimeout(timeouts.rest)); | ||
|
|
||
| test('with secret', async () => { | ||
| directLine = await createDirectLine.forREST({ token: false }); | ||
| }); | ||
|
|
||
| test('with token', async () => { | ||
| directLine = await createDirectLine.forREST({ token: true }); | ||
| }); | ||
| }); | ||
|
|
||
| // test('using Streaming Extensions', async () => { | ||
corinagum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // jest.setTimeout(timeouts.webSocket); | ||
| // directLine = await createDirectLine.forStreamingExtensions(); | ||
| // }); | ||
|
|
||
| describe('using Web Socket', () => { | ||
| beforeEach(() => jest.setTimeout(timeouts.webSocket)); | ||
|
|
||
| test('with secret', async () => { | ||
| directLine = await createDirectLine.forWebSocket({ token: false }); | ||
| }); | ||
|
|
||
| test('with token', async () => { | ||
| directLine = await createDirectLine.forWebSocket({ token: false }); | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| // If directLine object is undefined, that means the test is failing. | ||
| if (!directLine) { return; } | ||
|
|
||
| unsubscribes.push(directLine.end.bind(directLine)); | ||
| unsubscribes.push(await waitForConnected(directLine)); | ||
|
|
||
| const activityFromUser = { | ||
| // DirectLine.postActivityWithAttachments support "contentUrl" only but not "content" | ||
| attachments: [{ | ||
| contentType: 'image/png', | ||
| contentUrl: 'https://webchat-waterbottle.azurewebsites.net/public/surfacelogo.png' | ||
| }, { | ||
| contentType: 'image/png', | ||
| contentUrl: 'https://webchat-waterbottle.azurewebsites.net/public/xboxlogo.png' | ||
| }], | ||
| text: 'Hello, World!', | ||
| type: 'message' | ||
| }; | ||
|
|
||
| await Promise.all([ | ||
| postActivity(directLine, activityFromUser), | ||
| waitForBotToEcho(directLine, async ({ attachments, text }) => { | ||
| if (text === 'Hello, World!') { | ||
| // Bug #194 is causing trouble on the order of attachments sent. | ||
| // https://github.com/microsoft/BotFramework-DirectLineJS/issues/194 | ||
|
|
||
| // Until the bug is fixed, we will not check the order. | ||
|
|
||
| const [expecteds, actuals] = await Promise.all([ | ||
| Promise.all([ | ||
| fetchAsBase64(activityFromUser.attachments[0].contentUrl), | ||
| fetchAsBase64(activityFromUser.attachments[1].contentUrl) | ||
| ]), | ||
| Promise.all([ | ||
| fetchAsBase64(attachments[0].contentUrl), | ||
| fetchAsBase64(attachments[1].contentUrl) | ||
| ]) | ||
| ]); | ||
|
|
||
| expect(attachments[0]).not.toBe(attachments[1]); | ||
| expect(~actuals.indexOf(expecteds[0])).toBeTruthy(); | ||
| expect(~actuals.indexOf(expecteds[1])).toBeTruthy(); | ||
|
|
||
| // Use the commented code below after bug #194 is fixed. | ||
| // https://github.com/microsoft/BotFramework-DirectLineJS/issues/194 | ||
|
|
||
| // await expect(fetchAsBase64(attachments[0].contentUrl)).resolves.toBe(await fetchAsBase64(activityFromUser.attachments[0].contentUrl)); | ||
| // await expect(fetchAsBase64(attachments[1].contentUrl)).resolves.toBe(await fetchAsBase64(activityFromUser.attachments[1].contentUrl)); | ||
|
|
||
| return true; | ||
| } | ||
| }) | ||
| ]); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.