-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: private to public, 1.1.2 version
- Loading branch information
Showing
16 changed files
with
17,188 additions
and
17,188 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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
insert_final_newline = false | ||
trim_trailing_whitespace = false | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
insert_final_newline = false | ||
trim_trailing_whitespace = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Copyright 2019 Artur Kurowski <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
Copyright 2019 Artur Kurowski <[email protected]> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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 @@ | ||
export const testConfig = { | ||
port: 7000, | ||
}; | ||
export const testConfig = { | ||
port: 7000, | ||
}; |
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,35 +1,35 @@ | ||
import { Server } from 'ws'; | ||
import { WebSocketGateway, WebSocketServer, OnGatewayInit } from '@nestjs/websockets'; | ||
|
||
import { testConfig } from './config'; | ||
|
||
@WebSocketGateway(testConfig.port) | ||
export class EventsGateway implements OnGatewayInit { | ||
|
||
afterInit(server: Server) { | ||
server.on('connection', (ws) => { | ||
ws.on('message', (data: any) => { | ||
try { | ||
data = JSON.parse(data); | ||
} catch (e) { | ||
ws.send(JSON.stringify({ | ||
id: -1, | ||
jsonrpc: '2.0', | ||
error: { | ||
code: -1, | ||
message: e.message, | ||
}, | ||
})); | ||
return; | ||
} | ||
|
||
ws.send(JSON.stringify({ | ||
id: data.id, | ||
jsonrpc: '2.0', | ||
result: data, | ||
})); | ||
}); | ||
}); | ||
} | ||
|
||
} | ||
import { Server } from 'ws'; | ||
import { WebSocketGateway, WebSocketServer, OnGatewayInit } from '@nestjs/websockets'; | ||
|
||
import { testConfig } from './config'; | ||
|
||
@WebSocketGateway(testConfig.port) | ||
export class EventsGateway implements OnGatewayInit { | ||
|
||
afterInit(server: Server) { | ||
server.on('connection', (ws) => { | ||
ws.on('message', (data: any) => { | ||
try { | ||
data = JSON.parse(data); | ||
} catch (e) { | ||
ws.send(JSON.stringify({ | ||
id: -1, | ||
jsonrpc: '2.0', | ||
error: { | ||
code: -1, | ||
message: e.message, | ||
}, | ||
})); | ||
return; | ||
} | ||
|
||
ws.send(JSON.stringify({ | ||
id: data.id, | ||
jsonrpc: '2.0', | ||
result: data, | ||
})); | ||
}); | ||
}); | ||
} | ||
|
||
} |
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 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { EventsGateway } from './events.gateway'; | ||
|
||
@Module({ | ||
providers: [EventsGateway], | ||
}) | ||
import { Module } from '@nestjs/common'; | ||
import { EventsGateway } from './events.gateway'; | ||
|
||
@Module({ | ||
providers: [EventsGateway], | ||
}) | ||
export class EventsModule { } |
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,24 +1,24 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
import { WsAdapter } from '@nestjs/platform-ws'; | ||
|
||
import { EventsModule } from './events.module'; | ||
|
||
let app: INestApplication; | ||
const bootstrap = async () => { | ||
|
||
const mod = await Test.createTestingModule({ | ||
imports: [EventsModule], | ||
}).compile(); | ||
|
||
app = mod.createNestApplication(); | ||
app.useWebSocketAdapter(new WsAdapter()); | ||
await app.listen(7000); | ||
|
||
}; | ||
|
||
bootstrap().then(() => { | ||
// | ||
}).catch(() => { | ||
// | ||
}); | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
import { WsAdapter } from '@nestjs/platform-ws'; | ||
|
||
import { EventsModule } from './events.module'; | ||
|
||
let app: INestApplication; | ||
const bootstrap = async () => { | ||
|
||
const mod = await Test.createTestingModule({ | ||
imports: [EventsModule], | ||
}).compile(); | ||
|
||
app = mod.createNestApplication(); | ||
app.useWebSocketAdapter(new WsAdapter()); | ||
await app.listen(7000); | ||
|
||
}; | ||
|
||
bootstrap().then(() => { | ||
// | ||
}).catch(() => { | ||
// | ||
}); |
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,43 +1,43 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
import { WsAdapter } from '@nestjs/platform-ws'; | ||
|
||
import { RpcWebSocketClient, IRpcResponse } from '../src/rpc-websocket-client'; | ||
|
||
import { EventsModule } from '../__tests-utils__/events.module'; | ||
import { testConfig } from '../__tests-utils__/config'; | ||
|
||
describe('WebSocket', () => { | ||
let app: INestApplication; | ||
|
||
beforeAll(async () => { | ||
const mod = await Test.createTestingModule({ | ||
imports: [EventsModule], | ||
}).compile(); | ||
|
||
app = mod.createNestApplication(); | ||
app.useWebSocketAdapter(new WsAdapter()); | ||
await app.listen(testConfig.port); | ||
}); | ||
|
||
it(`RpcWebSocketClient`, async () => { | ||
const ws = new RpcWebSocketClient(); | ||
|
||
await ws.connect(`ws://127.0.0.1:${testConfig.port}`); | ||
|
||
const method = `test`; | ||
const params = [method]; | ||
const res: any = await ws.call(method, params); | ||
|
||
expect(res).toMatchObject({ | ||
id: res.id, | ||
method, | ||
params, | ||
jsonrpc: '2.0', | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
}); | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
import { WsAdapter } from '@nestjs/platform-ws'; | ||
|
||
import { RpcWebSocketClient, IRpcResponse } from '../src/rpc-websocket-client'; | ||
|
||
import { EventsModule } from '../__tests-utils__/events.module'; | ||
import { testConfig } from '../__tests-utils__/config'; | ||
|
||
describe('WebSocket', () => { | ||
let app: INestApplication; | ||
|
||
beforeAll(async () => { | ||
const mod = await Test.createTestingModule({ | ||
imports: [EventsModule], | ||
}).compile(); | ||
|
||
app = mod.createNestApplication(); | ||
app.useWebSocketAdapter(new WsAdapter()); | ||
await app.listen(testConfig.port); | ||
}); | ||
|
||
it(`RpcWebSocketClient`, async () => { | ||
const ws = new RpcWebSocketClient(); | ||
|
||
await ws.connect(`ws://127.0.0.1:${testConfig.port}`); | ||
|
||
const method = `test`; | ||
const params = [method]; | ||
const res: any = await ws.call(method, params); | ||
|
||
expect(res).toMatchObject({ | ||
id: res.id, | ||
method, | ||
params, | ||
jsonrpc: '2.0', | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
}); |
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,9 +1,9 @@ | ||
module.exports = { | ||
transform: { | ||
"^.+\\.tsx?$": "ts-jest", | ||
}, | ||
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", | ||
testPathIgnorePatterns: ["/node_modules/"], | ||
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], | ||
setupFiles: ["./jest.setup.js"], | ||
}; | ||
module.exports = { | ||
transform: { | ||
"^.+\\.tsx?$": "ts-jest", | ||
}, | ||
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", | ||
testPathIgnorePatterns: ["/node_modules/"], | ||
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], | ||
setupFiles: ["./jest.setup.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 +1 @@ | ||
jest.setTimeout(30000); | ||
jest.setTimeout(30000); |
Oops, something went wrong.