Skip to content

Commit

Permalink
Updated prettier with configs and travis with coveralls
Browse files Browse the repository at this point in the history
Signed-off-by: Aaryanna Simonelli <[email protected]>
  • Loading branch information
bashleigh committed Jul 11, 2018
1 parent b5ab087 commit 801a6da
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 47 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ before_install:
install:
- yarn
script:
- yarn run test
- yarn run test
after_success: yarn run coveralls
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@nestjs/testing": "^5.1.0",
"@types/es6-promise": "^3.3.0",
"@types/node": "^10.5.1",
"coveralls": "^3.0.2",
"jest": "^23.4.0",
"prettier": "^1.13.7",
"ts-jest": "^23.0.0",
Expand All @@ -26,9 +27,12 @@
"rxjs": "^6.2.1"
},
"scripts": {
"format": "prettier --write \"**/*.ts\"",
"build": "rm -rf ./dist && tsc",
"coverage": "jest --coverage",
"coveralls": "yarn run coverage --coverageReporters=text-lcov | coveralls",
"test": "jest",
"prepublish": "rm -rf dist && tsc"
"format": "prettier **/**/*.ts --ignore-path ./.prettierignore --write && git status",
"prepublish": "npm run format && npm run build"
},
"repository": {
"type": "git",
Expand Down
42 changes: 21 additions & 21 deletions src/__tests__/amqp.module.spec.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
import { Test } from "@nestjs/testing";
import AmqpModule from "./../amqp.module";
import { ConfigModule } from "nestjs-config";
import { Test } from '@nestjs/testing';
import AmqpModule from './../amqp.module';
import { ConfigModule } from 'nestjs-config';

describe("Instance amqp module", () => {
it("Load module with an array of connection", async () => {
describe('Instance amqp module', () => {
it('Load module with an array of connection', async () => {
const module = await Test.createTestingModule({
imports: [
ConfigModule.load(),
AmqpModule.forRoot([
{
host: "amqp://localhost:5672"
host: 'amqp://localhost:5672',
},
{
host: "localhost",
host: 'localhost',
port: 5672,
name: "test"
}
])
]
name: 'test',
},
]),
],
}).compile();

const connection1 = module.get<any>("amqpConnection_0");
const connectionTest = module.get<any>("amqpConnection_test");
const connection1 = module.get<any>('amqpConnection_0');
const connectionTest = module.get<any>('amqpConnection_test');

expect(connection1).toBeTruthy();
expect(connectionTest).toBeTruthy();
});

it("Load module with singular connection", async () => {
it('Load module with singular connection', async () => {
const module = await Test.createTestingModule({
imports: [
ConfigModule.load(),
AmqpModule.forRoot({
host: "amqp://localhost:5672"
})
]
host: 'amqp://localhost:5672',
}),
],
}).compile();

const connection = module.get<any>("amqpConnection_default");
const connection = module.get<any>('amqpConnection_default');

expect(connection).toBeTruthy();
});

it("Load module using env", async () => {
it('Load module using env', async () => {
const module = await Test.createTestingModule({
imports: [ConfigModule.load(), AmqpModule.forRoot()]
imports: [ConfigModule.load(), AmqpModule.forRoot()],
}).compile();

const connection = module.get<any>("amqpConnection_default");
const connection = module.get<any>('amqpConnection_default');

expect(connection).toBeTruthy();
});
Expand Down
10 changes: 5 additions & 5 deletions src/amqp/createConnectionProvider.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { AmqpConnectionOptions } from "../interfaces";
import * as amqp from "amqplib";
import resolveAmqpUrl from "./resolveAmqlUrl";
import { AmqpConnectionOptions } from '../interfaces';
import * as amqp from 'amqplib';
import resolveAmqpUrl from './resolveAmqlUrl';

export default function createConnectionProvider(
name: number | string,
options?: AmqpConnectionOptions
options?: AmqpConnectionOptions,
) {
const url = resolveAmqpUrl(options);
return {
provide: `amqpConnection_${options.name ? options.name : name}`,
useFactory: async () => await amqp.connect(url)
useFactory: async () => await amqp.connect(url),
};
}
8 changes: 4 additions & 4 deletions src/amqp/defaultConnection.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as amqp from "amqplib";
import { ConfigService } from "nestjs-config";
import * as amqp from 'amqplib';
import { ConfigService } from 'nestjs-config';

const DefaultConnection = {
provide: "amqpConnection_default",
provide: 'amqpConnection_default',
useFactory: async (config: ConfigService) => {
//TODO add configservice here
return await amqp.connect();
},
inject: [ConfigService]
inject: [ConfigService],
};
export default DefaultConnection;
6 changes: 3 additions & 3 deletions src/amqp/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import createConnectionProvider from "./createConnectionProvider";
import DefaultConnection from "./defaultConnection";
import resolveAmqpUrl from "./resolveAmqlUrl";
import createConnectionProvider from './createConnectionProvider';
import DefaultConnection from './defaultConnection';
import resolveAmqpUrl from './resolveAmqlUrl';

export { createConnectionProvider, DefaultConnection, resolveAmqpUrl };
10 changes: 5 additions & 5 deletions src/amqp/resolveAmqlUrl.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { AmqpConnectionOptions } from "./../interfaces";
import { AmqpConnectionOptions } from './../interfaces';

export default function resolveAmqpUrl(options: AmqpConnectionOptions): string {
if (Object.keys(options).length === 1) return options.host;
let url =
(options.hasOwnProperty("ssl") && options.ssl ? "amqps" : "amqp") + "://";
(options.hasOwnProperty('ssl') && options.ssl ? 'amqps' : 'amqp') + '://';

if (options.hasOwnProperty("username")) url += options.username;
if (options.hasOwnProperty("password")) url += `:${options.password}@`;
if (options.hasOwnProperty('username')) url += options.username;
if (options.hasOwnProperty('password')) url += `:${options.password}@`;
url += options.host;
if (options.hasOwnProperty("port")) url += `:${options.port}`;
if (options.hasOwnProperty('port')) url += `:${options.port}`;
return url;
}
2 changes: 1 addition & 1 deletion src/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import InjectAmqpConnection from "./injectampqconnection.decorator";
import InjectAmqpConnection from './injectampqconnection.decorator';

export { InjectAmqpConnection };
4 changes: 2 additions & 2 deletions src/decorators/injectampqconnection.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Inject } from "@nestjs/common";
import { Inject } from '@nestjs/common';

const InjectAmqpConnection = (
connectionName: string = "amqpConnection_default"
connectionName: string = 'amqpConnection_default',
) => Inject(connectionName);

export default InjectAmqpConnection;
2 changes: 1 addition & 1 deletion src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import AmqpConnectionOptions from "./amqpconnection-options.interface";
import AmqpConnectionOptions from './amqpconnection-options.interface';

export { AmqpConnectionOptions };
27 changes: 25 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,17 @@ [email protected]:
object-assign "^4"
vary "^1"

coveralls@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/coveralls/-/coveralls-3.0.2.tgz#f5a0bcd90ca4e64e088b710fa8dda640aea4884f"
dependencies:
growl "~> 1.10.0"
js-yaml "^3.11.0"
lcov-parse "^0.0.10"
log-driver "^1.2.7"
minimist "^1.2.0"
request "^2.85.0"

cpx@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/cpx/-/cpx-1.5.0.tgz#185be018511d87270dedccc293171e37655ab88f"
Expand Down Expand Up @@ -1438,6 +1449,10 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"

"growl@~> 1.10.0":
version "1.10.5"
resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e"

growly@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
Expand Down Expand Up @@ -2187,7 +2202,7 @@ js-tokens@^3.0.0, js-tokens@^3.0.2:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"

js-yaml@^3.7.0:
js-yaml@^3.11.0, js-yaml@^3.7.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1"
dependencies:
Expand Down Expand Up @@ -2298,6 +2313,10 @@ lcid@^1.0.0:
dependencies:
invert-kv "^1.0.0"

lcov-parse@^0.0.10:
version "0.0.10"
resolved "https://registry.yarnpkg.com/lcov-parse/-/lcov-parse-0.0.10.tgz#1b0b8ff9ac9c7889250582b70b71315d9da6d9a3"

left-pad@^1.2.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e"
Expand Down Expand Up @@ -2353,6 +2372,10 @@ lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.4:
version "4.17.10"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"

log-driver@^1.2.7:
version "1.2.7"
resolved "https://registry.yarnpkg.com/log-driver/-/log-driver-1.2.7.tgz#63b95021f0702fedfa2c9bb0a24e7797d71871d8"

longest@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
Expand Down Expand Up @@ -3133,7 +3156,7 @@ request-promise-native@^1.0.5:
stealthy-require "^1.1.0"
tough-cookie ">=2.3.3"

request@^2.83.0:
request@^2.83.0, request@^2.85.0:
version "2.87.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.87.0.tgz#32f00235cd08d482b4d0d68db93a829c0ed5756e"
dependencies:
Expand Down

0 comments on commit 801a6da

Please sign in to comment.