From 272655e30dd7f80b65872de270610e4844a6d0be Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 3 Jul 2017 22:47:31 -0400 Subject: [PATCH 1/3] Add ember-testing lib helpers. --- .../ember-testing-helpers-tests.ts | 79 +++++++++++++++++++ types/ember-testing-helpers/index.d.ts | 63 +++++++++++++++ types/ember-testing-helpers/tsconfig.json | 21 +++++ 3 files changed, 163 insertions(+) create mode 100644 types/ember-testing-helpers/ember-testing-helpers-tests.ts create mode 100644 types/ember-testing-helpers/index.d.ts create mode 100644 types/ember-testing-helpers/tsconfig.json diff --git a/types/ember-testing-helpers/ember-testing-helpers-tests.ts b/types/ember-testing-helpers/ember-testing-helpers-tests.ts new file mode 100644 index 0000000000..9088097b25 --- /dev/null +++ b/types/ember-testing-helpers/ember-testing-helpers-tests.ts @@ -0,0 +1,79 @@ +function testAndThen() { + const result: RSVP.Promise = andThen(() => "some string"); + result.then(s => s.length); +} + +function testClick() { + const result: RSVP.Promise = click('someString'); + result.then(() => {}); +} + +function testCurrentPath() { + const path = currentPath(); + const chars = path.split(''); +} + +function testCurrentRouteName() { + const routeName = currentRouteName(); + const isIndex = routeName === 'index'; +} + +function testCurrentURL() { + const url = currentURL(); + const isIndex = url.match(/^\/$/); +} + +function testFillIn() { + const textResult = fillIn('.foo', 'waffles'); + textResult.then(() => true); + const contextResult = fillIn('.bar', { }, 'pancakes'); + contextResult.catch(reason => false); +} + +function testFind() { + const found = find('#quux'); + found.addClass('has-ducks'); + + const foundInAContext = find('#baz', {}); + foundInAContext.removeClass('can-cluck'); +} + +function testFindWithAssert() { + const found = findWithAssert('#quux'); + found.addClass('has-ducks'); + + const foundInAContext = findWithAssert('#baz', {}); + foundInAContext.removeClass('can-cluck'); +} + +function testKeyEvent() { + keyEvent('.some-button', 'keydown', 11).then(() => 11); + keyEvent('.some-button', 'keypress', 101).then(() => 101); + keyEvent('.some-button', 'keyup', 1001).then(() => 1001); +} + +function testPauseTest() { + pauseTest().finally(() => { + const foo = 'fighters'; + }) +} + +function testResumeTest() { + resumeTest(); +} + +function testTriggerEvent() { + triggerEvent('.something', {}, 'click', {}).then(() => 'yay'); + triggerEvent('.something', 'mousedown').then(() => 'no'); + triggerEvent('.something', {}, 'fetch').then(() => 'huzzah'); + triggerEvent('.something', 'keydown').then(() => 'whomp whomp'); +} + +function testVisit() { + visit('some/url').then(() => {}) +} + +function testWait() { + const waited = wait('whatever'); + waited.then((s: string) => s.length); +} diff --git a/types/ember-testing-helpers/index.d.ts b/types/ember-testing-helpers/index.d.ts new file mode 100644 index 0000000000..c61eff40e8 --- /dev/null +++ b/types/ember-testing-helpers/index.d.ts @@ -0,0 +1,63 @@ +// Type definitions for ember-testing/lib/helpers +// Project: Ember.js Testing Helpers: https://github.com/emberjs/ember.js/tree/master/packages/ember-testing/lib/helpers +// Definitions by: Chris Krycho +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript version: 2.3 +// +// Note that these are distributed separately because they represent a discrete +// set of functionality, and as globally-injected items (as of Ember 2.13), are +// not easily or straightforwardly exported from the Ember type definitions. + +/// +/// + +type KeyEventType = 'keydown' | 'keyup' | 'keypress'; +type VoidWaitResult = RSVP.Promise; + +declare global { + // https://github.com/emberjs/ember.js/blob/master/packages/ember-testing/lib/helpers/and_then.js + function andThen(callback: (...args: any[]) => T): RSVP.Promise; + + // https://github.com/emberjs/ember.js/blob/master/packages/ember-testing/lib/helpers/click.js + function click(selector: string, context?: Object): VoidWaitResult; + + // https://github.com/emberjs/ember.js/blob/master/packages/ember-testing/lib/helpers/current_path.js + function currentPath(): string; + + // https://github.com/emberjs/ember.js/blob/master/packages/ember-testing/lib/helpers/current_route_name.js + function currentRouteName(): string; + + // https://github.com/emberjs/ember.js/blob/master/packages/ember-testing/lib/helpers/current_url.js + function currentURL(): string; + + // https://github.com/emberjs/ember.js/blob/master/packages/ember-testing/lib/helpers/fill_in.js + function fillIn(selector: string, context: Object, text: string): VoidWaitResult; + function fillIn(selector: string, text: string): VoidWaitResult; + + // https://github.com/emberjs/ember.js/blob/master/packages/ember-testing/lib/helpers/find.js + function find(selector: string, context?: Object): JQuery; + + // https://github.com/emberjs/ember.js/blob/master/packages/ember-testing/lib/helpers/find_with_assert.js + function findWithAssert(selector: string, context?: Object): JQuery; + + // https://github.com/emberjs/ember.js/blob/master/packages/ember-testing/lib/helpers/key_event.js + function keyEvent(selector: string, type: KeyEventType, keyCode: number): VoidWaitResult; + + // https://github.com/emberjs/ember.js/blob/master/packages/ember-testing/lib/helpers/pause_test.js + function pauseTest(): RSVP.Promise<{}>; + function resumeTest(): void; + + // https://github.com/emberjs/ember.js/blob/master/packages/ember-testing/lib/helpers/trigger_event.js + function triggerEvent(selector: string, context: Object, type: string, options: Object): VoidWaitResult; + function triggerEvent(selector: string, context: Object, type: string): VoidWaitResult; + function triggerEvent(selector: string, type: string, options: Object): VoidWaitResult; + function triggerEvent(selector: string, type: string): VoidWaitResult; + + // https://github.com/emberjs/ember.js/blob/master/packages/ember-testing/lib/helpers/visit.js + function visit(route: string): VoidWaitResult; + + // https://github.com/emberjs/ember.js/blob/master/packages/ember-testing/lib/helpers/wait.js + function wait(value: T): RSVP.Promise; +} + +export {}; diff --git a/types/ember-testing-helpers/tsconfig.json b/types/ember-testing-helpers/tsconfig.json new file mode 100644 index 0000000000..e4aa9692bf --- /dev/null +++ b/types/ember-testing-helpers/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "strict": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ember-testing-helpers-tests.ts" + ] +} From 5c9a773db9d88c9adcec8dd577425807bb7b9ea8 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 4 Jul 2017 08:13:26 -0400 Subject: [PATCH 2/3] Fix ember-testing-helpers tsconfig for CI. --- types/ember-testing-helpers/tsconfig.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/ember-testing-helpers/tsconfig.json b/types/ember-testing-helpers/tsconfig.json index e4aa9692bf..aaf474ecba 100644 --- a/types/ember-testing-helpers/tsconfig.json +++ b/types/ember-testing-helpers/tsconfig.json @@ -5,7 +5,9 @@ "es6", "dom" ], - "strict": true, + "noImplicitAny": true, + "noImplicitThis": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" From 61cf95a398e49b3b2f71cc85bf344521bd645159 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 14 Jul 2017 07:32:05 -0600 Subject: [PATCH 3/3] Add TS version header for ember-testing-helpers. --- types/ember-testing-helpers/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/ember-testing-helpers/index.d.ts b/types/ember-testing-helpers/index.d.ts index c61eff40e8..3fd1d4e23f 100644 --- a/types/ember-testing-helpers/index.d.ts +++ b/types/ember-testing-helpers/index.d.ts @@ -2,8 +2,8 @@ // Project: Ember.js Testing Helpers: https://github.com/emberjs/ember.js/tree/master/packages/ember-testing/lib/helpers // Definitions by: Chris Krycho // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript version: 2.3 -// +// TypeScript Version: 2.3 + // Note that these are distributed separately because they represent a discrete // set of functionality, and as globally-injected items (as of Ember 2.13), are // not easily or straightforwardly exported from the Ember type definitions.