From ea4008d4e80f5dea2418174e260ec87648295cf0 Mon Sep 17 00:00:00 2001 From: Glen M Date: Mon, 9 Oct 2017 18:43:18 -0400 Subject: [PATCH] Add definitions for atom-mocha-test-runner. (#20380) * Add definitions for atom-mocha-test-runner. * Remove the editorconfig. * Atom: remove editorconfigs, linebreak-style, and all lint disables. --- types/atom-keymap/.editorconfig | 3 - types/atom-keymap/tsconfig.json | 2 +- types/atom-keymap/tslint.json | 1 - .../atom-mocha-test-runner-tests.ts | 38 ++++++++ types/atom-mocha-test-runner/index.d.ts | 39 +++++++++ types/atom-mocha-test-runner/tsconfig.json | 25 ++++++ types/atom-mocha-test-runner/tslint.json | 37 ++++++++ types/atom/.editorconfig | 3 - types/atom/atom-tests.ts | 17 +++- types/atom/index.d.ts | 87 +++++++++++++++---- types/atom/tslint.json | 3 +- types/event-kit/.editorconfig | 3 - types/event-kit/event-kit-tests.ts | 2 +- types/event-kit/index.d.ts | 4 + types/event-kit/tslint.json | 3 +- types/first-mate/.editorconfig | 3 - types/first-mate/index.d.ts | 6 +- types/first-mate/tslint.json | 4 +- types/pathwatcher/.editorconfig | 3 - types/pathwatcher/tslint.json | 1 - types/text-buffer/.editorconfig | 3 - types/text-buffer/tslint.json | 1 - 22 files changed, 236 insertions(+), 52 deletions(-) delete mode 100644 types/atom-keymap/.editorconfig create mode 100644 types/atom-mocha-test-runner/atom-mocha-test-runner-tests.ts create mode 100644 types/atom-mocha-test-runner/index.d.ts create mode 100644 types/atom-mocha-test-runner/tsconfig.json create mode 100644 types/atom-mocha-test-runner/tslint.json delete mode 100644 types/atom/.editorconfig delete mode 100644 types/event-kit/.editorconfig delete mode 100644 types/first-mate/.editorconfig delete mode 100644 types/pathwatcher/.editorconfig delete mode 100644 types/text-buffer/.editorconfig diff --git a/types/atom-keymap/.editorconfig b/types/atom-keymap/.editorconfig deleted file mode 100644 index 2b997514d2..0000000000 --- a/types/atom-keymap/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*.ts] -indent_style = tab -indent_size = 2 diff --git a/types/atom-keymap/tsconfig.json b/types/atom-keymap/tsconfig.json index 1ef87fb730..f501df325f 100644 --- a/types/atom-keymap/tsconfig.json +++ b/types/atom-keymap/tsconfig.json @@ -21,4 +21,4 @@ "index.d.ts", "atom-keymap-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/atom-keymap/tslint.json b/types/atom-keymap/tslint.json index cd8f17056a..4b036f727a 100644 --- a/types/atom-keymap/tslint.json +++ b/types/atom-keymap/tslint.json @@ -5,7 +5,6 @@ "class-name": true, "indent": [true, "tabs"], "jsdoc-format": true, - "linebreak-style": [true, "LF"], "max-line-length": [true, 100], "quotemark": [true, "double", "avoid-escape"], "trailing-comma": [true, { diff --git a/types/atom-mocha-test-runner/atom-mocha-test-runner-tests.ts b/types/atom-mocha-test-runner/atom-mocha-test-runner-tests.ts new file mode 100644 index 0000000000..434e48f261 --- /dev/null +++ b/types/atom-mocha-test-runner/atom-mocha-test-runner-tests.ts @@ -0,0 +1,38 @@ +import { createRunner } from "atom-mocha-test-runner"; +import defaultMochaRunner = require("atom-mocha-test-runner"); + +const extraOptions = { + testSuffixes: ["-spec.js", "-spec.coffee"], +}; + +function mochaSetup(mocha: Mocha) { + mocha.addFile("test.file"); +} + +let testRunner = createRunner(); +testRunner = createRunner(extraOptions); +testRunner = createRunner(extraOptions, mochaSetup); +testRunner = createRunner({ + colors: true, + globalAtom: true, + htmlTitle: "Test Title", + reporter: "dot", + testSuffixes: ["test.file"], +}); + +declare const atom: Atom.AtomEnvironment; +declare const blob: object; +declare let num: number; + +async function runTests(): Promise { + const runnerArgs: Atom.Structures.TestRunnerArgs = { + testPaths: ["/var/test"], + logFile: "/var/log", + headless: false, + buildDefaultApplicationDelegate: () => blob, + buildAtomEnvironment: () => atom, + }; + + num = await defaultMochaRunner(runnerArgs); + return await testRunner(runnerArgs); +} diff --git a/types/atom-mocha-test-runner/index.d.ts b/types/atom-mocha-test-runner/index.d.ts new file mode 100644 index 0000000000..432d91c71a --- /dev/null +++ b/types/atom-mocha-test-runner/index.d.ts @@ -0,0 +1,39 @@ +// Type definitions for atom-mocha-test-runner 1.0 +// Project: https://github.com/BinaryMuse/atom-mocha-test-runner +// Definitions by: GlenCFL +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +/// +/// + +interface AtomMochaOptions { + /** Which reporter to use on the terminal. */ + reporter?: string; + + /** Whether or not to assign the created Atom environment to `global.atom`. */ + globalAtom?: boolean; + + /** File extensions that indicate that the file contains tests. */ + testSuffixes?: string[]; + + /** Whether or not to colorize output on the terminal. */ + colors?: boolean; + + /** The string to use for the window title in the HTML reporter. */ + htmlTitle?: string; +} + +// The test runner function is augmented on export by: +// import createRunner from './lib/create-runner' +// +// module.exports = createRunner() +// module.exports.createRunner = createRunner +// Which is what we're trying to model here. +interface TestRunnerExport extends AtomCore.TestRunner { + createRunner(options?: AtomMochaOptions, mochaConfigFunction?: + (mocha: Mocha) => void): AtomCore.TestRunner; +} + +declare const runner: TestRunnerExport; +export = runner; diff --git a/types/atom-mocha-test-runner/tsconfig.json b/types/atom-mocha-test-runner/tsconfig.json new file mode 100644 index 0000000000..22df333ccd --- /dev/null +++ b/types/atom-mocha-test-runner/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "atom-mocha-test-runner-tests.ts" + ] +} diff --git a/types/atom-mocha-test-runner/tslint.json b/types/atom-mocha-test-runner/tslint.json new file mode 100644 index 0000000000..4b036f727a --- /dev/null +++ b/types/atom-mocha-test-runner/tslint.json @@ -0,0 +1,37 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + // Custom rules. + "class-name": true, + "indent": [true, "tabs"], + "jsdoc-format": true, + "max-line-length": [true, 100], + "quotemark": [true, "double", "avoid-escape"], + "trailing-comma": [true, { + "multiline": { "objects": "always", "arrays": "always", "functions": "never" }, + "singleline": { "objects": "never", "arrays": "never", "functions": "never" } + }], + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-operator", + "check-module", + "check-separator", + "check-type", + "check-typecast", + "check-rest-spread", + "check-preblock" + ], + // Soon to be defaults. + "arrow-return-shorthand": [true, "multiline"], + "no-any": true, + "no-floating-promises": true, + "no-unbound-method": true, + "no-unsafe-any": true, + "number-literal-format": true, + "restrict-plus-operands": true, + "return-undefined": true, + "switch-final-break": true + } +} diff --git a/types/atom/.editorconfig b/types/atom/.editorconfig deleted file mode 100644 index 2b997514d2..0000000000 --- a/types/atom/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*.ts] -indent_style = tab -indent_size = 2 diff --git a/types/atom/atom-tests.ts b/types/atom/atom-tests.ts index 0f9def0a68..34f19e5f3e 100644 --- a/types/atom/atom-tests.ts +++ b/types/atom/atom-tests.ts @@ -524,6 +524,21 @@ regExp = cursor.subwordRegExp(); regExp = cursor.subwordRegExp({}); regExp = cursor.subwordRegExp({ backwards: true }); +//// CustomTestRunner ========================================================= +// http://flight-manual.atom.io/hacking-atom/sections/writing-specs/#customizing-your-test-runner +const testRunner: Atom.TestRunner = (params) => { + const delegate = params.buildDefaultApplicationDelegate(); + const environment = params.buildAtomEnvironment({ + applicationDelegate: delegate, + configDirPath: "/var/test", + document, + enablePersistence: false, + window, + }); + const { width, height } = environment.getSize(); + return Promise.resolve(width + height); +}; + //// Decoration =============================================================== // Construction and Destruction decoration.destroy(); @@ -1930,7 +1945,7 @@ sub = atom.workspace.onDidStopChangingActivePaneItem((item) => {}); sub = atom.workspace.onDidChangeActiveTextEditor(editor => { if (editor) { - editor.alive; + editor.id; } }); diff --git a/types/atom/index.d.ts b/types/atom/index.d.ts index 1cd564c19c..4a7f23cf60 100644 --- a/types/atom/index.d.ts +++ b/types/atom/index.d.ts @@ -309,6 +309,27 @@ declare global { /** The number of lines after the matched line to include in the results object. */ trailingContextLineCount?: number; } + + interface BuildEnvironment { + /** An object responsible for Atom's interaction with the browser process and host OS. + * Use buildDefaultApplicationDelegate for a default instance. + */ + applicationDelegate?: object; + + /** A window global. */ + window?: Window; + + /** A document global. */ + document?: Document; + + /** A path to the configuration directory (usually ~/.atom). */ + configDirPath?: string; + + /** A boolean indicating whether the Atom environment should save or load state + * from the file system. You probably want this to be false. + */ + enablePersistence?: boolean; + } } /** The static side to each exported class. Should generally only be used internally. */ @@ -348,6 +369,7 @@ declare global { // this appearing in the middle of the parameter list, which isn't aligned with // the ES6 spec. Maybe when they rewrite it in JavaScript this will change. /** A helper method to easily launch and run a task once. */ + // tslint:disable-next-line:no-any once(taskPath: string, ...args: any[]): AtomCore.Task; /** Creates a task. You should probably use .once */ @@ -446,6 +468,30 @@ declare global { resourcePath: string; safeMode: boolean; } + + interface TestRunnerArgs { + /** An array of paths to tests to run. Could be paths to files or directories. */ + testPaths: string[]; + + /** A function that can be called to construct an instance of the atom global. + * No atom global will be explicitly assigned, but you can assign one in your + * runner if desired. + */ + buildAtomEnvironment(options: Options.BuildEnvironment): AtomEnvironment; + + /** A function that builds a default instance of the application delegate, suitable + * to be passed as the applicationDelegate parameter to buildAtomEnvironment. + */ + buildDefaultApplicationDelegate(): object; + + /** An optional path to a log file to which test output should be logged. */ + logFile: string; + + /** A boolean indicating whether or not the tests are being run from the command + * line via atom --test. + */ + headless: boolean; + } } /** Atom global for dealing with packages, themes, menus, and the window. @@ -708,38 +754,47 @@ declare global { /** Add a listener for changes to a given key path. This is different than ::onDidChange in * that it will immediately call your callback with the current value of the config entry. */ + // tslint:disable-next-line:no-any observe(keyPath: string, callback: (value: any) => void): EventKit.Disposable; /** Add a listener for changes to a given key path. This is different than ::onDidChange in * that it will immediately call your callback with the current value of the config entry. */ + // tslint:disable:no-any observe(keyPath: string, options: { scope: string[]|ScopeDescriptor }, callback: (value: any) => void): EventKit.Disposable; + // tslint:enable:no-any /** Add a listener for changes to a given key path. If keyPath is not specified, your * callback will be called on changes to any key. */ + // tslint:disable-next-line:no-any onDidChange(callback: (values: { newValue: T, oldValue: T }) => void): EventKit.Disposable; /** Add a listener for changes to a given key path. If keyPath is not specified, your * callback will be called on changes to any key. */ + // tslint:disable-next-line:no-any onDidChange(keyPath: string, callback: (values: { newValue: T, oldValue: T }) => void): EventKit.Disposable; /** Add a listener for changes to a given key path. If keyPath is not specified, your * callback will be called on changes to any key. */ + // tslint:disable-next-line:no-any onDidChange(keyPath: string, options: { scope: string[]|ScopeDescriptor }, callback: (values: { newValue: T, oldValue: T }) => void): EventKit.Disposable; // Managing Settings /** Retrieves the setting for the given key. */ + // tslint:disable:no-any get(keyPath: string, options?: { sources?: string[], excludeSources?: string[], scope?: string[]|ScopeDescriptor }): any; + // tslint:enable:no-any /** Sets the value for a configuration setting. * This value is stored in Atom's internal configuration file. */ + // tslint:disable-next-line:no-any set(keyPath: string, value: any, options?: { scopeSelector?: string, source?: string }): void; @@ -749,8 +804,10 @@ declare global { /** Get all of the values for the given key-path, along with their associated * scope selector. */ + // tslint:disable:no-any getAll(keyPath: string, options?: { sources?: string[], excludeSources?: string[], scope?: ScopeDescriptor }): Array<{ scopeDescriptor: ScopeDescriptor, value: any}>; + // tslint:enable:no-any /** Get an Array of all of the source Strings with which settings have been added * via ::set. @@ -1395,21 +1452,6 @@ declare global { update(): void; } - interface Model { - // Properties - alive: boolean; - - // Lifecycle - /** Destroys this Model. */ - destroy(): void; - - /** Returns whether or not this Model is alive. */ - isAlive(): boolean; - - /** Returns whether or not this Model has been destroyed. */ - isDestroyed(): boolean; - } - /** A notification to the user containing a message and type. */ interface Notification { // Properties @@ -2214,6 +2256,7 @@ declare global { * Throws an error if this task has already been terminated or if sending a * message to the child process fails. */ + // tslint:disable-next-line:no-any start(...args: any[]): void; /** Send message to the task. @@ -2223,6 +2266,7 @@ declare global { send(message: string): void; /** Call a function when an event is emitted by the child process. */ + // tslint:disable-next-line:no-any on(eventName: string, callback: (param: any) => void): EventKit.Disposable; /** Forcefully stop the running task. @@ -2234,10 +2278,13 @@ declare global { cancel(): boolean; } + /** An interface which all custom test runners should implement. */ + type TestRunner = (params: Structures.TestRunnerArgs) => Promise; + /** This class represents all essential editing state for a single TextBuffer, * including cursor and selection positions, folds, and soft wraps. */ - interface TextEditor extends Model { + interface TextEditor { // Properties id: number; buffer: TextBuffer.TextBuffer; @@ -3440,6 +3487,7 @@ declare global { /** Add a provider that will be used to construct views in the workspace's view * layer based on model objects in its model layer. */ + // tslint:disable-next-line:no-any addViewProvider(modelConstructor: { new (...args: any[]): T }, createView: (instance: T) => HTMLElement|undefined): EventKit.Disposable; @@ -3895,6 +3943,7 @@ declare global { type ErrorNotification = AtomCore.Options.ErrorNotification; type Tooltip = AtomCore.Options.Tooltip; type WorkspaceScan = AtomCore.Options.WorkspaceScan; + type BuildEnvironment = AtomCore.Options.BuildEnvironment; } /** Data structures that are used within classes. */ @@ -3917,6 +3966,7 @@ declare global { type CancellablePromise = AtomCore.Structures.CancellablePromise; type ScandalResult = AtomCore.Structures.ScandalResult; type WindowLoadSettings = AtomCore.Structures.WindowLoadSettings; + type TestRunnerArgs = AtomCore.Structures.TestRunnerArgs; } // Atom Keymap ============================================================ @@ -4084,8 +4134,6 @@ declare global { /** Provides a registry for menu items that you'd like to appear in the application menu. */ type MenuManager = AtomCore.MenuManager; - type Model = AtomCore.Model; - /** A notification to the user containing a message and type. */ type Notification = AtomCore.Notification; @@ -4131,6 +4179,9 @@ declare global { /** Run a node script in a separate process. */ type Task = AtomCore.Task; + /** An interface which all custom test runners should implement. */ + type TestRunner = AtomCore.TestRunner; + /** This class represents all essential editing state for a single TextBuffer, * including cursor and selection positions, folds, and soft wraps. */ diff --git a/types/atom/tslint.json b/types/atom/tslint.json index a36bbd3600..adbd6dcf49 100644 --- a/types/atom/tslint.json +++ b/types/atom/tslint.json @@ -6,9 +6,7 @@ "class-name": true, "indent": [true, "tabs"], "jsdoc-format": true, - "linebreak-style": [true, "LF"], "max-line-length": [true, 100], - "no-any": false, "quotemark": [true, "double", "avoid-escape"], "trailing-comma": [true, { "multiline": { "objects": "always", "arrays": "always", "functions": "never" }, @@ -28,6 +26,7 @@ ], // Soon to be defaults. "arrow-return-shorthand": [true, "multiline"], + "no-any": true, "no-floating-promises": true, "no-unbound-method": true, "no-unsafe-any": true, diff --git a/types/event-kit/.editorconfig b/types/event-kit/.editorconfig deleted file mode 100644 index 2b997514d2..0000000000 --- a/types/event-kit/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*.ts] -indent_style = tab -indent_size = 2 diff --git a/types/event-kit/event-kit-tests.ts b/types/event-kit/event-kit-tests.ts index 41fa6ba22a..0cc6028fd6 100644 --- a/types/event-kit/event-kit-tests.ts +++ b/types/event-kit/event-kit-tests.ts @@ -14,7 +14,7 @@ class User { this.emitter = new Emitter(); } - onDidChangeName(callback: (value: any) => void) { + onDidChangeName(callback: (value: string) => void) { return this.emitter.on("did-change-name", callback); } diff --git a/types/event-kit/index.d.ts b/types/event-kit/index.d.ts index 8ce9bd8fbe..0df33472b1 100644 --- a/types/event-kit/index.d.ts +++ b/types/event-kit/index.d.ts @@ -92,21 +92,25 @@ declare global { // Event Subscription /** Registers a handler to be invoked whenever the given event is emitted. */ + // tslint:disable-next-line:no-any on(eventName: string, handler: (value: any) => void): Disposable; /** Register the given handler function to be invoked the next time an event * with the given name is emitted via ::emit. */ + // tslint:disable-next-line:no-any once(eventName: string, handler: (value: any) => void): Disposable; /** Register the given handler function to be invoked before all other * handlers existing at the time of subscription whenever events by the * given name are emitted via ::emit. */ + // tslint:disable-next-line:no-any preempt(eventName: string, handler: (value: any) => void): Disposable; // Event Emission /** Invoke handlers registered via ::on for the given event name. */ + // tslint:disable-next-line:no-any emit(eventName: string, value?: any): void; } } diff --git a/types/event-kit/tslint.json b/types/event-kit/tslint.json index 10fd9f0654..4b036f727a 100644 --- a/types/event-kit/tslint.json +++ b/types/event-kit/tslint.json @@ -5,9 +5,7 @@ "class-name": true, "indent": [true, "tabs"], "jsdoc-format": true, - "linebreak-style": [true, "LF"], "max-line-length": [true, 100], - "no-any": false, "quotemark": [true, "double", "avoid-escape"], "trailing-comma": [true, { "multiline": { "objects": "always", "arrays": "always", "functions": "never" }, @@ -27,6 +25,7 @@ ], // Soon to be defaults. "arrow-return-shorthand": [true, "multiline"], + "no-any": true, "no-floating-promises": true, "no-unbound-method": true, "no-unsafe-any": true, diff --git a/types/first-mate/.editorconfig b/types/first-mate/.editorconfig deleted file mode 100644 index 2b997514d2..0000000000 --- a/types/first-mate/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*.ts] -indent_style = tab -indent_size = 2 diff --git a/types/first-mate/index.d.ts b/types/first-mate/index.d.ts index 0986b80aa5..cf812b6add 100644 --- a/types/first-mate/index.d.ts +++ b/types/first-mate/index.d.ts @@ -19,11 +19,11 @@ declare global { maxTokensPerLine?: number; maxLineLength?: number; - injections?: any; - injectionSelector?: any; + injections?: object; + injectionSelector?: ScopeSelector; patterns?: ReadonlyArray; repository?: object; - firstLineMatch?: any; + firstLineMatch?: boolean; } } diff --git a/types/first-mate/tslint.json b/types/first-mate/tslint.json index 22fcf73c1c..4b036f727a 100644 --- a/types/first-mate/tslint.json +++ b/types/first-mate/tslint.json @@ -5,7 +5,6 @@ "class-name": true, "indent": [true, "tabs"], "jsdoc-format": true, - "linebreak-style": [true, "LF"], "max-line-length": [true, 100], "quotemark": [true, "double", "avoid-escape"], "trailing-comma": [true, { @@ -24,10 +23,9 @@ "check-rest-spread", "check-preblock" ], - // TODO - "no-any": false, // Soon to be defaults. "arrow-return-shorthand": [true, "multiline"], + "no-any": true, "no-floating-promises": true, "no-unbound-method": true, "no-unsafe-any": true, diff --git a/types/pathwatcher/.editorconfig b/types/pathwatcher/.editorconfig deleted file mode 100644 index 2b997514d2..0000000000 --- a/types/pathwatcher/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*.ts] -indent_style = tab -indent_size = 2 diff --git a/types/pathwatcher/tslint.json b/types/pathwatcher/tslint.json index cd8f17056a..4b036f727a 100644 --- a/types/pathwatcher/tslint.json +++ b/types/pathwatcher/tslint.json @@ -5,7 +5,6 @@ "class-name": true, "indent": [true, "tabs"], "jsdoc-format": true, - "linebreak-style": [true, "LF"], "max-line-length": [true, 100], "quotemark": [true, "double", "avoid-escape"], "trailing-comma": [true, { diff --git a/types/text-buffer/.editorconfig b/types/text-buffer/.editorconfig deleted file mode 100644 index 2b997514d2..0000000000 --- a/types/text-buffer/.editorconfig +++ /dev/null @@ -1,3 +0,0 @@ -[*.ts] -indent_style = tab -indent_size = 2 diff --git a/types/text-buffer/tslint.json b/types/text-buffer/tslint.json index cd8f17056a..4b036f727a 100644 --- a/types/text-buffer/tslint.json +++ b/types/text-buffer/tslint.json @@ -5,7 +5,6 @@ "class-name": true, "indent": [true, "tabs"], "jsdoc-format": true, - "linebreak-style": [true, "LF"], "max-line-length": [true, 100], "quotemark": [true, "double", "avoid-escape"], "trailing-comma": [true, {