diff --git a/integrationTest/helpers.ts b/integrationTest/helpers.ts index 5e653ea222..417cf63bef 100644 --- a/integrationTest/helpers.ts +++ b/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; } diff --git a/integrationTest/package.json b/integrationTest/package.json index 96a036979d..1115bfc08d 100644 --- a/integrationTest/package.json +++ b/integrationTest/package.json @@ -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" @@ -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" diff --git a/integrationTest/test/angular-project/package-lock.json b/integrationTest/test/angular-project/package-lock.json index ebbe84f822..5c88b6e738 100644 --- a/integrationTest/test/angular-project/package-lock.json +++ b/integrationTest/test/angular-project/package-lock.json @@ -431,12 +431,6 @@ "@types/jasmine": "*" } }, - "@types/node": { - "version": "8.9.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-8.9.5.tgz", - "integrity": "sha512-jRHfWsvyMtXdbhnz5CVHxaBgnV6duZnPlQuRSo/dm/GnmikNcmZhxIES4E9OZjUmQ8C+HCl4KJux+cXN/ErGDQ==", - "dev": true - }, "@types/q": { "version": "0.0.32", "resolved": "https://registry.npmjs.org/@types/q/-/q-0.0.32.tgz", diff --git a/integrationTest/test/angular-project/package.json b/integrationTest/test/angular-project/package.json index 06c146281b..3969dec97c 100644 --- a/integrationTest/test/angular-project/package.json +++ b/integrationTest/test/angular-project/package.json @@ -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", @@ -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" } } diff --git a/integrationTest/test/angular-project/verify/verify.ts b/integrationTest/test/angular-project/verify/verify.ts index 0ade81dc18..f522d0a181 100644 --- a/integrationTest/test/angular-project/verify/verify.ts +++ b/integrationTest/test/angular-project/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 { ScoreResult } from 'stryker-api/report'; @@ -6,10 +6,10 @@ 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); diff --git a/integrationTest/test/babel-transpiling/verify/verify.ts b/integrationTest/test/babel-transpiling/verify/verify.ts index 59d5c652d6..60cd78a858 100644 --- a/integrationTest/test/babel-transpiling/verify/verify.ts +++ b/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', () => { diff --git a/integrationTest/test/command/verify/verify.ts b/integrationTest/test/command/verify/verify.ts index ce549d4c0e..52198a635f 100644 --- a/integrationTest/test/command/verify/verify.ts +++ b/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'; @@ -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'); diff --git a/integrationTest/test/jasmine-jasmine/package.json b/integrationTest/test/jasmine-jasmine/package.json index 80274018cb..8e8ea435ac 100644 --- a/integrationTest/test/jasmine-jasmine/package.json +++ b/integrationTest/test/jasmine-jasmine/package.json @@ -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" }, diff --git a/integrationTest/test/jasmine-jasmine/verify/verify.ts b/integrationTest/test/jasmine-jasmine/verify/verify.ts index 17ab17045f..fae5682036 100644 --- a/integrationTest/test/jasmine-jasmine/verify/verify.ts +++ b/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'; @@ -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 diff --git a/integrationTest/test/jest-react/package.json b/integrationTest/test/jest-react/package.json index e493ecc36d..72d1c5568a 100644 --- a/integrationTest/test/jest-react/package.json +++ b/integrationTest/test/jest-react/package.json @@ -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" } } diff --git a/integrationTest/test/jest-react/verify/verify.ts b/integrationTest/test/jest-react/verify/verify.ts index a944fa5e93..ed977e2782 100644 --- a/integrationTest/test/jest-react/verify/verify.ts +++ b/integrationTest/test/jest-react/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 { ScoreResult } from 'stryker-api/report'; @@ -6,10 +6,10 @@ 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); diff --git a/integrationTest/test/karma-jasmine/package.json b/integrationTest/test/karma-jasmine/package.json index 8858ef5880..df581d57d0 100644 --- a/integrationTest/test/karma-jasmine/package.json +++ b/integrationTest/test/karma-jasmine/package.json @@ -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" diff --git a/integrationTest/test/karma-jasmine/verify/verify.ts b/integrationTest/test/karma-jasmine/verify/verify.ts index e5d7ec2736..db23c197e4 100644 --- a/integrationTest/test/karma-jasmine/verify/verify.ts +++ b/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', () => { diff --git a/integrationTest/test/karma-mocha/package.json b/integrationTest/test/karma-mocha/package.json index 8858ef5880..df581d57d0 100644 --- a/integrationTest/test/karma-mocha/package.json +++ b/integrationTest/test/karma-mocha/package.json @@ -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" diff --git a/integrationTest/test/karma-mocha/verify/verify.ts b/integrationTest/test/karma-mocha/verify/verify.ts index e5d7ec2736..db23c197e4 100644 --- a/integrationTest/test/karma-mocha/verify/verify.ts +++ b/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', () => { diff --git a/integrationTest/test/mocha-mocha/verify/verify.ts b/integrationTest/test/mocha-mocha/verify/verify.ts index 7ebf5b8d13..a04c8d8e80 100644 --- a/integrationTest/test/mocha-mocha/verify/verify.ts +++ b/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', () => { diff --git a/integrationTest/test/typescript-transpiling/verify/verify.ts b/integrationTest/test/typescript-transpiling/verify/verify.ts index 535566ed53..50263090b2 100644 --- a/integrationTest/test/typescript-transpiling/verify/verify.ts +++ b/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', () => { diff --git a/integrationTest/test/use-stryker-programmatically/package.json b/integrationTest/test/use-stryker-programmatically/package.json index d1f559857d..a066fec057 100644 --- a/integrationTest/test/use-stryker-programmatically/package.json +++ b/integrationTest/test/use-stryker-programmatically/package.json @@ -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" } } diff --git a/integrationTest/test/use-stryker-programmatically/usingStryker.js b/integrationTest/test/use-stryker-programmatically/usingStryker.js deleted file mode 100644 index a8d3dfffbc..0000000000 --- a/integrationTest/test/use-stryker-programmatically/usingStryker.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var stryker_1 = require("stryker"); -new stryker_1.default({ - testRunner: 'mocha', - mutate: [], - coverageAnalysis: 'off', - files: [] -}).runMutationTest().then(function () { return console.log('done'); }); diff --git a/integrationTest/test/vue-javascript/package.json b/integrationTest/test/vue-javascript/package.json index 7d3352640e..85f3d49152 100644 --- a/integrationTest/test/vue-javascript/package.json +++ b/integrationTest/test/vue-javascript/package.json @@ -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" }, @@ -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", diff --git a/integrationTest/test/vue-javascript/verify/verify.ts b/integrationTest/test/vue-javascript/verify/verify.ts index 6b835c4e87..606dfef323 100644 --- a/integrationTest/test/vue-javascript/verify/verify.ts +++ b/integrationTest/test/vue-javascript/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 { ScoreResult } from 'stryker-api/report'; @@ -6,10 +6,10 @@ 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); diff --git a/integrationTest/test/webpack-zero-conf-karma/verify/verify.ts b/integrationTest/test/webpack-zero-conf-karma/verify/verify.ts index 225bccd5ff..95b55f572c 100644 --- a/integrationTest/test/webpack-zero-conf-karma/verify/verify.ts +++ b/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(`]*>${score}<\\/th>`, 'g').test(actualContent); expect(isMatch, `Mutation score ${score} with annotation ${annotation} not found in ${actualContent}`).is.ok; @@ -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); }); }); diff --git a/package.json b/package.json index e89ec819fb..5ef3973e02 100644 --- a/package.json +++ b/package.json @@ -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", @@ -54,5 +52,8 @@ "engines": { "node": ">=6", "npm": ">=5" + }, + "dependencies": { + "@types/node": "^10.11.5" } } diff --git a/packages/stryker-api/test/integration/install-module/install-module.ts b/packages/stryker-api/test/integration/install-module/install-module.ts index 4659b4169a..97285f9ad8 100644 --- a/packages/stryker-api/test/integration/install-module/install-module.ts +++ b/packages/stryker-api/test/integration/install-module/install-module.ts @@ -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() { diff --git a/packages/stryker-babel-transpiler/test/helpers/projectLoader.ts b/packages/stryker-babel-transpiler/test/helpers/projectLoader.ts index 67f8bf9d67..1aba524ccc 100644 --- a/packages/stryker-babel-transpiler/test/helpers/projectLoader.ts +++ b/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((res, rej) => { + fs.readFile(fileName, (err, result) => { + if (err) { + rej(err); + } else { + res(result); + } + }); + }); +} + export class ProjectLoader { public static getFiles(basePath: string) { @@ -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) { diff --git a/packages/stryker-html-reporter/package.json b/packages/stryker-html-reporter/package.json index ac03b1985b..a909836a70 100644 --- a/packages/stryker-html-reporter/package.json +++ b/packages/stryker-html-reporter/package.json @@ -41,6 +41,7 @@ "mkdirp": "~0.5.1", "mz": "~2.7.0", "rimraf": "~2.6.1", + "@stryker-mutator/util": "~0.0.0", "typed-html": "~0.6.0" }, "peerDependencies": { @@ -48,8 +49,8 @@ }, "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", diff --git a/packages/stryker-html-reporter/src/util.ts b/packages/stryker-html-reporter/src/util.ts index 948c581800..e0c46ee64a 100644 --- a/packages/stryker-html-reporter/src/util.ts +++ b/packages/stryker-html-reporter/src/util.ts @@ -1,29 +1,29 @@ -import * as fs from 'mz/fs'; +import { fsAsPromised } from '@stryker-mutator/util'; import * as path from 'path'; import * as mkdirp from 'mkdirp'; import * as rimraf from 'rimraf'; -function copyFolderOrFile(fromPath: string, toPath: string): Promise { - return fs.stat(fromPath).then(stats => { - if (stats.isDirectory()) { - return copyFolder(fromPath, toPath); - } else { - return copyFile(fromPath, toPath); - } - }); +async function copyFolderOrFile(fromPath: string, toPath: string): Promise { + const stats = await fsAsPromised.stat(fromPath); + if (stats.isDirectory()) { + return copyFolder(fromPath, toPath); + } + else { + return copyFile(fromPath, toPath); + } } export function copyFolder(fromPath: string, to: string): Promise { return mkdir(to) - .then(() => fs.readdir(fromPath)) + .then(() => fsAsPromised.readdir(fromPath)) .then(files => Promise.all(files.map(file => copyFolderOrFile(path.join(fromPath, file), path.join(to, file))))) .then(_ => void 0); } function copyFile(fromFilename: string, toFilename: string): Promise { return new Promise((resolve, reject) => { - const readStream = fs.createReadStream(fromFilename); - const writeStream = fs.createWriteStream(toFilename); + const readStream = fsAsPromised.createReadStream(fromFilename); + const writeStream = fsAsPromised.createWriteStream(toFilename); readStream.on('error', reject); writeStream.on('error', reject); readStream.pipe(writeStream); @@ -57,7 +57,7 @@ export function mkdir(folderName: string): Promise { export function writeFile(fileName: string, content: string) { return mkdir(path.dirname(fileName)) - .then(_ => fs.writeFile(fileName, content, 'utf8')); + .then(_ => fsAsPromised.writeFile(fileName, content, 'utf8')); } export function countPathSep(fileName: string) { diff --git a/packages/stryker-html-reporter/tasks/clientResources.js b/packages/stryker-html-reporter/tasks/clientResources.js index a4e2e48b11..9c6980b517 100644 --- a/packages/stryker-html-reporter/tasks/clientResources.js +++ b/packages/stryker-html-reporter/tasks/clientResources.js @@ -1,7 +1,7 @@ const path = require('path'); const glob = require('glob'); const mkdirp = require('mkdirp'); -const fs = require('mz/fs'); +const fs = require('fs'); const rimraf = require('rimraf'); const callbackAsPromised = (res, rej) => (err, result) => { diff --git a/packages/stryker-html-reporter/test/helpers/EventPlayer.ts b/packages/stryker-html-reporter/test/helpers/EventPlayer.ts index c571952265..0af7a9f3fe 100644 --- a/packages/stryker-html-reporter/test/helpers/EventPlayer.ts +++ b/packages/stryker-html-reporter/test/helpers/EventPlayer.ts @@ -1,6 +1,6 @@ import * as path from 'path'; import { Reporter } from 'stryker-api/report'; -import * as fs from 'mz/fs'; +import { fsAsPromised } from '@stryker-mutator/util'; const eventName = (filename: string) => filename.substring(filename.indexOf('-') + 1, filename.indexOf('.')); @@ -9,9 +9,9 @@ export default class EventPlayer { constructor(private readonly fromDirectory: string) { } public replay(target: Reporter) { - const files = fs.readdirSync(this.fromDirectory).sort(); + const files = fsAsPromised.readdirSync(this.fromDirectory).sort(); return Promise.all(files.map( - filename => fs.readFile(path.join(this.fromDirectory, filename), 'utf8').then(content => ({ + filename => fsAsPromised.readFile(path.join(this.fromDirectory, filename), 'utf8').then(content => ({ content: JSON.parse(this.replacePathSeparator(content)), name: eventName(filename) })) diff --git a/packages/stryker-html-reporter/test/helpers/fsHelpers.ts b/packages/stryker-html-reporter/test/helpers/fsHelpers.ts index f8a4bdc51c..9ba734854d 100644 --- a/packages/stryker-html-reporter/test/helpers/fsHelpers.ts +++ b/packages/stryker-html-reporter/test/helpers/fsHelpers.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import { fs } from 'mz'; +import * as fs from 'fs'; type File = string | Directory; diff --git a/packages/stryker-html-reporter/test/integration/singleFileInFolderSpec.ts b/packages/stryker-html-reporter/test/integration/singleFileInFolderSpec.ts index babba3e3b4..4d3d8fd9cd 100644 --- a/packages/stryker-html-reporter/test/integration/singleFileInFolderSpec.ts +++ b/packages/stryker-html-reporter/test/integration/singleFileInFolderSpec.ts @@ -4,7 +4,7 @@ import { Config } from 'stryker-api/config'; import EventPlayer from '../helpers/EventPlayer'; import HtmlReporter from '../../src/HtmlReporter'; import { readDirectoryTree } from '../helpers/fsHelpers'; -import { fs } from 'mz'; +import * as fs from 'fs'; const REPORT_DIR = 'reports/mutation/singleFileInFolder'; diff --git a/packages/stryker-jest-runner/testResources/reactTsProject/package.json b/packages/stryker-jest-runner/testResources/reactTsProject/package.json index 27d2dff977..d32f82df9c 100644 --- a/packages/stryker-jest-runner/testResources/reactTsProject/package.json +++ b/packages/stryker-jest-runner/testResources/reactTsProject/package.json @@ -15,7 +15,6 @@ }, "devDependencies": { "@types/jest": "^22.2.3", - "@types/node": "^9.6.4", "@types/react": "^16.3.9", "@types/react-dom": "^16.0.5", "typescript": "^2.8.1" diff --git a/packages/stryker-typescript/test/unit/TypescriptMutatorSpec.ts b/packages/stryker-typescript/test/unit/TypescriptMutatorSpec.ts index e4636c65dc..4a391a9e8b 100644 --- a/packages/stryker-typescript/test/unit/TypescriptMutatorSpec.ts +++ b/packages/stryker-typescript/test/unit/TypescriptMutatorSpec.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import * as fs from 'mz/fs'; +import * as fs from 'fs'; import { expect } from 'chai'; import * as ts from 'typescript'; import { Config } from 'stryker-api/config'; diff --git a/packages/stryker-util/.vscode/launch.json b/packages/stryker-util/.vscode/launch.json new file mode 100644 index 0000000000..a949b9d86f --- /dev/null +++ b/packages/stryker-util/.vscode/launch.json @@ -0,0 +1,48 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Unit tests", + "program": "${workspaceFolder}/../../node_modules/mocha/bin/_mocha", + "args": [ + "-u", + "tdd", + "--timeout", + "999999", + "--colors", + "${workspaceFolder}/test/helpers/**/*.js", + "${workspaceFolder}/test/unit/**/*.js" + ], + "internalConsoleOptions": "openOnSessionStart", + "outFiles": [ + "${workspaceRoot}/test/**/*.js", + "${workspaceRoot}/src/**/*.js" + ] + }, + { + "type": "node", + "request": "launch", + "name": "Integration tests", + "program": "${workspaceFolder}/../../node_modules/mocha/bin/_mocha", + "args": [ + "-u", + "tdd", + "--timeout", + "999999", + "--colors", + "${workspaceFolder}/test/helpers/**/*.js", + "${workspaceFolder}/test/integration/**/*.js" + ], + "internalConsoleOptions": "openOnSessionStart", + "outFiles": [ + "${workspaceRoot}/test/**/*.js", + "${workspaceRoot}/src/**/*.js" + ] + } + ] +} \ No newline at end of file diff --git a/packages/stryker-util/.vscode/settings.json b/packages/stryker-util/.vscode/settings.json new file mode 100644 index 0000000000..75776c1ebe --- /dev/null +++ b/packages/stryker-util/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "files.exclude": { + ".git": true, + ".tscache": true, + "**/*.js": { + "when": "$(basename).ts" + }, + "**/*.d.ts": true, + "**/*.map": { + "when": "$(basename)" + } + } +} \ No newline at end of file diff --git a/packages/stryker-util/.vscode/tasks.json b/packages/stryker-util/.vscode/tasks.json new file mode 100644 index 0000000000..9b8051bdab --- /dev/null +++ b/packages/stryker-util/.vscode/tasks.json @@ -0,0 +1,18 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "tsc-watch", + "type": "shell", + "command": "npm start", + "problemMatcher": "$tsc-watch", + "isBackground": true, + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/packages/stryker-util/README.md b/packages/stryker-util/README.md new file mode 100644 index 0000000000..2944b2e6af --- /dev/null +++ b/packages/stryker-util/README.md @@ -0,0 +1,10 @@ +[![Build Status](https://travis-ci.org/stryker-mutator/stryker.svg?branch=master)](https://travis-ci.org/stryker-mutator/stryker) +[![NPM](https://img.shields.io/npm/dm/stryker-utils.svg)](https://www.npmjs.com/package/stryker-utils) +[![Node version](https://img.shields.io/node/v/stryker-utils.svg)](https://img.shields.io/node/v/stryker-utils.svg) +[![Gitter](https://badges.gitter.im/stryker-mutator/stryker.svg)](https://gitter.im/stryker-mutator/stryker?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) + +![Stryker](https://github.com/stryker-mutator/stryker/raw/master/stryker-80x80.png) + +# Stryker Util + +Utility functions for Stryker plugins and/or core packages. diff --git a/packages/stryker-util/package.json b/packages/stryker-util/package.json new file mode 100644 index 0000000000..1e43a28f56 --- /dev/null +++ b/packages/stryker-util/package.json @@ -0,0 +1,29 @@ +{ + "name": "@stryker-mutator/util", + "version": "0.0.0", + "description": "Contains utilities for Stryker, the mutation testing framework for JavaScript and friends", + "main": "src/index.js", + "typings": "src/index.d.ts", + "scripts": { + "start": "tsc -w", + "clean": "rimraf \"+(test|src)/**/*+(.d.ts|.js|.map)\" reports", + "prebuild": "npm run clean", + "build": "tsc -p .", + "postbuild": "tslint -p tsconfig.json", + "test": "nyc --check-coverage --reporter=html --report-dir=reports/coverage --lines 90 --functions 95 --branches 75 mocha \"test/helpers/**/*.js\" \"test/unit/**/*.js\" \"test/integration/**/*.js\"" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/stryker-mutator/stryker.git" + }, + "keywords": [ + "stryker", + "utils" + ], + "author": "Nico Jansen ", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/stryker-mutator/stryker/issues" + }, + "homepage": "https://github.com/stryker-mutator/stryker/tree/master/packages/@stryker-mutator/util#readme" +} diff --git a/packages/stryker-util/src/childProcessAsPromised.ts b/packages/stryker-util/src/childProcessAsPromised.ts new file mode 100644 index 0000000000..bb7022a137 --- /dev/null +++ b/packages/stryker-util/src/childProcessAsPromised.ts @@ -0,0 +1,6 @@ +import * as childProcess from 'child_process'; +import promisify from './promisify'; + +export default { + exec: promisify(childProcess.exec) +}; diff --git a/packages/stryker-util/src/fsAsPromised.ts b/packages/stryker-util/src/fsAsPromised.ts new file mode 100644 index 0000000000..644c83d866 --- /dev/null +++ b/packages/stryker-util/src/fsAsPromised.ts @@ -0,0 +1,21 @@ +import * as fs from 'fs'; +import promisify from './promisify'; + +/** + * This file contains an implementation of fs.promises + * Note: Can be removed once we drop support for node 8 (and 9). + */ + +export default { + createReadStream: fs.createReadStream, + createWriteStream: fs.createWriteStream, + exists: promisify(fs.exists), + existsSync: fs.existsSync, + lstat: promisify(fs.lstat), + readdir: promisify(fs.readdir), + readdirSync: fs.readdirSync, + readFile: promisify(fs.readFile), + stat: promisify(fs.stat), + symlink: promisify(fs.symlink), + writeFile: promisify(fs.writeFile), +}; diff --git a/packages/stryker-util/src/index.ts b/packages/stryker-util/src/index.ts new file mode 100644 index 0000000000..52dd2b3016 --- /dev/null +++ b/packages/stryker-util/src/index.ts @@ -0,0 +1,3 @@ +export { default as fsAsPromised } from './fsAsPromised'; +export { default as childProcessAsPromised } from './childProcessAsPromised'; +export { default as promisify } from './promisify'; diff --git a/packages/stryker-util/src/promisify.ts b/packages/stryker-util/src/promisify.ts new file mode 100644 index 0000000000..ee346cc10b --- /dev/null +++ b/packages/stryker-util/src/promisify.ts @@ -0,0 +1,45 @@ +import { exec } from 'child_process'; +import { exists } from 'fs'; +import * as util from 'util'; + +/** + * This file contains an implementation of util.promisify (available on node >= 8) + * Note: Can be removed once we drop support for node 6 (and 7). + */ +function promisify(original: any) { + if ('promisify' in util) { + return util.promisify(original); // let nodejs do it's thing thing, if it is supported + } else { + return innerPromisify(original); // Do it ourselves + } +} + +// This function is exported so that it can be tested on node >= 8 +export function innerPromisify(original: any) { + return function fn(...args: any[]) { + return new Promise((resolve, reject) => { + original.call(this, ...args, (err: Error, ...values: any[]) => { + if (original === exists) { + // the exists callback is NOT consistent with NodeJS callbacks: https://nodejs.org/api/fs.html#fs_fs_exists_path_callback + // First argument is the result instead of an error + resolve(err); + } else if (err) { + reject(err); + } else { + // Make an exception for child_process.exec, this is also done by node 8+'s implementation + // https://github.com/nodejs/node/blob/2ec57a71343cdb725d45801508fceb0a266a9324/lib/internal/util.js#L272 + if (original === exec) { + resolve({ + stderr: values[1], + stdout: values[0] + }); + } else { + resolve(values[0]); + } + } + }); + }); + }; +} + +export default promisify as typeof util.promisify; diff --git a/packages/stryker-util/test/helpers/initSinon.ts b/packages/stryker-util/test/helpers/initSinon.ts new file mode 100644 index 0000000000..b168594f22 --- /dev/null +++ b/packages/stryker-util/test/helpers/initSinon.ts @@ -0,0 +1,5 @@ +import * as sinon from 'sinon'; + +afterEach(() => { + sinon.restore(); +}); diff --git a/packages/stryker-util/test/helpers/initSourceMaps.ts b/packages/stryker-util/test/helpers/initSourceMaps.ts new file mode 100644 index 0000000000..fcfbfda16c --- /dev/null +++ b/packages/stryker-util/test/helpers/initSourceMaps.ts @@ -0,0 +1 @@ +import 'source-map-support/register'; diff --git a/packages/stryker-util/test/helpers/registerChaiPlugins.ts b/packages/stryker-util/test/helpers/registerChaiPlugins.ts new file mode 100644 index 0000000000..3f9437376e --- /dev/null +++ b/packages/stryker-util/test/helpers/registerChaiPlugins.ts @@ -0,0 +1,5 @@ +import * as sinonChai from 'sinon-chai'; +import * as chaiAsPromised from 'chai-as-promised'; +import * as chai from 'chai'; +chai.use(sinonChai); +chai.use(chaiAsPromised); diff --git a/packages/stryker-util/test/unit/childProcessAsPromised.ts b/packages/stryker-util/test/unit/childProcessAsPromised.ts new file mode 100644 index 0000000000..548bb66823 --- /dev/null +++ b/packages/stryker-util/test/unit/childProcessAsPromised.ts @@ -0,0 +1,10 @@ +import childProcess = require('child_process'); +import { expect } from 'chai'; +import { childProcessAsPromised, promisify } from '../../src'; + +describe('childProcessAsPromised', () => { + it(`should expose promisified exec`, () => { + // It's difficult to test this any other way. At least this way, we know it is promisified. + expect(childProcessAsPromised.exec.toString()).eq(promisify(childProcess.exec).toString()); + }); +}); diff --git a/packages/stryker-util/test/unit/fsAsPromisedSpec.ts b/packages/stryker-util/test/unit/fsAsPromisedSpec.ts new file mode 100644 index 0000000000..ff65c66fd3 --- /dev/null +++ b/packages/stryker-util/test/unit/fsAsPromisedSpec.ts @@ -0,0 +1,33 @@ +import fs = require('fs'); +import { expect } from 'chai'; +import { fsAsPromised, promisify } from '../../src'; + +describe('fsAsPromised', () => { + + describePromisifiedFunction('exists'); + describePromisifiedFunction('lstat'); + describePromisifiedFunction('symlink'); + describePromisifiedFunction('readFile'); + describePromisifiedFunction('writeFile'); + describePromisifiedFunction('stat'); + describePromisifiedFunction('readdir'); + + describeProxyFunction('existsSync'); + describeProxyFunction('readdirSync'); + describeProxyFunction('createReadStream'); + describeProxyFunction('createWriteStream'); + + function describeProxyFunction(fnToTest: keyof typeof fs & keyof typeof fsAsPromised) { + it(`should proxy ${fnToTest}`, () => { + // It's difficult to test this any other way. At least this way, we know it is promisified. + expect(fsAsPromised[fnToTest]).eq(fs[fnToTest]); + }); + } + + function describePromisifiedFunction(fnToTest: keyof typeof fs & keyof typeof fsAsPromised) { + it(`should expose promisified ${fnToTest}`, () => { + // It's difficult to test this any other way. At least this way, we know it is promisified. + expect(fsAsPromised[fnToTest].toString()).eq(promisify(fs[fnToTest]).toString()); + }); + } +}); diff --git a/packages/stryker-util/test/unit/promisifySpec.ts b/packages/stryker-util/test/unit/promisifySpec.ts new file mode 100644 index 0000000000..de47ad7bcd --- /dev/null +++ b/packages/stryker-util/test/unit/promisifySpec.ts @@ -0,0 +1,60 @@ +import promisify, { innerPromisify } from '../../src/promisify'; +import * as sinon from 'sinon'; +import { expect } from 'chai'; +import { exec } from 'child_process'; +import { exists } from 'fs'; + +describe('promisify', () => { + describePromisify(promisify); +}); + +describe('innerPromisify', () => { + describePromisify(innerPromisify); +}); + +function describePromisify(promisifyImplementation: any) { + + it('should resolve the promise when the callback resolves', async () => { + // Arrange + const actualCallbackFn = sinon.stub(); + + // Act + const actualPromisifiedFn = promisifyImplementation(actualCallbackFn); + const actualPromise = actualPromisifiedFn('foo', 42); + actualCallbackFn.callArgWith(2, null, 'baz', 42); + const actualResult = await actualPromise; + + // Assert + expect(actualPromise).instanceOf(Promise); + expect(actualCallbackFn).calledWithExactly('foo', 42, sinon.match.func); + expect(actualResult).eq('baz'); + }); + + it('should reject the promise when the callback resolved with an error', async () => { + // Arrange + const actualCallbackFn = sinon.stub(); + const expectedError = new Error('foobar'); + + // Act + const actualPromisifiedFn = promisifyImplementation(actualCallbackFn); + const actualPromise = actualPromisifiedFn('foo', 42); + actualCallbackFn.callArgWith(2, expectedError); + + // Assert + expect(actualPromise).instanceOf(Promise); + expect(actualCallbackFn).calledWithExactly('foo', 42, sinon.match.func); + await expect(actualPromise).rejectedWith(expectedError); + }); + + it('should resolve child_process.exec as an object instead of an array', async () => { + const execAsPromised = promisifyImplementation(exec); + const result = await execAsPromised('node -p \'"foo"\''); + expect(result.stdout.trim()).eq('foo'); + }); + + it('should resolve fs.exists with first argument being result instead of an error', async () => { + const existsAsPromised = promisifyImplementation(exists); + const result = await existsAsPromised(__filename); + expect(result).eq(true); + }); +} diff --git a/packages/stryker-util/tsconfig.json b/packages/stryker-util/tsconfig.json new file mode 100644 index 0000000000..7321cad4c9 --- /dev/null +++ b/packages/stryker-util/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "exclude": [ + "node_modules", + "src/**/*.d.ts", + "test/**/*.d.ts", + "testResources" + ] +} \ No newline at end of file diff --git a/packages/stryker/package.json b/packages/stryker/package.json index 6f9efa98c6..055a403d29 100644 --- a/packages/stryker/package.json +++ b/packages/stryker/package.json @@ -64,12 +64,12 @@ "lodash": "~4.17.4", "log4js": "~3.0.0", "mkdirp": "~0.5.1", - "mz": "~2.7.0", "prettier": "~1.14.0", "progress": "~2.0.0", "rimraf": "~2.6.1", "rxjs": "~6.3.0", "source-map": "~0.6.1", + "@stryker-mutator/util": "^0.0.0", "surrial": "~0.1.3", "tree-kill": "~1.2.0", "tslib": "~1.9.3", @@ -79,7 +79,7 @@ "@types/get-port": "~4.0.0", "@types/inquirer": "~0.0.42", "@types/istanbul-lib-instrument": "~1.7.0", - "@types/node": "^6.0.114", + "@types/node": "~10.11.4", "@types/prettier": "~1.13.1", "@types/progress": "~2.0.1", "stryker-api": "^0.21.2" diff --git a/packages/stryker/src/PluginLoader.ts b/packages/stryker/src/PluginLoader.ts index 259794700c..431bb5a5ed 100644 --- a/packages/stryker/src/PluginLoader.ts +++ b/packages/stryker/src/PluginLoader.ts @@ -1,8 +1,8 @@ -import * as fs from 'mz/fs'; import * as path from 'path'; import { getLogger } from 'stryker-api/logging'; import * as _ from 'lodash'; import { importModule } from './utils/fileUtils'; +import { fsAsPromised } from '@stryker-mutator/util'; const IGNORED_PACKAGES = ['stryker-cli', 'stryker-api']; @@ -26,7 +26,7 @@ export default class PluginLoader { const regexp = new RegExp('^' + pluginExpression.replace('*', '.*')); this.log.debug('Loading %s from %s', pluginExpression, pluginDirectory); - const plugins = fs.readdirSync(pluginDirectory) + const plugins = fsAsPromised.readdirSync(pluginDirectory) .filter(pluginName => IGNORED_PACKAGES.indexOf(pluginName) === -1 && regexp.test(pluginName)) .map(pluginName => pluginDirectory + '/' + pluginName); if (plugins.length === 0) { diff --git a/packages/stryker/src/config/ConfigReader.ts b/packages/stryker/src/config/ConfigReader.ts index 575c4b0014..15e94a0b8d 100644 --- a/packages/stryker/src/config/ConfigReader.ts +++ b/packages/stryker/src/config/ConfigReader.ts @@ -1,5 +1,5 @@ import * as _ from 'lodash'; -import * as fs from 'mz/fs'; +import fs = require('fs'); import * as path from 'path'; import { Config } from 'stryker-api/config'; import { StrykerOptions } from 'stryker-api/core'; diff --git a/packages/stryker/src/globals.ts b/packages/stryker/src/globals.ts index 7f5149dad6..f8a2e714dd 100644 --- a/packages/stryker/src/globals.ts +++ b/packages/stryker/src/globals.ts @@ -9,24 +9,3 @@ interface Event { } interface MessageEvent { } interface CloseEvent { } interface WebSocket { } -declare namespace NodeJS { - type MessageListener = (message: any, sendHandle: any) => void; - type UncaughtExceptionListener = (error: Error) => void; - type UnhandledRejectionListener = (reason: any, promise: Promise) => void; - type RejectionHandledListener = (promise: Promise) => void; - export interface Process extends EventEmitter { - addListener(event: 'uncaughtException', listener: UncaughtExceptionListener): this; - addListener(event: 'unhandledRejection', listener: UnhandledRejectionListener): this; - addListener(event: 'rejectionHandled', listener: RejectionHandledListener): this; - emit(event: 'uncaughtException', error: Error): boolean; - emit(event: 'unhandledRejection', reason: any, promise: Promise): boolean; - emit(event: 'rejectionHandled', promise: Promise): boolean; - on(event: string, listener: (...args: any[]) => void): this; - on(event: 'uncaughtException', listener: UncaughtExceptionListener): this; - on(event: 'unhandledRejection', listener: UnhandledRejectionListener): this; - on(event: 'rejectionHandled', listener: RejectionHandledListener): this; - } -} -declare module 'fs' { - export function createWriteStream(path: string, options?: string): WriteStream; -} diff --git a/packages/stryker/src/initializer/StrykerConfigWriter.ts b/packages/stryker/src/initializer/StrykerConfigWriter.ts index 1586c776c5..b06e2c22cb 100644 --- a/packages/stryker/src/initializer/StrykerConfigWriter.ts +++ b/packages/stryker/src/initializer/StrykerConfigWriter.ts @@ -1,5 +1,5 @@ -import * as fs from 'mz/fs'; import * as _ from 'lodash'; +import { fsAsPromised } from '@stryker-mutator/util'; import { getLogger } from 'stryker-api/logging'; import { StrykerOptions } from 'stryker-api/core'; import PromptOption from './PromptOption'; @@ -14,7 +14,7 @@ export default class StrykerConfigWriter { } public guardForExistingConfig() { - if (fs.existsSync(STRYKER_CONFIG_FILE)) { + if (fsAsPromised.existsSync(STRYKER_CONFIG_FILE)) { const msg = 'Stryker config file "stryker.conf.js" already exists in the current directory. Please remove it and try again.'; this.log.error(msg); @@ -26,7 +26,7 @@ export default class StrykerConfigWriter { * Create stryker.conf.js based on the chosen framework and test runner * @function */ - public async write( + public write( selectedTestRunner: null | PromptOption, selectedTestFramework: null | PromptOption, selectedMutator: null | PromptOption, @@ -58,7 +58,7 @@ export default class StrykerConfigWriter { private writeStrykerConfig(configObject: Partial) { this.out('Writing stryker.conf.js...'); - return fs.writeFile(STRYKER_CONFIG_FILE, this.wrapInModule(configObject)); + return fsAsPromised.writeFile(STRYKER_CONFIG_FILE, this.wrapInModule(configObject)); } private wrapInModule(configObject: Partial) { diff --git a/packages/stryker/src/input/InputFileResolver.ts b/packages/stryker/src/input/InputFileResolver.ts index 486fc01846..e728133257 100644 --- a/packages/stryker/src/input/InputFileResolver.ts +++ b/packages/stryker/src/input/InputFileResolver.ts @@ -1,6 +1,6 @@ import * as path from 'path'; -import * as fs from 'mz/fs'; -import { exec } from 'mz/child_process'; +import { fsAsPromised } from '@stryker-mutator/util'; +import { childProcessAsPromised } from '@stryker-mutator/util'; import { getLogger } from 'stryker-api/logging'; import { File } from 'stryker-api/core'; import { glob } from '../utils/fileUtils'; @@ -48,8 +48,8 @@ export default class InputFileResolver { } private resolveFilesUsingGit(): Promise { - return exec('git ls-files --others --exclude-standard --cached --exclude .stryker-tmp', { maxBuffer: 10 * 1000 * 1024 }) - .then(([stdout]) => stdout.toString()) + return childProcessAsPromised.exec('git ls-files --others --exclude-standard --cached --exclude .stryker-tmp', { maxBuffer: 10 * 1000 * 1024 }) + .then(({stdout}) => stdout.toString()) .then(output => output.split('\n').map(fileName => fileName.trim())) .then(fileNames => fileNames.filter(fileName => fileName).map(fileName => path.resolve(fileName))) .catch(error => { @@ -71,7 +71,7 @@ export default class InputFileResolver { } private readFile(fileName: string): Promise { - return fs.readFile(fileName).then(content => new File(fileName, content)) + return fsAsPromised.readFile(fileName).then(content => new File(fileName, content)) .then(file => { this.reportSourceFilesRead(file); return file; diff --git a/packages/stryker/src/reporters/EventRecorderReporter.ts b/packages/stryker/src/reporters/EventRecorderReporter.ts index e2ae4e6ed4..9ee54db908 100644 --- a/packages/stryker/src/reporters/EventRecorderReporter.ts +++ b/packages/stryker/src/reporters/EventRecorderReporter.ts @@ -1,10 +1,10 @@ import { getLogger } from 'stryker-api/logging'; import * as path from 'path'; -import * as fs from 'mz/fs'; import { StrykerOptions } from 'stryker-api/core'; import { SourceFile, MutantResult, MatchedMutant, Reporter, ScoreResult } from 'stryker-api/report'; import { cleanFolder } from '../utils/fileUtils'; import StrictReporter from './StrictReporter'; +import { fsAsPromised } from '@stryker-mutator/util'; const DEFAULT_BASE_FOLDER = 'reports/mutation/events'; @@ -36,7 +36,7 @@ export default class EventRecorderReporter implements StrictReporter { private writeToFile(methodName: keyof Reporter, data: any) { const filename = path.join(this.baseFolder, `${this.format(this.index++)}-${methodName}.json`); this.log.debug(`Writing event ${methodName} to file ${filename}`); - return fs.writeFile(filename, JSON.stringify(data), { encoding: 'utf8' }); + return fsAsPromised.writeFile(filename, JSON.stringify(data), { encoding: 'utf8' }); } private format(input: number) { diff --git a/packages/stryker/src/utils/StrykerTempFolder.ts b/packages/stryker/src/utils/StrykerTempFolder.ts deleted file mode 100644 index a537d46a58..0000000000 --- a/packages/stryker/src/utils/StrykerTempFolder.ts +++ /dev/null @@ -1,74 +0,0 @@ -import * as fs from 'mz/fs'; -import * as path from 'path'; -import * as mkdirp from 'mkdirp'; -import { getLogger } from 'stryker-api/logging'; -import { deleteDir } from './fileUtils'; - -const baseTempFolder = path.join(process.cwd(), '.stryker-tmp'); -const tempFolder = path.join(baseTempFolder, random().toString()); -mkdirp.sync(baseTempFolder); -mkdirp.sync(tempFolder); - -/** - * Creates a new random folder with the specified prefix. - * @param prefix The prefix. - * @returns The path to the folder. - */ -function createRandomFolder(prefix: string): string { - const dir = tempFolder + path.sep + prefix + random(); - mkdirp.sync(dir); - return dir; -} - -/** - * Creates a random integer number. - * @returns A random integer. - */ -function random(): number { - return Math.ceil(Math.random() * 10000000); -} - -/** - * Writes data to a specified file. - * @param fileName The path to the file. - * @param data The content of the file. - * @returns A promise to eventually save the file. - */ -function writeFile(fileName: string, data: string | Buffer, instrumenter: NodeJS.ReadWriteStream | null = null): Promise { - if (Buffer.isBuffer(data)) { - return fs.writeFile(fileName, data); - } else if (instrumenter) { - instrumenter.pipe(fs.createWriteStream(fileName, 'utf8')); - return writeToStream(data, instrumenter); - } else { - return fs.writeFile(fileName, data, 'utf8'); - } -} - -function writeToStream(data: string | Buffer, stream: NodeJS.WritableStream): Promise { - return new Promise((res, rej) => { - stream.end(data as string, (err: Error) => { - if (err) { - rej(err); - } else { - res(); - } - }); - }); -} - -/** - * Deletes the Stryker-temp folder - */ -function clean() { - const log = getLogger('StrykerTempFolder'); - log.debug(`Cleaning stryker temp folder ${baseTempFolder}`); - return deleteDir(baseTempFolder) - .catch(() => log.info(`Failed to clean stryker temp folder ${baseTempFolder}`)); -} - -export default { - clean, - createRandomFolder, - writeFile -}; diff --git a/packages/stryker/src/utils/TempFolder.ts b/packages/stryker/src/utils/TempFolder.ts index 7f574f22ef..a35ce55267 100644 --- a/packages/stryker/src/utils/TempFolder.ts +++ b/packages/stryker/src/utils/TempFolder.ts @@ -1,4 +1,4 @@ -import * as fs from 'mz/fs'; +import { fsAsPromised } from '@stryker-mutator/util'; import * as path from 'path'; import * as mkdirp from 'mkdirp'; import { getLogger } from 'stryker-api/logging'; @@ -41,8 +41,8 @@ export class TempFolder { */ public copyFile(fromFilename: string, toFilename: string, instrumenter: NodeJS.ReadWriteStream | null): Promise { return new Promise((resolve, reject) => { - let readStream: NodeJS.ReadableStream = fs.createReadStream(fromFilename, { encoding: 'utf8' }); - const writeStream = fs.createWriteStream(toFilename); + let readStream: NodeJS.ReadableStream = fsAsPromised.createReadStream(fromFilename, { encoding: 'utf8' }); + const writeStream = fsAsPromised.createWriteStream(toFilename); readStream.on('error', reject); writeStream.on('error', reject); if (instrumenter) { diff --git a/packages/stryker/src/utils/fileUtils.ts b/packages/stryker/src/utils/fileUtils.ts index 502a156368..4387e74a00 100644 --- a/packages/stryker/src/utils/fileUtils.ts +++ b/packages/stryker/src/utils/fileUtils.ts @@ -1,8 +1,8 @@ -import * as fs from 'mz/fs'; import * as path from 'path'; import * as nodeGlob from 'glob'; import * as mkdirp from 'mkdirp'; import * as rimraf from 'rimraf'; +import { fsAsPromised } from '@stryker-mutator/util'; export function glob(expression: string): Promise { return new Promise((resolve, reject) => { @@ -18,7 +18,7 @@ export function deleteDir(dirToDelete: string): Promise { export async function cleanFolder(folderName: string) { try { - await fs.lstat(folderName); + await fsAsPromised.lstat(folderName); await deleteDir(folderName); return mkdirp.sync(folderName); } catch (e) { @@ -42,9 +42,9 @@ export function importModule(moduleName: string) { */ export function writeFile(fileName: string, data: string | Buffer): Promise { if (Buffer.isBuffer(data)) { - return fs.writeFile(fileName, data); + return fsAsPromised.writeFile(fileName, data); } else { - return fs.writeFile(fileName, data, 'utf8'); + return fsAsPromised.writeFile(fileName, data, 'utf8'); } } @@ -54,7 +54,7 @@ export function writeFile(fileName: string, data: string | Buffer): Promise { basePath = path.resolve(basePath); const nodeModules = path.resolve(basePath, 'node_modules'); - const exists = await fs.exists(nodeModules); - if (exists) { + if (await fsAsPromised.exists(nodeModules)) { return nodeModules; } else { const parent = path.dirname(basePath); diff --git a/packages/stryker/test/integration/source-mapper/SourceMapperIT.ts b/packages/stryker/test/integration/source-mapper/SourceMapperIT.ts index 26bf3147ca..07665becbc 100644 --- a/packages/stryker/test/integration/source-mapper/SourceMapperIT.ts +++ b/packages/stryker/test/integration/source-mapper/SourceMapperIT.ts @@ -1,8 +1,8 @@ -import * as fs from 'mz/fs'; import * as path from 'path'; import { File } from 'stryker-api/core'; import { TranspiledSourceMapper } from '../../../src/transpiler/SourceMapper'; import { expect } from 'chai'; +import { fsAsPromised } from '@stryker-mutator/util'; function resolve(...filePart: string[]) { return path.resolve(__dirname, '..', '..', '..', 'testResources', 'source-mapper', ...filePart); @@ -11,7 +11,7 @@ function resolve(...filePart: string[]) { function readFiles(...files: string[]): Promise { return Promise.all(files .map(relative => resolve(relative)) - .map(fileName => fs.readFile(fileName).then(content => new File(fileName, content)))); + .map(fileName => fsAsPromised.readFile(fileName).then(content => new File(fileName, content)))); } describe('Source mapper integration', function() { diff --git a/packages/stryker/test/unit/PluginLoaderSpec.ts b/packages/stryker/test/unit/PluginLoaderSpec.ts index 71ec1b8df4..7ef956eecd 100644 --- a/packages/stryker/test/unit/PluginLoaderSpec.ts +++ b/packages/stryker/test/unit/PluginLoaderSpec.ts @@ -1,5 +1,4 @@ import * as path from 'path'; -import * as fs from 'mz/fs'; import { Logger } from 'stryker-api/logging'; import * as sinon from 'sinon'; import { expect } from 'chai'; @@ -7,6 +6,7 @@ import * as fileUtils from '../../src/utils/fileUtils'; import PluginLoader from '../../src/PluginLoader'; import currentLogMock from '../helpers/logMock'; import { Mock } from '../helpers/producers'; +import { fsAsPromised } from '@stryker-mutator/util'; describe('PluginLoader', () => { @@ -20,7 +20,7 @@ describe('PluginLoader', () => { log = currentLogMock(); sandbox = sinon.createSandbox(); importModuleStub = sandbox.stub(fileUtils, 'importModule'); - pluginDirectoryReadMock = sandbox.stub(fs, 'readdirSync'); + pluginDirectoryReadMock = sandbox.stub(fsAsPromised, 'readdirSync'); }); describe('without wildcards', () => { diff --git a/packages/stryker/test/unit/initializer/StrykerInitializerSpec.ts b/packages/stryker/test/unit/initializer/StrykerInitializerSpec.ts index 530d1b523f..cc2c0581e2 100644 --- a/packages/stryker/test/unit/initializer/StrykerInitializerSpec.ts +++ b/packages/stryker/test/unit/initializer/StrykerInitializerSpec.ts @@ -1,7 +1,7 @@ import * as child from 'child_process'; -import * as fs from 'mz/fs'; import * as sinon from 'sinon'; import { Logger } from 'stryker-api/logging'; +import { fsAsPromised } from '@stryker-mutator/util'; import { expect } from 'chai'; import * as inquirer from 'inquirer'; import StrykerInitializer from '../../../src/initializer/StrykerInitializer'; @@ -25,8 +25,8 @@ describe('StrykerInitializer', () => { out = sandbox.stub(); inquirerPrompt = sandbox.stub(inquirer, 'prompt'); childExecSync = sandbox.stub(child, 'execSync'); - fsWriteFile = sandbox.stub(fs, 'writeFile'); - fsExistsSync = sandbox.stub(fs, 'existsSync'); + fsWriteFile = sandbox.stub(fsAsPromised, 'writeFile'); + fsExistsSync = sandbox.stub(fsAsPromised, 'existsSync'); restClientSearchGet = sandbox.stub(); restClientPackageGet = sandbox.stub(); sandbox.stub(restClient, 'RestClient') @@ -120,7 +120,7 @@ describe('StrykerInitializer', () => { await sut.initialize(); expect(inquirerPrompt).to.have.been.callCount(6); expect(out).to.have.been.calledWith('OK, downgrading coverageAnalysis to "all"'); - expect(fs.writeFile).to.have.been.calledWith('stryker.conf.js', sinon.match('coverageAnalysis: "all"')); + expect(fsAsPromised.writeFile).to.have.been.calledWith('stryker.conf.js', sinon.match('coverageAnalysis: "all"')); }); it('should install any additional dependencies', async () => { @@ -148,7 +148,7 @@ describe('StrykerInitializer', () => { transpilers: ['webpack'] }); await sut.initialize(); - expect(fs.writeFile).to.have.been.calledWith('stryker.conf.js', sinon.match('testRunner: "awesome"') + expect(fsAsPromised.writeFile).to.have.been.calledWith('stryker.conf.js', sinon.match('testRunner: "awesome"') .and(sinon.match('testFramework: "awesome"')) .and(sinon.match('packageManager: "npm"')) .and(sinon.match('coverageAnalysis: "perTest"')) @@ -166,8 +166,8 @@ describe('StrykerInitializer', () => { transpilers: ['webpack'] }); await sut.initialize(); - expect(fs.writeFile).to.have.been.calledWith('stryker.conf.js', sinon.match('someOtherSetting: "enabled"')); - expect(fs.writeFile).to.have.been.calledWith('stryker.conf.js', sinon.match('files: []')); + expect(fsAsPromised.writeFile).to.have.been.calledWith('stryker.conf.js', sinon.match('someOtherSetting: "enabled"')); + expect(fsAsPromised.writeFile).to.have.been.calledWith('stryker.conf.js', sinon.match('files: []')); }); describe('but no testFramework can be found that supports the testRunner', () => { @@ -190,7 +190,7 @@ describe('StrykerInitializer', () => { await sut.initialize(); expect(out).to.have.been.calledWith('No stryker test framework plugin found that is compatible with ghost, downgrading coverageAnalysis to "all"'); - expect(fs.writeFile).to.have.been.calledWith('stryker.conf.js', sinon.match('coverageAnalysis: "all"')); + expect(fsAsPromised.writeFile).to.have.been.calledWith('stryker.conf.js', sinon.match('coverageAnalysis: "all"')); }); }); @@ -221,7 +221,7 @@ describe('StrykerInitializer', () => { await sut.initialize(); expect(out).to.have.been.calledWith('An error occurred during installation, please try it yourself: "npm i --save-dev stryker-api stryker-ghost-runner"'); - expect(fs.writeFile).to.have.been.called; + expect(fsAsPromised.writeFile).to.have.been.called; }); }); @@ -243,7 +243,7 @@ describe('StrykerInitializer', () => { expect(log.error).to.have.been.calledWith('Unable to reach https://api.npms.io (for query /v2/search?q=keywords:stryker-test-runner). Please check your internet connection.'); expect(out).to.have.been.calledWith('Unable to select a test runner. You will need to configure it manually.'); - expect(fs.writeFile).to.have.been.called; + expect(fsAsPromised.writeFile).to.have.been.called; }); it('should log error and continue when fetching test frameworks', async () => { @@ -264,7 +264,7 @@ describe('StrykerInitializer', () => { expect(log.error).to.have.been.calledWith('Unable to reach https://api.npms.io (for query /v2/search?q=keywords:stryker-test-framework). Please check your internet connection.'); expect(out).to.have.been.calledWith('No stryker test framework plugin found that is compatible with awesome, downgrading coverageAnalysis to "all"'); - expect(fs.writeFile).to.have.been.called; + expect(fsAsPromised.writeFile).to.have.been.called; }); it('should log error and continue when fetching mutators', async () => { @@ -285,7 +285,7 @@ describe('StrykerInitializer', () => { expect(log.error).to.have.been.calledWith('Unable to reach https://api.npms.io (for query /v2/search?q=keywords:stryker-mutator). Please check your internet connection.'); expect(out).to.have.been.calledWith('Unable to select a mutator. You will need to configure it manually.'); - expect(fs.writeFile).to.have.been.called; + expect(fsAsPromised.writeFile).to.have.been.called; }); it('should log error and continue when fetching transpilers', async () => { @@ -305,7 +305,7 @@ describe('StrykerInitializer', () => { expect(log.error).to.have.been.calledWith('Unable to reach https://api.npms.io (for query /v2/search?q=keywords:stryker-transpiler). Please check your internet connection.'); expect(out).to.have.been.calledWith('Unable to select transpilers. You will need to configure it manually, if you want to use any.'); - expect(fs.writeFile).to.have.been.called; + expect(fsAsPromised.writeFile).to.have.been.called; }); it('should log error and continue when fetching stryker reporters', async () => { @@ -325,7 +325,7 @@ describe('StrykerInitializer', () => { await sut.initialize(); expect(log.error).to.have.been.calledWith('Unable to reach https://api.npms.io (for query /v2/search?q=keywords:stryker-reporter). Please check your internet connection.'); - expect(fs.writeFile).to.have.been.called; + expect(fsAsPromised.writeFile).to.have.been.called; }); it('should log warning and continue when fetching custom config', async () => { @@ -345,7 +345,7 @@ describe('StrykerInitializer', () => { await sut.initialize(); expect(log.warn).to.have.been.calledWith('Could not fetch additional initialization config for dependency stryker-awesome-runner. You might need to configure it manually'); - expect(fs.writeFile).to.have.been.called; + expect(fsAsPromised.writeFile).to.have.been.called; }); }); diff --git a/packages/stryker/test/unit/input/InputFileResolverSpec.ts b/packages/stryker/test/unit/input/InputFileResolverSpec.ts index 9280e9b2c3..8fee03df73 100644 --- a/packages/stryker/test/unit/input/InputFileResolverSpec.ts +++ b/packages/stryker/test/unit/input/InputFileResolverSpec.ts @@ -1,7 +1,6 @@ import * as path from 'path'; import { expect } from 'chai'; -import * as fs from 'mz/fs'; -import * as childProcess from 'mz/child_process'; +import { childProcessAsPromised } from '@stryker-mutator/util'; import { Logger } from 'stryker-api/logging'; import { File } from 'stryker-api/core'; import { SourceFile } from 'stryker-api/report'; @@ -12,6 +11,7 @@ import currentLogMock from '../../helpers/logMock'; import BroadcastReporter from '../../../src/reporters/BroadcastReporter'; import { Mock, mock, createFileNotFoundError } from '../../helpers/producers'; import { errorToString, normalizeWhiteSpaces } from '../../../src/utils/objectUtils'; +import { fsAsPromised } from '@stryker-mutator/util'; const files = (...namesWithContent: [string, string][]): File[] => namesWithContent.map((nameAndContent): File => new File( @@ -31,7 +31,7 @@ describe('InputFileResolver', () => { log = currentLogMock(); reporter = mock(BroadcastReporter); globStub = sandbox.stub(fileUtils, 'glob'); - readFileStub = sandbox.stub(fs, 'readFile') + readFileStub = sandbox.stub(fsAsPromised, 'readFile') .withArgs(sinon.match.string).resolves(Buffer.from('')) // fallback .withArgs(sinon.match.string).resolves(Buffer.from('')) // fallback .withArgs(sinon.match('file1')).resolves(Buffer.from('file 1 content')) @@ -47,15 +47,17 @@ describe('InputFileResolver', () => { globStub.withArgs('file3').resolves(['/file3.js']); globStub.withArgs('file*').resolves(['/file1.js', '/file2.js', '/file3.js']); globStub.resolves([]); // default - childProcessExecStub = sandbox.stub(childProcess, 'exec'); + childProcessExecStub = sandbox.stub(childProcessAsPromised, 'exec'); }); it('should use git to identify files if files array is missing', async () => { sut = new InputFileResolver([], undefined, reporter); - childProcessExecStub.resolves([Buffer.from(` + childProcessExecStub.resolves({ + stdout: Buffer.from(` file1.js foo/bar/baz.ts - `)]); + `) + }); const result = await sut.resolve(); expect(childProcessExecStub).calledWith('git ls-files --others --exclude-standard --cached --exclude .stryker-tmp', { maxBuffer: 10 * 1000 * 1024 }); @@ -81,9 +83,11 @@ describe('InputFileResolver', () => { it('should be able to handled deleted files reported by `git ls-files`', async () => { sut = new InputFileResolver([], undefined, reporter); - childProcessExecStub.resolves([Buffer.from(` + childProcessExecStub.resolves({ + stdout: Buffer.from(` deleted/file.js - `)]); + `) + }); const fileNotFoundError = createFileNotFoundError(); readFileStub.withArgs('deleted/file.js').rejects(fileNotFoundError); const result = await sut.resolve(); diff --git a/packages/stryker/test/unit/reporters/EventRecorderReporterSpec.ts b/packages/stryker/test/unit/reporters/EventRecorderReporterSpec.ts index f2cb4ce56d..bbbd898c44 100644 --- a/packages/stryker/test/unit/reporters/EventRecorderReporterSpec.ts +++ b/packages/stryker/test/unit/reporters/EventRecorderReporterSpec.ts @@ -1,12 +1,12 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; -import * as fs from 'mz/fs'; import { Reporter } from 'stryker-api/report'; import EventRecorderReporter from '../../../src/reporters/EventRecorderReporter'; import * as fileUtils from '../../../src/utils/fileUtils'; import currentLogMock from '../../helpers/logMock'; import StrictReporter from '../../../src/reporters/StrictReporter'; import { ALL_REPORTER_EVENTS } from '../../helpers/producers'; +import { fsAsPromised } from '@stryker-mutator/util'; describe('EventRecorderReporter', () => { @@ -18,7 +18,7 @@ describe('EventRecorderReporter', () => { beforeEach(() => { sandbox = sinon.createSandbox(); cleanFolderStub = sandbox.stub(fileUtils, 'cleanFolder'); - writeFileStub = sandbox.stub(fs, 'writeFile'); + writeFileStub = sandbox.stub(fsAsPromised, 'writeFile'); }); afterEach(() => { @@ -63,7 +63,7 @@ describe('EventRecorderReporter', () => { describe('when writeFile is successful', () => { arrange(); - it('should writeFile', () => expect(fs.writeFile).to.have.been.calledWith(sinon.match(RegExp(`.*0000\\d-${eventName}\\.json`)), JSON.stringify(expected))); + it('should writeFile', () => expect(fsAsPromised.writeFile).to.have.been.calledWith(sinon.match(RegExp(`.*0000\\d-${eventName}\\.json`)), JSON.stringify(expected))); }); }); }; diff --git a/packages/stryker/test/unit/utils/TempFolderSpec.ts b/packages/stryker/test/unit/utils/TempFolderSpec.ts index ee8a341267..8c19a44a67 100644 --- a/packages/stryker/test/unit/utils/TempFolderSpec.ts +++ b/packages/stryker/test/unit/utils/TempFolderSpec.ts @@ -1,7 +1,7 @@ import * as sinon from 'sinon'; import { expect } from 'chai'; import * as mkdirp from 'mkdirp'; -import * as fs from 'mz/fs'; +import { fsAsPromised } from '@stryker-mutator/util'; import { TempFolder } from '../../../src/utils/TempFolder'; import * as fileUtils from '../../../src/utils/fileUtils'; @@ -16,7 +16,7 @@ describe('TempFolder', () => { sandbox = sinon.createSandbox(); sandbox.stub(mkdirp, 'sync'); - sandbox.stub(fs, 'writeFile'); + sandbox.stub(fsAsPromised, 'writeFile'); deleteDirStub = sandbox.stub(fileUtils, 'deleteDir'); cwdStub = sandbox.stub(process, 'cwd'); cwdStub.returns(mockCwd); diff --git a/packages/stryker/test/unit/utils/fileUtilsSpec.ts b/packages/stryker/test/unit/utils/fileUtilsSpec.ts index 10cf144b36..e0448a2f01 100644 --- a/packages/stryker/test/unit/utils/fileUtilsSpec.ts +++ b/packages/stryker/test/unit/utils/fileUtilsSpec.ts @@ -1,29 +1,29 @@ +import * as path from 'path'; import { expect } from 'chai'; +import { fsAsPromised } from '@stryker-mutator/util'; import * as fileUtils from '../../../src/utils/fileUtils'; -import * as fs from 'mz/fs'; -import * as path from 'path'; describe('fileUtils', () => { let existsStub: sinon.SinonStub; beforeEach(() => { - sandbox.stub(fs, 'writeFile'); - sandbox.stub(fs, 'symlink'); - existsStub = sandbox.stub(fs, 'exists'); + sandbox.stub(fsAsPromised, 'writeFile'); + sandbox.stub(fsAsPromised, 'symlink'); + existsStub = sandbox.stub(fsAsPromised, 'exists'); }); describe('writeFile', () => { it('should call fs.writeFile', () => { fileUtils.writeFile('filename', 'data'); - expect(fs.writeFile).calledWith('filename', 'data', 'utf8'); + expect(fsAsPromised.writeFile).calledWith('filename', 'data', 'utf8'); }); }); describe('symlinkJunction', () => { it('should call fs.symlink', async () => { await fileUtils.symlinkJunction('a', 'b'); - expect(fs.symlink).calledWith('a', 'b', 'junction'); + expect(fsAsPromised.symlink).calledWith('a', 'b', 'junction'); }); }); diff --git a/workspace.code-workspace b/workspace.code-workspace index 1b0a4aeab3..62a01d09a9 100644 --- a/workspace.code-workspace +++ b/workspace.code-workspace @@ -48,6 +48,9 @@ { "path": "packages/stryker-webpack-transpiler" }, + { + "path": "packages/stryker-util" + }, { "path": "integrationTest" } @@ -66,4 +69,4 @@ } } } -} \ No newline at end of file +}