Skip to content

Commit

Permalink
fix(ts-2.4): Fix type issues for typescript 2.4 (#337)
Browse files Browse the repository at this point in the history
* The task api type of T (instead of `T | undefined`)
* Mutator api copy siganture
  • Loading branch information
nicojs authored and simondel committed Jul 14, 2017
1 parent 6fb998a commit c18079b
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 59 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"chai-as-promised": "^6.0.0",
"concurrently": "^3.4.0",
"glob": "^7.1.1",
"lerna": "^2.0.0-rc.5",
"lerna": "^2.0.0",
"link-parent-bin": "^0.1.1",
"mocha": "^3.2.0",
"nyc": "^10.2.0",
Expand All @@ -50,4 +50,4 @@
"test:stryker-api": "lerna run test --scope stryker",
"lerna-publish": "lerna publish --conventional-commits --yes --git-remote gh-publish"
}
}
}
46 changes: 9 additions & 37 deletions packages/stryker-api/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,19 @@
"version": "0.2.0",
"configurations": [
{
"name": "Run unit tests",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/grunt-cli/bin/grunt",
"preLaunchTask": "build",
"stopOnEntry": false,
"name": "Unit tests",
"program": "${workspaceRoot}/../../node_modules/mocha/bin/_mocha",
"args": [
"mochaTest:unit"
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceRoot}/test/**/*.js"
],
"cwd": "${workspaceRoot}/.",
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}"
},{
"name": "Run integration tests",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/grunt-cli/bin/grunt",
// "preLaunchTask": "build",
"stopOnEntry": false,
"args": [
"mochaTest:integration"
],
"cwd": "${workspaceRoot}/.",
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}"
"internalConsoleOptions": "openOnSessionStart"
}
]
}
11 changes: 11 additions & 0 deletions packages/stryker-api/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"args": ["start"],
"showOutput": "silent",
"isBackground": true,
"problemMatcher": "$tsc-watch"
}
8 changes: 6 additions & 2 deletions packages/stryker-api/testResources/module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
"use:test_framework": "node useTestFramework.js",
"use:mutant": "node useMutant.js",
"use:report": "node useReport.js",
"use:test_runner": "node useTestRunner.js"
"use:test_runner": "node useTestRunner.js",
"postinstall": "install-local"
},
"author": "",
"license": "ISC",
"devDependencies": {
"stryker-api": "file:../../",
"install-local": "^0.4.0",
"typescript": "^2.2.2"
},
"localDependencies": {
"stryker-api": "../.."
}
}
1 change: 1 addition & 0 deletions packages/stryker-karma-runner/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"typescript.tsdk": "../../node_modules/typescript/lib",
"files": {
"exclude": {
".git": "",
Expand Down
11 changes: 11 additions & 0 deletions packages/stryker-karma-runner/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"args": ["start"],
"showOutput": "silent",
"isBackground": true,
"problemMatcher": "$tsc-watch"
}
6 changes: 4 additions & 2 deletions packages/stryker-karma-runner/src/KarmaConfigReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class KarmaConfigReader {
// We cannot delegate config reading to karma's config reader, because we cannot serialize the result to child processes
// It results in: TypeError: Serializing native function: bound configure
const configModule = requireModule(this.karmaConfigFile);
const config = new Config();
const config: karma.ConfigOptions = new Config();
configModule(config);

// Use native functionality of parsing the files, so we ensure that those are correctly resolved
Expand Down Expand Up @@ -67,7 +67,9 @@ export default class KarmaConfigReader {

class Config implements karma.ConfigOptions {
[key: string]: any


autoWatch: boolean = false;

readonly LOG_DISABLE = 'OFF';
readonly LOG_ERROR = 'ERROR';
readonly LOG_WARN = 'WARN';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default class TestRunnerChildProcessAdapter extends EventEmitter implemen
return this.currentTask.promise;
}

dispose(): Promise<undefined> {
dispose(): Promise<void> {
this.currentTask = new DisposeTask(MAX_WAIT_FOR_DISPOSE);
this.sendDisposeCommand();
return this.currentTask.promise
Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/src/mutators/ArrayDeclaratorMutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class ArrayDeclaratorMutator implements Mutator {

constructor() { }

applyMutations(node: IdentifiedNode, copy: <T>(obj: T, deep?: boolean) => T): void | IdentifiedNode {
applyMutations(node: IdentifiedNode, copy: <T extends IdentifiedNode> (obj: T, deep?: boolean) => T): void | IdentifiedNode {
if ((node.type === Syntax.CallExpression || node.type === Syntax.NewExpression) && node.callee.type === Syntax.Identifier && node.callee.name === 'Array' && node.arguments.length > 0) {
let mutatedNode = copy(node);
mutatedNode.arguments = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/src/mutators/BinaryOperatorMutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class BinaryOperatorMutator implements Mutator {
'!==': '==='
};

applyMutations(node: IdentifiedNode, copy: <T>(obj: T, deep?: boolean) => T): IdentifiedNode[] {
applyMutations(node: IdentifiedNode, copy: <T extends IdentifiedNode> (obj: T, deep?: boolean) => T): IdentifiedNode[] {
let nodes: IdentifiedNode[] = [];

if (node.type === this.type && this.operators[node.operator]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/src/mutators/BlockStatementMutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class BlockStatementMutator implements Mutator {

constructor() { }

applyMutations(node: IdentifiedNode, copy: <T>(obj: T, deep?: boolean) => T): void | IdentifiedNode {
applyMutations(node: IdentifiedNode, copy: <T extends IdentifiedNode> (obj: T, deep?: boolean) => T): void | IdentifiedNode {
if (node.type === this.type && node.body.length > 0) {
let mutatedNode = copy(node);
mutatedNode.body = [];
Expand Down
7 changes: 4 additions & 3 deletions packages/stryker/src/mutators/BooleanSubstitutionMutator.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Mutator, IdentifiedNode } from 'stryker-api/mutant';
import { Mutator, IdentifiedNode, Identified } from 'stryker-api/mutant';
import { Syntax } from 'esprima';
import { Expression } from 'estree';

export default class BooleanSubstitutionMutator implements Mutator {
name = 'BooleanSubstitution';

applyMutations(node: IdentifiedNode, copy: <T>(obj: T, deep?: boolean) => T): IdentifiedNode[] {
applyMutations(node: IdentifiedNode, copy: <T extends IdentifiedNode> (obj: T, deep?: boolean) => T): IdentifiedNode[] {
const nodes: IdentifiedNode[] = [];

// !a -> a
if (node.type === Syntax.UnaryExpression && node.operator === '!') {
let mutatedNode = copy(node.argument) as IdentifiedNode;
let mutatedNode = copy(node.argument as Expression & Identified) as IdentifiedNode;
mutatedNode.nodeID = node.nodeID;
nodes.push(mutatedNode);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/src/mutators/LogicalOperatorMutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class LogicalOperatorMutator implements Mutator {
'||': '&&'
};

applyMutations(node: IdentifiedNode, copy: <T>(obj: T, deep?: boolean) => T): IdentifiedNode[] {
applyMutations(node: IdentifiedNode, copy: <T extends IdentifiedNode> (obj: T, deep?: boolean) => T): IdentifiedNode[] {
let nodes: IdentifiedNode[] = [];

if (node.type === this.type && this.operators[node.operator]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/src/mutators/RemoveConditionalsMutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class RemoveConditionalsMutator implements Mutator {

constructor() { }

applyMutations(node: IdentifiedNode, copy: <T>(obj: T, deep?: boolean) => T): IdentifiedNode[] | void {
applyMutations(node: IdentifiedNode, copy: <T extends IdentifiedNode> (obj: T, deep?: boolean) => T): IdentifiedNode[] | void {
if (this.canMutate(node)) {
let nodes: IdentifiedNode[] = [];

Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/src/mutators/UnaryOperatorMutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class UnaryOperatorMutator implements Mutator {
'-': '+'
};

applyMutations(node: IdentifiedNode, copy: <T>(obj: T, deep?: boolean) => T): IdentifiedNode[] {
applyMutations(node: IdentifiedNode, copy: <T extends IdentifiedNode> (obj: T, deep?: boolean) => T): IdentifiedNode[] {
let nodes: IdentifiedNode[] = [];

if (node.type === this.type && this.operators[node.operator]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/src/mutators/UpdateOperatorMutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class UpdateOperatorMutator implements Mutator {
'--': '++'
};

applyMutations(node: IdentifiedNode, copy: <T>(obj: T, deep?: boolean) => T): void | IdentifiedNode {
applyMutations(node: IdentifiedNode, copy: <T extends IdentifiedNode> (obj: T, deep?: boolean) => T): void | IdentifiedNode {
if (node.type === this.type && this.operators[node.operator]) {
let mutatedNode = copy(node);
mutatedNode.operator = this.operators[node.operator];
Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/src/utils/StrykerTempFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function writeFile(filename: string, data: string): Promise<void> {
function copyFile(fromFilename: string, toFilename: string, instrumenter: NodeJS.ReadWriteStream | null): Promise<void> {
return new Promise<void>((resolve, reject) => {
let readStream: NodeJS.ReadableStream = fs.createReadStream(fromFilename, { encoding: 'utf8' });
let writeStream = fs.createWriteStream(toFilename, { encoding: 'utf8' });
let writeStream = fs.createWriteStream(toFilename);
readStream.on('error', reject);
writeStream.on('error', reject);
if (instrumenter) {
Expand Down
6 changes: 3 additions & 3 deletions packages/stryker/src/utils/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
*/
export default class Task<T> {

private _promise: Promise<T | undefined>;
private resolveFn: (value?: undefined | T | PromiseLike<T>) => void;
private _promise: Promise<T>;
private resolveFn: (value?: T | PromiseLike<T>) => void;
private rejectFn: (reason: any) => void;
private _isResolved = false;
private timeout: NodeJS.Timer;

constructor(timeoutMs?: number, private timeoutHandler?: () => PromiseLike<T>) {
this._promise = new Promise<T | undefined>((resolve, reject) => {
this._promise = new Promise<T>((resolve, reject) => {
this.resolveFn = resolve;
this.rejectFn = reject;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('ProgressAppendOnlyReporter', () => {
});

it('should should log 50% with 10s ETC after 10s with 1 completed test', () => {
sut.onMutantTested(mutantResult(MutantStatus.Killed));
sut.onMutantTested(mutantResult({ status: MutantStatus.Killed }));
expect(process.stdout.write).to.not.have.been.called;
sandbox.clock.tick(10000);
expect(process.stdout.write).to.have.been.calledWith(`Mutation testing 50% (ETC 10s) ` +
Expand Down

0 comments on commit c18079b

Please sign in to comment.