From 1c5db5c08dd1ecc2c9cf9bf3d3a3371e0bf7b349 Mon Sep 17 00:00:00 2001 From: Nico Jansen Date: Mon, 3 Oct 2016 17:27:53 +0200 Subject: [PATCH] feat(ts2.0): Migrate to typescript 2.0 (#154) * feat(ts-2): Upgrade to typescript 2 * Using @types dev dependencies * Update estree node structure in mutator module * Remove dependency on typings * Fix(mutators) Use new ESTree API * feat(mutants): Make use of ts2 type narrowing * Make use of ts2 type narrowing * Rename module 'stryker-api/estree' back to 'estree' * feat(ts2.0): Update mutators * Update mutators by injecting the new signature of the copy function. This allows us to remove most of the type castings. * refactor(Mutators) Use new estree API * fix(lint): Fix linting issues Mostely: * Semicolon * Whitespaces * double quotes <> single quotes * fix(deps): Stryker-api v0.3.0-0 * Removed unused other stryker dependencies * fix(RemoveConditionalsMutator): Use correct nodeID * Use the nodeID of the test expression wrather than the if-expression itself. * Add Ternary operator `true` mutation * fix(stryker-api): Make stryker backward compatible * Make stryker backward compatible with stryker-api@0.2.0 by removing the import of the new `'stryker-api/estree'` --- .bithoundrc | 11 +- Gruntfile.js | 10 +- customTyping/karma.d.ts | 396 ------------------ package.json | 25 +- src/ConfigReader.ts | 20 +- src/InputFileResolver.ts | 6 +- src/MutantRunResultMatcher.ts | 2 +- src/MutatorOrchestrator.ts | 49 ++- src/PluginLoader.ts | 16 +- src/Stryker.ts | 2 +- src/TestRunnerOrchestrator.ts | 17 +- .../IsolatedTestRunnerAdapter.ts | 20 +- .../IsolatedTestRunnerAdapterFactory.ts | 6 +- src/mutators/BinaryOperatorMutator.ts | 43 ++ src/mutators/BlockStatementMutator.ts | 19 +- src/mutators/ConditionalBoundaryMutator.ts | 15 - src/mutators/LogicalOperatorMutator.ts | 25 ++ src/mutators/MathMutator.ts | 15 - src/mutators/OperatorMutator.ts | 43 -- src/mutators/OperatorMutatorMap.ts | 5 - src/mutators/RemoveConditionalsMutator.ts | 46 +- src/mutators/ReverseConditionalMutator.ts | 18 - src/mutators/UnaryOperatorMutator.ts | 31 +- src/mutators/UpdateOperatorMutator.ts | 25 ++ src/reporters/BroadcastReporter.ts | 16 +- src/reporters/ClearTextReporter.ts | 10 +- src/reporters/EventRecorderReporter.ts | 14 +- src/stryker-cli.ts | 4 +- src/utils/StrykerTempFolder.ts | 6 +- src/utils/fileUtils.ts | 8 +- src/utils/objectUtils.ts | 10 + src/utils/parserUtils.ts | 9 +- test/integration/install-module/Executor.ts | 4 +- .../install-module/install-module.ts | 2 +- .../DirectResolvedTestRunner.ts | 10 +- .../IsolatedTestRunnerAdapterSpec.ts | 12 +- .../NeverResolvedTestRunner.ts | 8 +- .../SlowInitAndDisposeTestRunner.ts | 18 +- test/integration/utils/fileUtilsSpec.ts | 12 +- test/unit/InputFileResolverSpec.ts | 12 +- test/unit/MutantSpec.ts | 45 +- test/unit/MutatorOrchestratorSpec.ts | 13 +- test/unit/PluginLoaderSpec.ts | 2 +- test/unit/StrykerSpec.ts | 10 +- test/unit/TestRunnerOrchestratorSpec.ts | 6 +- test/unit/TestSelectorOrchestratorSpec.ts | 4 +- .../IsolatedTestRunnerAdapterSpec.ts | 4 +- .../JasmineTestSelectorSpec.ts | 10 +- .../mutators/BinaryOperatorMutatorSpec.ts | 49 +++ test/unit/mutators/OperatorMutatorSpec.ts | 55 --- .../mutators/RemoveConditionalsMutatorSpec.ts | 91 ++-- test/unit/reporters/ClearTextReporterSpec.ts | 2 +- .../reporters/EventRecorderReporterSpec.ts | 4 +- test/unit/reporters/ProgressReporterSpec.ts | 2 +- test/unit/utils/parserUtilsSpec.ts | 6 +- testResources/module/package.json | 8 +- testResources/module/typings.json | 6 - tslint.json | 58 +++ typings.json | 28 -- 59 files changed, 561 insertions(+), 862 deletions(-) delete mode 100644 customTyping/karma.d.ts create mode 100644 src/mutators/BinaryOperatorMutator.ts delete mode 100644 src/mutators/ConditionalBoundaryMutator.ts create mode 100644 src/mutators/LogicalOperatorMutator.ts delete mode 100644 src/mutators/MathMutator.ts delete mode 100644 src/mutators/OperatorMutator.ts delete mode 100644 src/mutators/OperatorMutatorMap.ts delete mode 100644 src/mutators/ReverseConditionalMutator.ts create mode 100644 src/mutators/UpdateOperatorMutator.ts create mode 100644 test/unit/mutators/BinaryOperatorMutatorSpec.ts delete mode 100644 test/unit/mutators/OperatorMutatorSpec.ts delete mode 100644 testResources/module/typings.json create mode 100644 tslint.json delete mode 100644 typings.json diff --git a/.bithoundrc b/.bithoundrc index d017cc048c..1af1f841c4 100644 --- a/.bithoundrc +++ b/.bithoundrc @@ -1,5 +1,10 @@ { "critics": { - "lint": { "engine": "tslint" } - } -} \ No newline at end of file + "lint": { "engine": "tslint" }, + "wc": { "limit": 3000 } + }, + "test": [ + "test/**", + "testResources/**" + ] +} diff --git a/Gruntfile.js b/Gruntfile.js index 9737362084..9b71d43289 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -114,13 +114,21 @@ module.exports = function (grunt) { commitMessage: 'chore: release v%VERSION%', prereleaseName: 'rc' } + }, + tslint: { + src: { + src: ['*.ts', 'src/**/*.ts'] + }, + test: { + src: ['test/**/*.ts', 'testResources/module/*.ts'] + } } }); grunt.registerTask('default', ['test']); grunt.registerTask('watch-test', ['test', 'watch']); grunt.registerTask('test', ['build', 'coverage']); - grunt.registerTask('build', ['clean', 'ts']); + grunt.registerTask('build', ['clean', 'tslint', 'ts']); grunt.registerTask('integration', ['mochaTest:integration']); grunt.registerTask('coverage', ['mocha_istanbul:coverage']); grunt.registerTask('serve', ['watch']); diff --git a/customTyping/karma.d.ts b/customTyping/karma.d.ts deleted file mode 100644 index 68007f1bf1..0000000000 --- a/customTyping/karma.d.ts +++ /dev/null @@ -1,396 +0,0 @@ -// Type definitions for karma v0.13.9 -// Project: https://github.com/karma-runner/karma -// Definitions by: Tanguy Krotoff -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// -/// -/// - -declare module 'karma' { - // See Karma public API https://karma-runner.github.io/0.13/dev/public-api.html - import Promise = require('bluebird'); - import https = require('https'); - import log4js = require('log4js'); - - namespace karma { - interface Karma { - /** - * `start` method is deprecated since 0.13. It will be removed in 0.14. - * Please use - * - * server = new Server(config, [done]) - * server.start() - * - * instead. - */ - server: DeprecatedServer; - Server: Server; - runner: Runner; - launcher: Launcher; - VERSION: string; - } - - interface LauncherStatic { - generateId(): string; - //TODO: injector should be of type `di.Injector` - new (emitter: NodeJS.EventEmitter, injector: any): Launcher; - } - - interface Launcher { - Launcher: LauncherStatic; - //TODO: Can this return value ever be typified? - launch(names: string[], protocol: string, hostname: string, port: number, urlRoot: string): any[]; - kill(id: string, callback: Function): boolean; - restart(id: string): boolean; - killAll(callback: Function): void; - areAllCaptured(): boolean; - markCaptured(id: string): void; - } - - interface DeprecatedServer { - start(options?: any, callback?: ServerCallback): void; - } - - interface Runner { - run(options?: ConfigOptions | ConfigFile, callback?: ServerCallback): void; - } - - interface TestResults { - disconnected: boolean; - error: boolean; - exitCode: number; - failed: number; - success: number; - } - - interface Server extends NodeJS.EventEmitter { - new (options?: ConfigOptions | ConfigFile, callback?: ServerCallback): Server; - /** - * Start the server - */ - start(): void; - /** - * Get properties from the injector - * @param token - */ - get(token: string): any; - /** - * Force a refresh of the file list - */ - refreshFiles(): Promise; - - on(event: string, listener: Function): this; - - /** - * Listen to the 'run_complete' event. - */ - on(event: 'run_complete', listener: (browsers: any, results: TestResults ) => void): this; - - ///** - // * Backward-compatibility with karma-intellij bundled with WebStorm. - // * Deprecated since version 0.13, to be removed in 0.14 - // */ - //static start(): void; - } - - interface ServerCallback { - (exitCode: number): void; - } - - interface Config { - set: (config: ConfigOptions) => void; - LOG_DISABLE: string; - LOG_ERROR: string; - LOG_WARN: string; - LOG_INFO: string; - LOG_DEBUG: string; - } - - interface ConfigFile { - configFile: string; - } - - interface ConfigOptions { - /** - * @description Enable or disable watching files and executing the tests whenever one of these files changes. - * @default true - */ - autoWatch?: boolean; - /** - * @description When Karma is watching the files for changes, it tries to batch multiple changes into a single run - * so that the test runner doesn't try to start and restart running tests more than it should. - * The configuration setting tells Karma how long to wait (in milliseconds) after any changes have occurred - * before starting the test process again. - * @default 250 - */ - autoWatchBatchDelay?: number; - /** - * @default '' - * @description The root path location that will be used to resolve all relative paths defined in files and exclude. - * If the basePath configuration is a relative path then it will be resolved to - * the __dirname of the configuration file. - */ - basePath?: string; - /** - * @default 2000 - * @description How long does Karma wait for a browser to reconnect (in ms). - *

- * With a flaky connection it is pretty common that the browser disconnects, - * but the actual test execution is still running without any problems. Karma does not treat a disconnection - * as immediate failure and will wait browserDisconnectTimeout (ms). - * If the browser reconnects during that time, everything is fine. - *

- */ - browserDisconnectTimeout?: number; - /** - * @default 0 - * @description The number of disconnections tolerated. - *

- * The disconnectTolerance value represents the maximum number of tries a browser will attempt - * in the case of a disconnection. Usually any disconnection is considered a failure, - * but this option allows you to define a tolerance level when there is a flaky network link between - * the Karma server and the browsers. - *

- */ - browserDisconnectTolerance?: number; - /** - * @default 10000 - * @description How long will Karma wait for a message from a browser before disconnecting from it (in ms). - *

- * If, during test execution, Karma does not receive any message from a browser within - * browserNoActivityTimeout (ms), it will disconnect from the browser - *

- */ - browserNoActivityTimeout?: number; - /** - * @default [] - * Possible Values: - *
    - *
  • Chrome (launcher comes installed with Karma)
  • - *
  • ChromeCanary (launcher comes installed with Karma)
  • - *
  • PhantomJS (launcher comes installed with Karma)
  • - *
  • Firefox (launcher requires karma-firefox-launcher plugin)
  • - *
  • Opera (launcher requires karma-opera-launcher plugin)
  • - *
  • Internet Explorer (launcher requires karma-ie-launcher plugin)
  • - *
  • Safari (launcher requires karma-safari-launcher plugin)
  • - *
- * @description A list of browsers to launch and capture. When Karma starts up, it will also start up each browser - * which is placed within this setting. Once Karma is shut down, it will shut down these browsers as well. - * You can capture any browser manually by opening the browser and visiting the URL where - * the Karma web server is listening (by default it is http://localhost:9876/). - */ - browsers?: string[]; - /** - * @default 60000 - * @description Timeout for capturing a browser (in ms). - *

- * The captureTimeout value represents the maximum boot-up time allowed for a - * browser to start and connect to Karma. If any browser does not get captured within the timeout, Karma - * will kill it and try to launch it again and, after three attempts to capture it, Karma will give up. - *

- */ - captureTimeout?: number; - client?: ClientOptions; - /** - * @default true - * @description Enable or disable colors in the output (reporters and logs). - */ - colors?: boolean; - /** - * @default [] - * @description List of files/patterns to exclude from loaded files. - */ - exclude?: string[]; - /** - * @default [] - * @description List of files/patterns to load in the browser. - */ - files?: (FilePattern | string)[]; - /** - * @default [] - * @description List of test frameworks you want to use. Typically, you will set this to ['jasmine'], ['mocha'] or ['qunit']... - * Please note just about all frameworks in Karma require an additional plugin/framework library to be installed (via NPM). - */ - frameworks?: string[]; - /** - * @default 'localhost' - * @description Hostname to be used when capturing browsers. - */ - hostname?: string; - /** - * @default {} - * @description Options object to be used by Node's https class. - * Object description can be found in the - * [NodeJS.org API docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener) - */ - httpsServerOptions?: https.ServerOptions; - /** - * @default config.LOG_INFO - * Possible values: - *
    - *
  • config.LOG_DISABLE
  • - *
  • config.LOG_ERROR
  • - *
  • config.LOG_WARN
  • - *
  • config.LOG_INFO
  • - *
  • config.LOG_DEBUG
  • - *
- * @description Level of logging. - */ - logLevel?: string; - /** - * @default [{type: 'console'}] - * @description A list of log appenders to be used. See the documentation for [log4js] for more information. - */ - loggers?: log4js.AppenderConfigBase[]; - /** - * @default ['karma-*'] - * @description List of plugins to load. A plugin can be a string (in which case it will be required - * by Karma) or an inlined plugin - Object. - * By default, Karma loads all sibling NPM modules which have a name starting with karma-*. - * Note: Just about all plugins in Karma require an additional library to be installed (via NPM). - */ - plugins?: any[]; - /** - * @default 9876 - * @description The port where the web server will be listening. - */ - port?: number; - /** - * @default {'**\/*.coffee': 'coffee'} - * @description A map of preprocessors to use. - * - * Preprocessors can be loaded through [plugins]. - * - * Note: Just about all preprocessors in Karma (other than CoffeeScript and some other defaults) - * require an additional library to be installed (via NPM). - * - * Be aware that preprocessors may be transforming the files and file types that are available at run time. For instance, - * if you are using the "coverage" preprocessor on your source files, if you then attempt to interactively debug - * your tests, you'll discover that your expected source code is completely changed from what you expected. Because - * of that, you'll want to engineer this so that your automated builds use the coverage entry in the "reporters" list, - * but your interactive debugging does not. - * - */ - preprocessors?: { [name: string]: string | string[] } - /** - * @default 'http:' - * Possible Values: - *
    - *
  • http:
  • - *
  • https:
  • - *
- * @description Protocol used for running the Karma webserver. - * Determines the use of the Node http or https class. - * Note: Using 'https:' requires you to specify httpsServerOptions. - */ - protocol?: string; - /** - * @default {} - * @description A map of path-proxy pairs. - */ - proxies?: { [path: string]: string } - /** - * @default true - * @description Whether or not Karma or any browsers should raise an error when an inavlid SSL certificate is found. - */ - proxyValidateSSL?: boolean; - /** - * @default 0 - * @description Karma will report all the tests that are slower than given time limit (in ms). - * This is disabled by default (since the default value is 0). - */ - reportSlowerThan?: number; - /** - * @default ['progress'] - * Possible Values: - *
    - *
  • dots
  • - *
  • progress
  • - *
- * @description A list of reporters to use. - * Additional reporters, such as growl, junit, teamcity or coverage can be loaded through plugins. - * Note: Just about all additional reporters in Karma (other than progress) require an additional library to be installed (via NPM). - */ - reporters?: string[]; - /** - * @default false - * @description Continuous Integration mode. - * If true, Karma will start and capture all configured browsers, run tests and then exit with an exit code of 0 or 1 depending - * on whether all tests passed or any tests failed. - */ - singleRun?: boolean; - /** - * @default ['polling', 'websocket'] - * @description An array of allowed transport methods between the browser and testing server. This configuration setting - * is handed off to [socket.io](http://socket.io/) (which manages the communication - * between browsers and the testing server). - */ - transports?: string[]; - /** - * @default '/' - * @description The base url, where Karma runs. - * All of Karma's urls get prefixed with the urlRoot. This is helpful when using proxies, as - * sometimes you might want to proxy a url that is already taken by Karma. - */ - urlRoot?: string; - } - - interface ClientOptions { - /** - * @default undefined - * @description When karma run is passed additional arguments on the command-line, they - * are passed through to the test adapter as karma.config.args (an array of strings). - * The client.args option allows you to set this value for actions other than run. - * How this value is used is up to your test adapter - you should check your adapter's - * documentation to see how (and if) it uses this value. - */ - args?: string[]; - /** - * @default true - * @description Run the tests inside an iFrame or a new window - * If true, Karma runs the tests inside an iFrame. If false, Karma runs the tests in a new window. Some tests may not run in an - * iFrame and may need a new window to run. - */ - useIframe?: boolean; - /** - * @default true - * @description Capture all console output and pipe it to the terminal. - */ - captureConsole?: boolean; - } - - interface FilePattern { - /** - * The pattern to use for matching. This property is mandatory. - */ - pattern: string; - /** - * @default true - * @description If autoWatch is true all files that have set watched to true will be watched - * for changes. - */ - watched?: boolean; - /** - * @default true - * @description Should the files be included in the browser using