This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
5,348 additions
and
9,155 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,74 @@ | ||
node_modules | ||
yarn-error.log | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage/ | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
dist | ||
# Typescript v1 declaration files | ||
typings | ||
|
||
__tests__/coverage | ||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# dotenv environment variable files | ||
.env* | ||
|
||
# Library | ||
dist/ | ||
typings/ | ||
|
||
# gatsby files | ||
.cache/ | ||
public/ | ||
|
||
# Mac files | ||
.DS_Store | ||
|
||
# Yarn | ||
yarn-error.log | ||
.pnp/ | ||
.pnp.js | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity |
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,3 +1,3 @@ | ||
{ | ||
"src/**/*.{js,ts,tsx}": ["eslint --ext js,ts,tsx --fix", "git add"] | ||
"lib/*.{js,ts,tsx}": ["eslint --ext js,ts,tsx --fix"] | ||
} |
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,4 +1,5 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
"trailingComma": "all", | ||
"arrowParens": "avoid" | ||
} |
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,7 +1,7 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- '10' | ||
- '12.18.0' | ||
|
||
cache: | ||
yarn: true | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react'; | ||
|
||
import { renderHook, act } from '@testing-library/react-hooks'; | ||
|
||
import { useMqttState, Connector } from '../lib'; | ||
import { URL, options } from './connection'; | ||
|
||
let wrapper; | ||
|
||
describe('Connector wrapper', () => { | ||
beforeAll(() => { | ||
wrapper = ({ children }) => ( | ||
<Connector brokerUrl={URL} options={options}> | ||
{children} | ||
</Connector> | ||
); | ||
}); | ||
|
||
it('should not connect with mqtt, wrong url', async () => { | ||
const { result, waitForValueToChange } = renderHook(() => useMqttState(), { | ||
wrapper: ({ children }) => ( | ||
<Connector | ||
brokerUrl="mqtt://test.mosqu.org:1884" | ||
options={{ connectTimeout: 2000 }} | ||
> | ||
{children} | ||
</Connector> | ||
), | ||
}); | ||
|
||
await waitForValueToChange(() => result.current.connectionStatus); | ||
|
||
expect(result.current.connectionStatus).toBe( | ||
'getaddrinfo ENOTFOUND test.mosqu.org', | ||
); | ||
|
||
await waitForValueToChange(() => result.current.connectionStatus); | ||
|
||
expect(result.current.connectionStatus).toBe('Offline'); | ||
}); | ||
|
||
it('should connect with mqtt', async () => { | ||
const { result, wait } = renderHook(() => useMqttState(), { | ||
wrapper, | ||
}); | ||
|
||
await wait(() => result.current.client?.connected === true); | ||
|
||
expect(result.current.connectionStatus).toBe('Connected'); | ||
|
||
await act(async () => { | ||
await result.current.client?.end(); | ||
}); | ||
}); | ||
|
||
it('should connect passing props', async () => { | ||
const { result, wait } = renderHook(() => useMqttState(), { | ||
wrapper: ({ children }) => ( | ||
<Connector brokerUrl={URL} options={{ keepalive: 0 }}> | ||
{children} | ||
</Connector> | ||
), | ||
}); | ||
|
||
await wait(() => result.current.client?.connected === true); | ||
|
||
expect(result.current.connectionStatus).toBe('Connected'); | ||
|
||
await act(async () => { | ||
await result.current.client?.end(); | ||
}); | ||
}); | ||
}); |
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,2 @@ | ||
export const URL = 'mqtt://127.0.0.1:1883'; | ||
export const options = {}; |
Oops, something went wrong.