Skip to content

Commit

Permalink
fix(any-promise): Don't register a promise implementation (#1180)
Browse files Browse the repository at this point in the history
Remove dependency on 'mz' which in turn removes the depencency
on 'any-promise'. This will allow test processes to roll their own
Promise implementation
using ['any-promise'](https://www.npmjs.com/package/any-promise)

Add '@stryker-mutator/util' as a dependency. In there we can maintain library
logic that we want to share between plugins and core packages.
The promisified fs and child_process implementations moved to this package.
The idea of promisified API's is that they can gradually
be removed in the future (node 8 and 10).
  • Loading branch information
nicojs committed Oct 15, 2018
1 parent 6bc69ae commit 1d3e2f6
Show file tree
Hide file tree
Showing 67 changed files with 473 additions and 247 deletions.
6 changes: 3 additions & 3 deletions integrationTest/helpers.ts
@@ -1,12 +1,12 @@
import * as path from 'path';
import * as fs from 'mz/fs';
import { fsAsPromised } from '@stryker-mutator/util';
import { expect } from 'chai';
import { ScoreResult } from 'stryker-api/report';

export async function readScoreResult(eventResultDirectory = path.resolve('reports', 'mutation', 'events')) {
const allReportFiles = await fs.readdir(eventResultDirectory);
const allReportFiles = await fsAsPromised.readdir(eventResultDirectory);
const scoreResultReportFile = allReportFiles.find(file => !!file.match(/.*onScoreCalculated.*/));
expect(scoreResultReportFile).ok;
const scoreResultContent = await fs.readFile(path.resolve(eventResultDirectory, scoreResultReportFile || ''), 'utf8');
const scoreResultContent = await fsAsPromised.readFile(path.resolve(eventResultDirectory, scoreResultReportFile || ''), 'utf8');
return JSON.parse(scoreResultContent) as ScoreResult;
}
2 changes: 1 addition & 1 deletion integrationTest/package.json
Expand Up @@ -20,7 +20,6 @@
"link-parent-bin": "~0.2.0",
"load-grunt-tasks": "~4.0.0",
"mocha": "~5.2.0",
"mz": "~2.7.0",
"ts-node": "~7.0.0",
"typescript": "~2.9.2",
"webpack": "~4.16.0"
Expand All @@ -41,6 +40,7 @@
"stryker-karma-runner": "../packages/stryker-karma-runner",
"stryker-mocha-framework": "../packages/stryker-mocha-framework",
"stryker-mocha-runner": "../packages/stryker-mocha-runner",
"@stryker-mutator/util": "../packages/stryker-util",
"stryker-typescript": "../packages/stryker-typescript",
"stryker-vue-mutator": "../packages/stryker-vue-mutator",
"stryker-webpack-transpiler": "../packages/stryker-webpack-transpiler"
Expand Down
6 changes: 0 additions & 6 deletions integrationTest/test/angular-project/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions integrationTest/test/angular-project/package.json
Expand Up @@ -34,7 +34,6 @@
"@angular/language-service": "^6.0.3",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
Expand All @@ -51,6 +50,7 @@
"localDependencies": {
"stryker": "../../../packages/stryker",
"stryker-karma-runner": "../../../packages/stryker-karma-runner",
"stryker-typescript": "../../../packages/stryker-typescript"
"stryker-typescript": "../../../packages/stryker-typescript",
"@stryker-mutator/util": "../../../packages/stryker-util"
}
}
6 changes: 3 additions & 3 deletions integrationTest/test/angular-project/verify/verify.ts
@@ -1,15 +1,15 @@
import * as fs from 'mz/fs';
import { fsAsPromised } from '@stryker-mutator/util';
import { expect } from 'chai';
import * as path from 'path';
import { ScoreResult } from 'stryker-api/report';

describe('After running stryker on angular project', () => {
it('should report 15% mutation score', async () => {
const eventsDir = path.resolve(__dirname, '..', 'reports', 'mutation', 'events');
const allReportFiles = await fs.readdir(eventsDir);
const allReportFiles = await fsAsPromised.readdir(eventsDir);
const scoreResultReportFile = allReportFiles.find(file => !!file.match(/.*onScoreCalculated.*/));
expect(scoreResultReportFile).ok;
const scoreResultContent = await fs.readFile(path.resolve(eventsDir, scoreResultReportFile || ''), 'utf8');
const scoreResultContent = await fsAsPromised.readFile(path.resolve(eventsDir, scoreResultReportFile || ''), 'utf8');
const scoreResult = JSON.parse(scoreResultContent) as ScoreResult;
expect(scoreResult.killed).eq(2);
expect(scoreResult.survived).eq(11);
Expand Down
4 changes: 2 additions & 2 deletions integrationTest/test/babel-transpiling/verify/verify.ts
@@ -1,9 +1,9 @@
import * as chai from 'chai';
import * as fs from 'mz/fs';
import { fsAsPromised } from '@stryker-mutator/util';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);
const expect = chai.expect;
const expectFileExists = (path: string) => expect(fs.exists(path), `File ${path} does not exist`).to.eventually.eq(true);
const expectFileExists = (path: string) => expect(fsAsPromised.exists(path), `File ${path} does not exist`).to.eventually.eq(true);

describe('Verify stryker has ran correctly', () => {

Expand Down
4 changes: 2 additions & 2 deletions integrationTest/test/command/verify/verify.ts
@@ -1,4 +1,4 @@
import * as fs from 'mz/fs';
import { fsAsPromised } from '@stryker-mutator/util';
import { expect } from 'chai';
import * as path from 'path';
import { readScoreResult } from '../../../helpers';
Expand All @@ -12,7 +12,7 @@ describe('After running stryker with the command test runner', () => {
});

it('should write to a log file', async () => {
const strykerLog = await fs.readFile('./stryker.log', 'utf8');
const strykerLog = await fsAsPromised.readFile('./stryker.log', 'utf8');
expect(strykerLog).contains('INFO InitialTestExecutor Initial test run succeeded. Ran 1 test');
expect(strykerLog).matches(/Stryker Done in \d+/);
expect(strykerLog).not.contains('ERROR');
Expand Down
2 changes: 1 addition & 1 deletion integrationTest/test/jasmine-jasmine/package.json
Expand Up @@ -5,7 +5,7 @@
"description": "A module to perform an integration test",
"main": "index.js",
"scripts": {
"pretest": "rimraf \"reports\" \"verify/*.map\" \"stryker.log\"",
"pretest": "rimraf \"reports\" \"stryker.log\"",
"test": "stryker run",
"posttest": "mocha --require ts-node/register verify/*.ts"
},
Expand Down
4 changes: 2 additions & 2 deletions integrationTest/test/jasmine-jasmine/verify/verify.ts
@@ -1,4 +1,4 @@
import * as fs from 'mz/fs';
import { fsAsPromised } from '@stryker-mutator/util';
import { expect } from 'chai';
import { readScoreResult } from '../../../helpers';

Expand All @@ -11,7 +11,7 @@ describe('After running stryker with test runner jasmine, test framework jasmine
});

it('should write to a log file', async () => {
const strykerLog = await fs.readFile('./stryker.log', 'utf8');
const strykerLog = await fsAsPromised.readFile('./stryker.log', 'utf8');
expect(strykerLog).contains('INFO InputFileResolver Found 2 of 10 file(s) to be mutated');
expect(strykerLog).matches(/Stryker Done in \d+/);
// TODO, we now have an error because of a memory leak: https://github.com/jasmine/jasmine-npm/issues/134
Expand Down
3 changes: 2 additions & 1 deletion integrationTest/test/jest-react/package.json
Expand Up @@ -16,6 +16,7 @@
"localDependencies": {
"stryker": "../../../packages/stryker",
"stryker-javascript-mutator": "../../../packages/stryker-javascript-mutator",
"stryker-jest-runner": "../../../packages/stryker-jest-runner"
"stryker-jest-runner": "../../../packages/stryker-jest-runner",
"@stryker-mutator/util": "../../../packages/stryker-util"
}
}
6 changes: 3 additions & 3 deletions integrationTest/test/jest-react/verify/verify.ts
@@ -1,15 +1,15 @@
import * as fs from 'mz/fs';
import { fsAsPromised } from '@stryker-mutator/util';
import { expect } from 'chai';
import * as path from 'path';
import { ScoreResult } from 'stryker-api/report';

describe('After running stryker on angular project', () => {
it('should report 50% mutation score', async () => {
const eventsDir = path.resolve(__dirname, '..', 'reports', 'mutation', 'events');
const allReportFiles = await fs.readdir(eventsDir);
const allReportFiles = await fsAsPromised.readdir(eventsDir);
const scoreResultReportFile = allReportFiles.find(file => !!file.match(/.*onScoreCalculated.*/));
expect(scoreResultReportFile).ok;
const scoreResultContent = await fs.readFile(path.resolve(eventsDir, scoreResultReportFile || ''), 'utf8');
const scoreResultContent = await fsAsPromised.readFile(path.resolve(eventsDir, scoreResultReportFile || ''), 'utf8');
const scoreResult = JSON.parse(scoreResultContent) as ScoreResult;
expect(scoreResult.killed).eq(1);
expect(scoreResult.survived).eq(1);
Expand Down
4 changes: 2 additions & 2 deletions integrationTest/test/karma-jasmine/package.json
Expand Up @@ -5,9 +5,9 @@
"description": "A module to perform an integration test",
"main": "index.js",
"scripts": {
"pretest": "rimraf \"reports\" \"verify/*.js\" \"verify/*.map\" && tsc -p .",
"pretest": "rimraf \"reports\"",
"test": "stryker run stryker.conf.js",
"posttest": "mocha verify/*.js"
"posttest": "mocha --require ts-node/register verify/*.ts"
},
"author": "",
"license": "ISC"
Expand Down
4 changes: 2 additions & 2 deletions integrationTest/test/karma-jasmine/verify/verify.ts
@@ -1,9 +1,9 @@
import * as chai from 'chai';
import * as fs from 'mz/fs';
import { fsAsPromised } from '@stryker-mutator/util';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);
const expect = chai.expect;
const expectFileExists = (path: string) => expect(fs.exists(path), `File ${path} does not exist`).to.eventually.eq(true);
const expectFileExists = (path: string) => expect(fsAsPromised.exists(path), `File ${path} does not exist`).to.eventually.eq(true);

describe('Verify stryker has ran correctly', () => {

Expand Down
4 changes: 2 additions & 2 deletions integrationTest/test/karma-mocha/package.json
Expand Up @@ -5,9 +5,9 @@
"description": "A module to perform an integration test",
"main": "index.js",
"scripts": {
"pretest": "rimraf \"reports\" \"verify/*.js\" \"verify/*.map\" && tsc -p .",
"pretest": "rimraf \"reports\"",
"test": "stryker run stryker.conf.js",
"posttest": "mocha verify/*.js"
"posttest": "mocha --require ts-node/register verify/*.ts"
},
"author": "",
"license": "ISC"
Expand Down
4 changes: 2 additions & 2 deletions integrationTest/test/karma-mocha/verify/verify.ts
@@ -1,9 +1,9 @@
import * as chai from 'chai';
import * as fs from 'mz/fs';
import { fsAsPromised } from '@stryker-mutator/util';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);
const expect = chai.expect;
const expectFileExists = (path: string) => expect(fs.exists(path), `File ${path} does not exist`).to.eventually.eq(true);
const expectFileExists = (path: string) => expect(fsAsPromised.exists(path), `File ${path} does not exist`).to.eventually.eq(true);

describe('Verify stryker has ran correctly', () => {

Expand Down
4 changes: 2 additions & 2 deletions integrationTest/test/mocha-mocha/verify/verify.ts
@@ -1,9 +1,9 @@
import * as chai from 'chai';
import * as fs from 'mz/fs';
import { fsAsPromised } from '@stryker-mutator/util';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);
const expect = chai.expect;
const expectFileExists = (path: string) => expect(fs.exists(path), `File ${path} does not exist`).to.eventually.eq(true);
const expectFileExists = (path: string) => expect(fsAsPromised.exists(path), `File ${path} does not exist`).to.eventually.eq(true);

describe('Verify stryker has ran correctly', () => {

Expand Down
4 changes: 2 additions & 2 deletions integrationTest/test/typescript-transpiling/verify/verify.ts
@@ -1,9 +1,9 @@
import * as chai from 'chai';
import * as fs from 'mz/fs';
import { fsAsPromised } from '@stryker-mutator/util';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);
const expect = chai.expect;
const expectFileExists = (path: string) => expect(fs.exists(path), `File ${path} does not exist`).to.eventually.eq(true);
const expectFileExists = (path: string) => expect(fsAsPromised.exists(path), `File ${path} does not exist`).to.eventually.eq(true);

describe('Verify stryker has ran correctly', () => {

Expand Down
Expand Up @@ -3,7 +3,6 @@
"version": "0.0.0",
"private": true,
"scripts": {
"pretest": "tsc -p .",
"test": "node usingStryker.js"
"test": "node --require ts-node/register usingStryker.ts"
}
}

This file was deleted.

7 changes: 4 additions & 3 deletions integrationTest/test/vue-javascript/package.json
Expand Up @@ -9,9 +9,9 @@
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
"start": "npm run dev",
"unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run",
"pretest": "rimraf \"reports\" \"verify/*.js\" \"verify/*.map\" && tsc -p .",
"pretest": "rimraf \"reports\"",
"test": "stryker run stryker.conf.js",
"posttest": "mocha verify/*.js",
"posttest": "mocha --require ts-node/register verify/*.ts",
"lint": "eslint --ext .js,.vue src test/unit",
"build": "node build/build.js"
},
Expand Down Expand Up @@ -85,9 +85,10 @@
},
"localDependencies": {
"stryker": "../../../packages/stryker",
"stryker-javascript-mutator": "../../../packages/stryker-javascript-mutator",
"stryker-karma-runner": "../../../packages/stryker-karma-runner",
"stryker-vue-mutator": "../../../packages/stryker-vue-mutator",
"stryker-javascript-mutator": "../../../packages/stryker-javascript-mutator"
"@stryker-mutator/util": "../../../packages/stryker-util"
},
"engines": {
"node": ">= 6.0.0",
Expand Down
6 changes: 3 additions & 3 deletions integrationTest/test/vue-javascript/verify/verify.ts
@@ -1,15 +1,15 @@
import * as fs from 'mz/fs';
import { fsAsPromised } from '@stryker-mutator/util';
import { expect } from 'chai';
import * as path from 'path';
import { ScoreResult } from 'stryker-api/report';

describe('After running stryker on VueJS project', () => {
it('should report 25% mutation score', async () => {
const eventsDir = path.resolve(__dirname, '..', 'reports', 'mutation', 'events');
const allReportFiles = await fs.readdir(eventsDir);
const allReportFiles = await fsAsPromised.readdir(eventsDir);
const scoreResultReportFile = allReportFiles.find(file => !!file.match(/.*onScoreCalculated.*/));
expect(scoreResultReportFile).ok;
const scoreResultContent = await fs.readFile(path.resolve(eventsDir, scoreResultReportFile || ''), 'utf8');
const scoreResultContent = await fsAsPromised.readFile(path.resolve(eventsDir, scoreResultReportFile || ''), 'utf8');
const scoreResult = JSON.parse(scoreResultContent) as ScoreResult;
expect(scoreResult.killed).eq(4);
expect(scoreResult.survived).eq(12);
Expand Down
8 changes: 4 additions & 4 deletions integrationTest/test/webpack-zero-conf-karma/verify/verify.ts
@@ -1,9 +1,9 @@
import * as chai from 'chai';
import * as fs from 'mz/fs';
import { fsAsPromised } from '@stryker-mutator/util';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);
const expect = chai.expect;
const expectFileExists = (path: string) => expect(fs.exists(path), `File ${path} does not exist`).to.eventually.eq(true);
const expectFileExists = (path: string) => expect(fsAsPromised.exists(path), `File ${path} does not exist`).to.eventually.eq(true);
function expectMutationScore(score: string, annotation: string, actualContent: string) {
const isMatch = new RegExp(`<th\\s+class="[^"]* text-${annotation}"[^>]*>${score}<\\/th>`, 'g').test(actualContent);
expect(isMatch, `Mutation score ${score} with annotation ${annotation} not found in ${actualContent}`).is.ok;
Expand All @@ -15,8 +15,8 @@ describe('Verify stryker has ran correctly', () => {
expectFileExists('reports/mutation/html/index.html'),
]);
});
it('should contain the correct mutation score', () => {
const indexContent = fs.readFileSync('reports/mutation/html/index.html', 'utf8');
it('should contain the correct mutation score', async () => {
const indexContent = await fsAsPromised.readFile('reports/mutation/html/index.html', 'utf8');
expectMutationScore('33.33', 'danger', indexContent);
});
});
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -14,8 +14,6 @@
"@types/lodash": "^4.14.110",
"@types/mkdirp": "^0.5.2",
"@types/mocha": "^2.2.44",
"@types/mz": "0.0.32",
"@types/node": "^6.0.114",
"@types/rimraf": "2.0.2",
"@types/sinon": "^5.0.1",
"@types/sinon-chai": "^3.2.0",
Expand Down Expand Up @@ -54,5 +52,8 @@
"engines": {
"node": ">=6",
"npm": ">=5"
},
"dependencies": {
"@types/node": "^10.11.5"
}
}
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { exec } from 'mz/child_process';
import { exec } from 'child_process';
import * as path from 'path';

describe('we have a module using stryker', function() {
Expand Down
16 changes: 14 additions & 2 deletions packages/stryker-babel-transpiler/test/helpers/projectLoader.ts
@@ -1,10 +1,22 @@
import * as fs from 'mz/fs';
import * as fs from 'fs';
import * as path from 'path';
import { File } from 'stryker-api/core';
import * as glob from 'glob';

const CARRIAGE_RETURN = '\r'.charCodeAt(0);

function readFile(fileName: string) {
return new Promise<Buffer>((res, rej) => {
fs.readFile(fileName, (err, result) => {
if (err) {
rej(err);
} else {
res(result);
}
});
});
}

export class ProjectLoader {

public static getFiles(basePath: string) {
Expand All @@ -16,7 +28,7 @@ export class ProjectLoader {
return this.glob(basePath)
.then(fileNames => fileNames.map(fileName => path.join(basePath, fileName)))
.then(fileNames => Promise.all(fileNames.map(fileName =>
fs.readFile(fileName).then(content => new File(fileName, this.normalize(content))))));
readFile(fileName).then(content => new File(fileName, this.normalize(content))))));
}

private static normalize(content: Buffer) {
Expand Down
3 changes: 2 additions & 1 deletion packages/stryker-html-reporter/package.json
Expand Up @@ -41,15 +41,16 @@
"mkdirp": "~0.5.1",
"mz": "~2.7.0",
"rimraf": "~2.6.1",
"@stryker-mutator/util": "~0.0.0",
"typed-html": "~0.6.0"
},
"peerDependencies": {
"stryker-api": ">=0.18.0 <0.22.0"
},
"devDependencies": {
"@types/file-url": "~2.0.0",
"@types/node": "^10.11.5",
"@types/jsdom": "~12.2.0",
"@types/node": "~6.14.0",
"bootstrap": "4.1.3",
"highlight.js": "~9.13.0",
"jquery": "~3.3.1",
Expand Down

0 comments on commit 1d3e2f6

Please sign in to comment.