From a9e3fd15ad64be71a3d738e31b1d0999670de366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 4 Jun 2019 12:37:02 +0200 Subject: [PATCH] chore: import eslint rules from eslint-config-loopback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fix violations of these new rules (mostly mocha/no-identical-title) Signed-off-by: Miroslav Bajtoš --- .../test/integration/lib/project-generator.js | 4 +-- packages/cli/test/unit/utils.unit.js | 4 +-- .../class-level-bindings.acceptance.ts | 2 +- .../src/__tests__/unit/binding-sorter.unit.ts | 2 +- .../src/__tests__/unit/application.unit.ts | 2 +- packages/eslint-config/eslintrc.js | 9 ++++++ .../src/__tests__/unit/rest.component.unit.ts | 30 ++++++++++++------- 7 files changed, 36 insertions(+), 17 deletions(-) diff --git a/packages/cli/test/integration/lib/project-generator.js b/packages/cli/test/integration/lib/project-generator.js index 8a4ecae55136..6387806c32ec 100644 --- a/packages/cli/test/integration/lib/project-generator.js +++ b/packages/cli/test/integration/lib/project-generator.js @@ -36,7 +36,7 @@ module.exports = function(projGenerator, props, projectType) { describe('_setupGenerator', () => { describe('args validation', () => { - it('errors out if validation fails', () => { + it('errors out if validation fails for an argument value', () => { const result = testUtils .executeGenerator(projGenerator) .withArguments(['fooBar']); @@ -45,7 +45,7 @@ module.exports = function(projGenerator, props, projectType) { ); }); - it('errors out if validation fails', () => { + it('errors out if validation fails for an option value', () => { const result = testUtils .executeGenerator(projGenerator) .withOptions({name: 'fooBar'}) diff --git a/packages/cli/test/unit/utils.unit.js b/packages/cli/test/unit/utils.unit.js index 21abbda992c8..521af81f67e9 100644 --- a/packages/cli/test/unit/utils.unit.js +++ b/packages/cli/test/unit/utils.unit.js @@ -364,7 +364,7 @@ describe('Utils', () => { ); }); - it('returns string for an array check with a number', () => { + it('returns string for an array check with an object', () => { expect(utils.validateStringObject('array')({})).to.be.eql( 'The value must be a stringified array', ); @@ -374,7 +374,7 @@ describe('Utils', () => { expect(utils.validateStringObject('object')('{}')).to.be.True(); }); - it('returns string for an array check with an object', () => { + it('returns string for an array check with an object-like string', () => { expect(utils.validateStringObject('array')('{}')).to.be.eql( 'The value must be a stringified array', ); diff --git a/packages/context/src/__tests__/acceptance/class-level-bindings.acceptance.ts b/packages/context/src/__tests__/acceptance/class-level-bindings.acceptance.ts index 305ffc6c2903..be4f66db7acb 100644 --- a/packages/context/src/__tests__/acceptance/class-level-bindings.acceptance.ts +++ b/packages/context/src/__tests__/acceptance/class-level-bindings.acceptance.ts @@ -637,7 +637,7 @@ describe('Context bindings - Injecting dependencies of classes', () => { expect(store.locations).to.eql(['San Francisco', 'San Jose']); }); - it('injects values by tag asynchronously', async () => { + it('reports correct resolution path when injecting values by tag', async () => { class Store { constructor(@inject.tag('store:location') public locations: string[]) {} } diff --git a/packages/context/src/__tests__/unit/binding-sorter.unit.ts b/packages/context/src/__tests__/unit/binding-sorter.unit.ts index 856e237309a7..e8e4693f1588 100644 --- a/packages/context/src/__tests__/unit/binding-sorter.unit.ts +++ b/packages/context/src/__tests__/unit/binding-sorter.unit.ts @@ -53,7 +53,7 @@ describe('BindingComparator', () => { assertOrder('validator1', 'validator2', 'metrics', 'logger1'); }); - it('sorts by binding order without phase tags', () => { + it('sorts by binding order without phase tags (for symbol tags)', () => { /** * Phases * - '': validator1 // not part of ['log', 'auth'] diff --git a/packages/core/src/__tests__/unit/application.unit.ts b/packages/core/src/__tests__/unit/application.unit.ts index 61d993999f0d..eefa920f30dd 100644 --- a/packages/core/src/__tests__/unit/application.unit.ts +++ b/packages/core/src/__tests__/unit/application.unit.ts @@ -152,7 +152,7 @@ describe('Application', () => { expect(binding.tagNames).to.containEql('foo'); }); - it('binds providers from a component', () => { + it('honors tags when binding providers from a component', () => { @bind({tags: ['foo']}) class MyProvider implements Provider { value() { diff --git a/packages/eslint-config/eslintrc.js b/packages/eslint-config/eslintrc.js index d32f8a414fa6..4debac0c64f8 100644 --- a/packages/eslint-config/eslintrc.js +++ b/packages/eslint-config/eslintrc.js @@ -56,6 +56,15 @@ module.exports = { // TypeScript allows the same name for namespace and function 'no-redeclare': 'off', + /** + * Rules imported from eslint-config-loopback + */ + 'mocha/handle-done-callback': 'error', + 'mocha/no-exclusive-tests': 'error', + 'mocha/no-identical-title': 'error', + 'mocha/no-nested-tests': 'error', + 'no-array-constructor': 'error', + /** * TypeScript specific rules * See https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules diff --git a/packages/rest/src/__tests__/unit/rest.component.unit.ts b/packages/rest/src/__tests__/unit/rest.component.unit.ts index 835a3e28298d..42af53957ee8 100644 --- a/packages/rest/src/__tests__/unit/rest.component.unit.ts +++ b/packages/rest/src/__tests__/unit/rest.component.unit.ts @@ -25,10 +25,21 @@ import {aRestServerConfig} from '../helpers'; const SequenceActions = RestBindings.SequenceActions; describe('RestComponent', () => { describe('Providers', () => { - describe('Default implementations are bound', () => { + describe('Default implementation', () => { let app: Application; let comp: Component; + const EXPECTED_KEYS = [ + RestBindings.SequenceActions.LOG_ERROR.key, + RestBindings.SequenceActions.FIND_ROUTE.key, + RestBindings.SequenceActions.INVOKE_METHOD.key, + RestBindings.SequenceActions.REJECT.key, + RestBindings.BIND_ELEMENT.key, + RestBindings.GET_FROM_CONTEXT.key, + RestBindings.SequenceActions.PARSE_PARAMS.key, + RestBindings.SequenceActions.SEND.key, + ]; + before(async () => { app = new Application(); app.component(RestComponent); @@ -42,16 +53,15 @@ describe('RestComponent', () => { comp = await app.get('components.RestComponent'); }); - it('', async () => { - for (const key in comp.providers || {}) { - it(key, async () => { - const result = await app.get(key); - const expected: Provider = new comp.providers![key](); - expect(result).to.deepEqual(expected.value()); - }); - } - }); + for (const key of EXPECTED_KEYS) { + it(`binds ${key}`, async () => { + const result = await app.get(key); + const expected: Provider = new comp.providers![key](); + expect(result).to.deepEqual(expected.value()); + }); + } }); + describe('LOG_ERROR', () => { it('matches expected argument signature', async () => { const app = new Application();