Skip to content

Commit

Permalink
feat(package): restructure package internals (#2714)
Browse files Browse the repository at this point in the history
- Redirect typescript output to "dist" directories
- No longer compile "api" package root ts files (reduce complexity)
- Enable typescript `--strict` mode
- Fix 2 (small) bugs that resulted from uninitialized properties
- Use default import syntax for commonjs modules instead of wildcard import syntax (eg. ~`import * as path from 'path'`~ _`import path from 'path'_),
- Use named exports instead of a mix of default exports and named exports everywhere.
- Force named exports using an eslint rule.

If you're using deep-imports from `@stryker-mutator/core` or friends, they will have to be updated. Note: as a general rule: don't rely on deep imports from Stryker, as they might break at any moment.

```diff
- import { default as HtmlReporter } from '@stryker-mutator/core/src/reporters/html/html-reporter';
+ import { HtmlReporter } from '@stryker-mutator/core/dist/src/reporters/html/html-reporter';
```
  • Loading branch information
nicojs committed Jan 27, 2021
1 parent 5adec32 commit e1711d2
Show file tree
Hide file tree
Showing 382 changed files with 1,269 additions and 10,229 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -25,6 +25,7 @@ module.exports = {
"groups": ["builtin", "external", "internal", "parent", "sibling", "index"]
}
],
'import/no-default-export': 'error',
'prettier/prettier': ['error'],
'sort-imports': 'off',
'no-case-declarations': 'off',
Expand Down
20 changes: 6 additions & 14 deletions .gitignore
Expand Up @@ -3,37 +3,29 @@ lerna-debug.log
npm-debug.log
stryker.log
lint.log

coverage
reports
.tscache
stryker-tmp
.stryker-tmp
.stryker-tmp-2
.nyc_output
.DS_Store
*.map
# Ignore heap dumps
packages/report.*.json

src-generated
dist
dist-test
packages/report.*.json # Ignore heap dumps
e2e/module/*.js
e2e/module/*.map
e2e/module/*.d.ts
e2e/*.js
e2e/*.map
e2e/*.d.ts
packages/*/src/**/*.js
packages/*/test/**/*.js
packages/*/src/**/*.d.ts
packages/*/test/**/*.d.ts
packages/*/dist
e2e/test/*/dist
e2e/test/*/dist-test
.idea
*.iml
*.tmp.txt
.nyc_output
package-lock.json
.DS_Store
tsconfig.*.tsbuildinfo
src-generated
packages/core/schema
__filterSpecs.js
8 changes: 4 additions & 4 deletions e2e/helpers.ts
@@ -1,15 +1,15 @@
import { promises as fs } from 'fs';
import { promises as fsPromises } from 'fs';

import { mutationTestReportSchema } from '@stryker-mutator/api/report';
import { expect } from 'chai';
import path from 'path';
import { calculateMetrics, MetricsResult, Metrics } from 'mutation-testing-metrics';

export async function readMutationTestResult(eventResultDirectory = path.resolve('reports', 'mutation', 'events')) {
const allReportFiles = await fs.readdir(eventResultDirectory);
const allReportFiles = await fsPromises.readdir(eventResultDirectory);
const mutationTestReportFile = allReportFiles.find(file => !!file.match(/.*onMutationTestReportReady.*/));
expect(mutationTestReportFile).ok;
const mutationTestReportContent = await fs.readFile(path.resolve(eventResultDirectory, mutationTestReportFile || ''), 'utf8');
const mutationTestReportContent = await fsPromises.readFile(path.resolve(eventResultDirectory, mutationTestReportFile || ''), 'utf8');
const report = JSON.parse(mutationTestReportContent) as mutationTestReportSchema.MutationTestResult;
const metricsResult = calculateMetrics(report.files);
return metricsResult;
Expand All @@ -20,7 +20,7 @@ type WritableMetricsResult = {
};

export function readLogFile(fileName = path.resolve('stryker.log')): Promise<string> {
return fs.readFile(fileName, 'utf8');
return fsPromises.readFile(fileName, 'utf8');
}

export async function expectMetricsResult(expectedMetricsResult: Partial<MetricsResult>) {
Expand Down
4 changes: 2 additions & 2 deletions e2e/test/command/verify/verify.ts
@@ -1,4 +1,4 @@
import { promises as fs } from 'fs';
import { promises as fsPromises } from 'fs';

import { expect } from 'chai';
import { expectMetricsResult, produceMetrics } from '../../../helpers';
Expand All @@ -21,7 +21,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 fsPromises.readFile('./stryker.log', 'utf8');
expect(strykerLog).contains('INFO DryRunExecutor Initial test run succeeded. Ran 1 test');
expect(strykerLog).matches(/MutationTestExecutor Done in \d+/);
expect(strykerLog).not.contains('ERROR');
Expand Down
7 changes: 3 additions & 4 deletions e2e/test/exit-prematurely-dry-run-fails/verify/verify.ts
@@ -1,6 +1,5 @@
import { promises as fs } from 'fs';
import { promises as fsPromises } from 'fs';
import chai, { expect } from 'chai';
import { it } from 'mocha';
import chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);

Expand All @@ -9,7 +8,7 @@ describe('Verify stryker has handled dry run failure correctly', () => {
let strykerLog: string;

before(async () => {
strykerLog = await fs.readFile('./stryker.log', 'utf8');
strykerLog = await fsPromises.readFile('./stryker.log', 'utf8');
});

it('should about failed tests in initial test run', async () => {
Expand All @@ -30,6 +29,6 @@ describe('Verify stryker has handled dry run failure correctly', () => {


it('should not delete the temp dir', async () => {
await expect(fs.stat('.stryker-tmp'), 'Expected the `.stryker-tmp` dir to not be deleted.').not.rejected;
await expect(fsPromises.stat('.stryker-tmp'), 'Expected the `.stryker-tmp` dir to not be deleted.').not.rejected;
});
});
4 changes: 2 additions & 2 deletions e2e/test/jasmine-javascript/verify/verify.ts
@@ -1,4 +1,4 @@
import { promises as fs } from 'fs';
import { promises as fsPromises } from 'fs';

import { expect } from 'chai';
import { expectMetrics } from '../../../helpers';
Expand All @@ -20,7 +20,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 fsPromises.readFile('./stryker.log', 'utf8');
expect(strykerLog).matches(/INFO InputFileResolver Found 2 of 9 file\(s\) to be mutated/);
expect(strykerLog).matches(/Done in \d+ second/);
// TODO, we now have an error because of a memory leak: https://github.com/jasmine/jasmine-npm/issues/134
Expand Down
5 changes: 2 additions & 3 deletions e2e/test/mocha-old-version/verify/verify.ts
@@ -1,13 +1,12 @@
import { promises as fs } from 'fs';
import { promises as fsPromises } from 'fs';
import { expect } from 'chai';
import { it } from 'mocha';

describe('Verify stryker runs with mocha < 6', () => {

let strykerLog: string;

before(async () => {
strykerLog = await fs.readFile('./stryker.log', 'utf8');
strykerLog = await fsPromises.readFile('./stryker.log', 'utf8');
});

it('should warn about old mocha version', async () => {
Expand Down
1 change: 1 addition & 0 deletions e2e/tsconfig.json
Expand Up @@ -2,6 +2,7 @@
"extends": "../tsconfig.settings.json",
"compilerOptions": {
"declaration": false,
"composite": false,
"importHelpers": false,
"esModuleInterop": true,
"rootDir": ".",
Expand Down
2 changes: 1 addition & 1 deletion helpers/bootstrap-local-dependencies.ts
@@ -1,5 +1,5 @@
import { ListByPackage, LocalInstaller, progress } from 'install-local';
import * as fs from 'fs';
import fs from 'fs';
import glob = require('glob');
import path = require('path');

Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -15,6 +15,7 @@
"@types/rimraf": "~3.0.0",
"@types/sinon": "^9.0.10",
"@types/sinon-chai": "~3.2.4",
"@types/source-map-support": "^0.5.3",
"@typescript-eslint/eslint-plugin": "4.14.0",
"@typescript-eslint/parser": "4.14.1",
"chai": "~4.2.0",
Expand All @@ -41,7 +42,7 @@
"rimraf": "~3.0.0",
"sinon": "~9.2.0",
"sinon-chai": "~3.5.0",
"source-map-support": "~0.5.6",
"source-map-support": "^0.5.19",
"typescript": "~4.1.3"
},
"scripts": {
Expand All @@ -50,7 +51,7 @@
"lint": "eslint . --resolve-plugins-relative-to . --ext .ts,.tsx",
"lint:log": "eslint . --resolve-plugins-relative-to . --ext .ts,.tsx -f compact -o lint.log",
"lint:fix": "eslint . --resolve-plugins-relative-to . --ext .ts,.tsx --fix",
"clean": "rimraf \"packages/api/!(stryker.conf)+(.d.ts|.js|.map)\" \"packages/*/+(test|src)/**/*+(.d.ts|.js|.map)\" \"packages/*/{.nyc_output,reports,coverage,src-generated,*.tsbuildinfo,.stryker-tmp,dist}\"",
"clean": "rimraf \"packages/*/{.nyc_output,reports,coverage,src-generated,*.tsbuildinfo,.stryker-tmp,dist}\" \"packages/core/schema/stryker-schema.json\"",
"generate": "node tasks/generate-json-schema-to-ts.js && node tasks/generate-mono-schema.js",
"prebuild": "npm run generate",
"build": "tsc -b && lerna run build",
Expand Down
5 changes: 0 additions & 5 deletions packages/api/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion packages/api/.mocharc.jsonc
@@ -1,4 +1,4 @@
{
"require": ["test/setup.js"],
"require": ["dist/test/setup.js"],
"timeout": 10000
}
27 changes: 14 additions & 13 deletions packages/api/.npmignore
@@ -1,13 +1,14 @@
**/*
!*.d.ts
!bin/**
!src/**
!schema/**
!*.js
src/**/*.map
src/**/*.ts
!{src,src-generated}/**/*.d.ts
!schema/*.json
!readme.md
!LICENSE
!CHANGELOG.md
stryker.conf.js
test
dist/test
/schema
/reports
/testResources
/.nyc_output
.vscode
.nycrc.json
*.tsbuildinfo
tsconfig?(.*).json
.mocharc.jsonc
.nyc_output
.gitattributes
7 changes: 3 additions & 4 deletions packages/api/.vscode/launch.json
Expand Up @@ -10,13 +10,12 @@
"--timeout",
"999999",
"--colors",
"${workspaceRoot}/test/helpers/**/*.js",
"${workspaceRoot}/test/unit/**/*.js"
"${workspaceRoot}/dist/test/helpers/**/*.js",
"${workspaceRoot}/dist/test/unit/**/*.js"
],
"internalConsoleOptions": "openOnSessionStart",
"outFiles": [
"${workspaceRoot}/test/**/*.js",
"${workspaceRoot}/src/**/*.js"
"${workspaceRoot}/dist/**/*.js"
],
"skipFiles": [
"<node_internals>/**"
Expand Down
1 change: 1 addition & 0 deletions packages/api/check.d.ts
@@ -0,0 +1 @@
export * from './dist/src/check';
1 change: 1 addition & 0 deletions packages/api/check.js
@@ -0,0 +1 @@
module.exports = require("./dist/src/check")
3 changes: 0 additions & 3 deletions packages/api/check.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/api/core.d.ts
@@ -0,0 +1 @@
export * from './dist/src/core';
1 change: 1 addition & 0 deletions packages/api/core.js
@@ -0,0 +1 @@
module.exports = require("./dist/src/core")
11 changes: 0 additions & 11 deletions packages/api/core.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/api/logging.d.ts
@@ -0,0 +1 @@
export * from './dist/src/logging';
1 change: 1 addition & 0 deletions packages/api/logging.js
@@ -0,0 +1 @@
module.exports = require("./dist/src/logging")
2 changes: 0 additions & 2 deletions packages/api/logging.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/api/package.json
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"stryker": "node ../core/bin/stryker run",
"test": "nyc npm run test:unit",
"test:unit": "mocha \"test/unit/**/*.js\""
"test:unit": "mocha \"dist/test/unit/**/*.js\""
},
"keywords": [
"mutation testing",
Expand Down
1 change: 1 addition & 0 deletions packages/api/plugin.d.ts
@@ -0,0 +1 @@
export * from './dist/src/plugin';
1 change: 1 addition & 0 deletions packages/api/plugin.js
@@ -0,0 +1 @@
module.exports = require("./dist/src/plugin")
6 changes: 0 additions & 6 deletions packages/api/plugin.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/api/report.d.ts
@@ -0,0 +1 @@
export * from './dist/src/report';
1 change: 1 addition & 0 deletions packages/api/report.js
@@ -0,0 +1 @@
module.exports = require("./dist/src/report")
14 changes: 0 additions & 14 deletions packages/api/report.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/api/src/check/checker.ts
@@ -1,4 +1,4 @@
import { Mutant } from '../../core';
import { Mutant } from '../core';

import { CheckResult } from './check-result';

Expand Down
3 changes: 3 additions & 0 deletions packages/api/src/check/index.ts
@@ -0,0 +1,3 @@
export * from './checker';
export * from './check-result';
export * from './check-status';
2 changes: 1 addition & 1 deletion packages/api/src/core/file.ts
Expand Up @@ -3,7 +3,7 @@ import { Surrializable, surrial } from 'surrial';
/**
* Represents a file within Stryker. Could be a strictly in-memory file.
*/
export default class File implements Surrializable {
export class File implements Surrializable {
private _textContent: string | undefined;
private readonly _content: Buffer;

Expand Down
11 changes: 11 additions & 0 deletions packages/api/src/core/index.ts
@@ -0,0 +1,11 @@
export { File } from './file';
export { Position } from './position';
export { Location } from './location';
export { Range } from './range';
export { Mutant } from './mutant';
export * from '../../src-generated/stryker-core';
export * from './report-types';
export * from './stryker-options-schema';
export * from './partial-stryker-options';
export * from './instrument';
export * from './mutant-coverage';
6 changes: 2 additions & 4 deletions packages/api/src/core/location.ts
@@ -1,11 +1,9 @@
import Position from './position';
import { Position } from './position';

/**
* A location in the source code which can span multiple lines and/or columns.
*/
interface Location {
export interface Location {
start: Position;
end: Position;
}

export default Location;
8 changes: 3 additions & 5 deletions packages/api/src/core/mutant.ts
@@ -1,10 +1,10 @@
import Range from './range';
import Location from './location';
import { Range } from './range';
import { Location } from './location';

/**
* Represents a mutant
*/
interface Mutant {
export interface Mutant {
/**
* The id of the mutant. Unique within a run.
*/
Expand Down Expand Up @@ -34,5 +34,3 @@ interface Mutant {
*/
ignoreReason?: string;
}

export default Mutant;
2 changes: 1 addition & 1 deletion packages/api/src/core/partial-stryker-options.ts
@@ -1,4 +1,4 @@
import { StrykerOptions } from '../../core';
import { StrykerOptions } from '../../src-generated/stryker-core';

/**
* When configuring stryker, every option is optional
Expand Down

0 comments on commit e1711d2

Please sign in to comment.