http#get TypeScript Examples
The following examples show how to use
http#get.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: typeorm-uml.class.ts From typeorm-uml with MIT License | 6 votes |
/**
* Creates and returns Typeorm connection based on selected configuration file.
*
* @async
* @private
* @param {string} configPath A path to Typeorm config file.
* @param {Flags} flags An object with command flags.
* @returns {Connection} A connection instance.
*/
private async getConnection( configPath: string, flags: Flags ): Promise<Connection> {
let root = process.cwd();
let configName = configPath;
if ( isAbsolute( configName ) ) {
root = dirname( configName );
configName = basename( configName );
}
const cwd = dirname( resolve( root, configName ) );
process.chdir( cwd );
const connectionOptionsReader = new ConnectionOptionsReader( { root, configName } );
const connectionOptions = await connectionOptionsReader.get( flags.connection || 'default' );
return getConnectionManager().create( connectionOptions );
}
Example #2
Source File: typeorm-uml.class.ts From typeorm-uml with MIT License | 6 votes |
/**
* Downloads image into a file.
*
* @private
* @param {string} url The URL to download.
* @param {string} filename The output filename.
* @returns {Promise} A promise object.
*/
private download( url: string, filename: string ): Promise<void> {
return new Promise( ( resolve ) => {
get( url, ( response ) => {
response.pipe( createWriteStream( this.getPath( filename ) ) );
response.on( 'end', resolve );
} );
} );
}
Example #3
Source File: index.spec.ts From fastify-sse-v2 with MIT License | 4 votes |
describe("Test SSE plugin", function () {
let server: FastifyInstance;
let source: Pushable<EventMessage>;
beforeEach(async function () {
source = pushable<EventMessage>();
server = await getFastifyServer(source);
});
afterEach(async function () {
source.end();
if(server) {
await server.close();
}
});
it("should open event stream", function (done) {
const eventsource = getEventSource(server);
eventsource.addEventListener("open", function () {
expect(eventsource.readyState).to.equal(eventsource.OPEN);
eventsource.close();
done();
});
});
it("should set plugin headers", function (done) {
try {
get(getBaseUrl(server), {timeout: 100}, (res) => {
expect(res.headers["x-test-header2"]).to.be.deep.equal("test2");
res.destroy();
done();
});
} catch(e) {
done(e);
}
});
it("should set retry", function (done) {
const eventsource = getEventSource(server);
eventsource.addEventListener("open", function () {
source.end();
});
eventsource.addEventListener("error", function () {
// @ts-ignore
expect(eventsource.reconnectInterval).to.be.equal(3000);
eventsource.close();
done();
});
});
it("should end client", function (done) {
const eventsource = getEventSource(server);
eventsource.addEventListener("open", function () {
source.end();
});
eventsource.addEventListener("message", function () {
eventsource.close();
throw "shouldn't be called";
});
eventsource.addEventListener("end", function (e: Event) {
expect(e.type).to.be.equal("end");
// @ts-ignore
expect(e.data).to.be.equal("Stream closed");
eventsource.close();
done();
});
});
it("should send single event", function (done) {
const eventsource = getEventSource(server);
source.push({id: "1", event: "message", data: "Something"});
eventsource.onmessage = (evt => {
expect(evt.data).equal("Something");
expect(evt.type).equal("message");
expect(evt.lastEventId).equal("1");
eventsource.close();
done();
});
});
it("should send multiple events", function (done) {
const eventsource = getEventSource(server);
source.push({id: "1", event: "message", data: "Something"});
source.push({id: "2", event: "message", data: "Something"});
source.end();
const spy = sinon.spy();
eventsource.onmessage = (() => spy());
eventsource.onerror = (() => {
expect(spy.callCount).to.be.equal(2);
eventsource.close();
done();
});
});
});