-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove isBrowser, look for global members instead
- Loading branch information
Showing
7 changed files
with
66 additions
and
21 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
libraries/botframework-streaming/src/utilities/doesGlobalFileReaderExist.ts
This file contains 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 @@ | ||
/** | ||
* @module botframework-streaming | ||
*/ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
export const doesGlobalFileReaderExist = new Function('try {return typeof FileReader !== "undefined" && FileReader !== null;}catch(e){ return false;}'); |
9 changes: 9 additions & 0 deletions
9
libraries/botframework-streaming/src/utilities/doesGlobalWebSocketExist.ts
This file contains 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 @@ | ||
/** | ||
* @module botframework-streaming | ||
*/ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
export const doesGlobalWebSocketExist = new Function('try {return typeof WebSocket !== "undefined" && WebSocket !== null;}catch(e){ return false;}'); |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 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
43 changes: 39 additions & 4 deletions
43
libraries/botframework-streaming/tests/InternalUtilities.test.js
This file contains 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,10 +1,45 @@ | ||
const { isBrowser } = require('../lib/utilities'); | ||
const { doesGlobalFileReaderExist, doesGlobalWebSocketExist } = require('../lib/utilities'); | ||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
|
||
describe('Internal Utilities', () => { | ||
it('isBrowser() should return false when being run via Node.js', () => { | ||
// More specifically, it should return false when the global object is not window. | ||
expect(isBrowser()).to.be.false; | ||
it('doesGlobalWebSocketExist() should return true if global.WebSocket is truthy', () => { | ||
global.WebSocket = {}; | ||
try { | ||
expect(doesGlobalWebSocketExist()).to.be.true; | ||
} finally { | ||
global.WebSocket = undefined; | ||
} | ||
}); | ||
|
||
it('doesGlobalWebSocketExist() should return false if global.WebSocket is null or undefined', () => { | ||
expect(doesGlobalWebSocketExist()).to.be.false; | ||
|
||
global.WebSocket = null; | ||
try { | ||
expect(doesGlobalWebSocketExist()).to.be.false; | ||
} finally { | ||
global.WebSocket = undefined; | ||
} | ||
}); | ||
|
||
it('doesGlobalFileReaderExist() should return true if global.FileReader is truthy', () => { | ||
global.FileReader = {}; | ||
try { | ||
expect(doesGlobalFileReaderExist()).to.be.true; | ||
} finally { | ||
global.FileReader = undefined; | ||
} | ||
}); | ||
|
||
it('doesGlobalFileReaderExist() should return false if global.FileReader is null or undefined', () => { | ||
expect(doesGlobalFileReaderExist()).to.be.false; | ||
|
||
global.FileReader = null; | ||
try { | ||
expect(doesGlobalFileReaderExist()).to.be.false; | ||
} finally { | ||
global.FileReader = undefined; | ||
} | ||
}); | ||
}); |