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.
This commit is contained in:
Glen M 2017-10-09 18:43:18 -04:00 committed by Wesley Wigham
parent b4b8c2f7d3
commit ea4008d4e8
22 changed files with 236 additions and 52 deletions

View File

@ -1,3 +0,0 @@
[*.ts]
indent_style = tab
indent_size = 2

View File

@ -21,4 +21,4 @@
"index.d.ts",
"atom-keymap-tests.ts"
]
}
}

View File

@ -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, {

View File

@ -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<number> {
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);
}

39
types/atom-mocha-test-runner/index.d.ts vendored Normal file
View File

@ -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 <https://github.com/GlenCFL>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="atom" />
/// <reference types="mocha" />
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;

View File

@ -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"
]
}

View File

@ -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
}
}

View File

@ -1,3 +0,0 @@
[*.ts]
indent_style = tab
indent_size = 2

View File

@ -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;
}
});

87
types/atom/index.d.ts vendored
View File

@ -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<T = any>(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<T = any>(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<T = any>(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<number>;
/** 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<T>(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<T> = AtomCore.Structures.CancellablePromise<T>;
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.
*/

View File

@ -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,

View File

@ -1,3 +0,0 @@
[*.ts]
indent_style = tab
indent_size = 2

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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,

View File

@ -1,3 +0,0 @@
[*.ts]
indent_style = tab
indent_size = 2

View File

@ -19,11 +19,11 @@ declare global {
maxTokensPerLine?: number;
maxLineLength?: number;
injections?: any;
injectionSelector?: any;
injections?: object;
injectionSelector?: ScopeSelector;
patterns?: ReadonlyArray<object>;
repository?: object;
firstLineMatch?: any;
firstLineMatch?: boolean;
}
}

View File

@ -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,

View File

@ -1,3 +0,0 @@
[*.ts]
indent_style = tab
indent_size = 2

View File

@ -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, {

View File

@ -1,3 +0,0 @@
[*.ts]
indent_style = tab
indent_size = 2

View File

@ -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, {