-
Notifications
You must be signed in to change notification settings - Fork 13
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
1 parent
d677e0b
commit e0ffac0
Showing
8 changed files
with
190 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
version: 2 | ||
|
||
aliases: | ||
# ------------------------- | ||
# ALIASES: Caches | ||
# ------------------------- | ||
- &restore-deps-cache | ||
key: deps-cache-{{ checksum "package-lock.json" }} | ||
|
||
- &save-deps-cache | ||
key: deps-cache-{{ checksum "package-lock.json" }} | ||
paths: | ||
- ~/client-js/node_modules | ||
|
||
# ------------------------- | ||
# ALIASES: Branch Filters | ||
# ------------------------- | ||
- &filter-only-master | ||
branches: | ||
only: master | ||
- &filter-only-semantic-pr | ||
branches: | ||
only: /^(pull|dependabot|fix|feat)\/.*$/ | ||
|
||
defaults: &defaults | ||
working_directory: ~/client-js | ||
|
||
jobs: | ||
test: | ||
<<: *defaults | ||
docker: | ||
- image: circleci/node:10 | ||
steps: | ||
- checkout | ||
- restore_cache: *restore-deps-cache | ||
- run: npm install | ||
- run: npm install codecov | ||
- run: npm test | ||
- run: ./node_modules/.bin/codecov | ||
- save_cache: *save-deps-cache | ||
|
||
build: | ||
<<: *defaults | ||
docker: | ||
- image: circleci/node:10 | ||
steps: | ||
- checkout | ||
- restore_cache: *restore-deps-cache | ||
- run: npm install | ||
- run: npm run build | ||
- save_cache: *save-deps-cache | ||
|
||
release: | ||
<<: *defaults | ||
docker: | ||
- image: circleci/node:10 | ||
steps: | ||
- checkout | ||
- restore_cache: *restore-deps-cache | ||
- run: npm install | ||
- run: npm run build | ||
- run: npx semantic-release | ||
- save_cache: *save-deps-cache | ||
|
||
workflows: | ||
version: 2 | ||
analysis: | ||
jobs: | ||
- test: | ||
filters: *filter-only-semantic-pr | ||
- build: | ||
filters: *filter-only-semantic-pr | ||
|
||
release: | ||
jobs: | ||
- test: | ||
filters: *filter-only-master | ||
- build: | ||
filters: *filter-only-master | ||
- hold: | ||
filters: *filter-only-master | ||
type: approval | ||
requires: | ||
- test | ||
- build | ||
- release: | ||
filters: *filter-only-master | ||
requires: | ||
- hold |
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
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,10 @@ | ||
const Fetch = (url: string, options: any): Promise<any> => { | ||
const resultPromise = { | ||
text: () => { | ||
return Promise.resolve(options.body); | ||
}, | ||
}; | ||
return Promise.resolve(resultPromise); | ||
}; | ||
|
||
export default Fetch; |
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,28 @@ | ||
class WebSocket { | ||
private callbacks: any; | ||
constructor(uri: string, props: any) { | ||
this.callbacks = {}; | ||
} | ||
public addEventListener(eventName: string, callback: any) { | ||
this.callbacks[eventName] = callback; | ||
if (eventName === "open") { | ||
setTimeout(() => { | ||
callback(); | ||
}, 10); | ||
} | ||
} | ||
public removeEventListener(eventName: string, callback: any) { | ||
delete this.callbacks[eventName]; | ||
} | ||
public send(data: any) { | ||
Object.entries(this.callbacks).forEach(([eventName, callback]: [string, any]) => { | ||
if (eventName === "message") { | ||
callback({data}); | ||
} | ||
}); | ||
} | ||
public close() { | ||
this.callbacks = {}; | ||
} | ||
} | ||
export default WebSocket; |
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,21 @@ | ||
import HTTPTransport from "./HTTPTransport"; | ||
|
||
describe("HTTPTransport", () => { | ||
it("can connect", () => { | ||
const wst = new HTTPTransport("http://localhost:8545"); | ||
return wst.connect(); | ||
}); | ||
it("can close", () => { | ||
const wst = new HTTPTransport("http://localhost:8545"); | ||
wst.close(); | ||
}); | ||
it("can send and receive data", (done) => { | ||
const wst = new HTTPTransport("http://localhost:8545"); | ||
wst.onData((data: any) => { | ||
const d = JSON.parse(data); | ||
expect(d.foo).toEqual("bar"); | ||
done(); | ||
}); | ||
wst.sendData(JSON.stringify({foo: "bar"})); | ||
}); | ||
}); |
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,21 @@ | ||
import WebSocketTransport from "./WebSocketTransport"; | ||
|
||
describe("WebSocketTransport", () => { | ||
it("can connect", () => { | ||
const wst = new WebSocketTransport("http://localhost:8545"); | ||
return wst.connect(); | ||
}); | ||
it("can close", () => { | ||
const wst = new WebSocketTransport("http://localhost:8545"); | ||
wst.close(); | ||
}); | ||
it("can send and receive data", (done) => { | ||
const wst = new WebSocketTransport("http://localhost:8545"); | ||
wst.onData((data: any) => { | ||
const d = JSON.parse(data); | ||
expect(d.foo).toEqual("bar"); | ||
done(); | ||
}); | ||
wst.sendData(JSON.stringify({foo: "bar"})); | ||
}); | ||
}); |
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