Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(package): restructure package internals #2714

Merged
merged 23 commits into from Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dfe8dc2
refactor(dist): ouput typescript to "dist" dir
nicojs Jan 25, 2021
648ea68
refactor(api): no longer compile api package root ts files
nicojs Jan 25, 2021
8f7f4a0
Fix core.d.ts file
nicojs Jan 25, 2021
4be037b
Update stryker bin
nicojs Jan 25, 2021
be3ca7d
Add mono schema to clean
nicojs Jan 25, 2021
8d989e1
Take new `dist` dir into account when loading plugins
nicojs Jan 25, 2021
86de21a
fix plugin loader test
nicojs Jan 25, 2021
0043c21
Remove unnesesary `timer.reset()` call, instead greedy initialize it
nicojs Jan 25, 2021
b255e5a
Fix incorrect dry run timout logging
nicojs Jan 25, 2021
2ce5228
Fix issue with race condition incorrect `clearInterval` call.
nicojs Jan 25, 2021
62ea482
Enable typescript strict mode
nicojs Jan 25, 2021
90910da
update paths in jest-env
nicojs Jan 25, 2021
8c9becf
refactor(named exports): named instead of default exports
nicojs Jan 27, 2021
d6e4ee9
chore(eslint): enable no-default-export rule
nicojs Jan 27, 2021
74e68de
refactor(import syntax): enable ts `esModuleInterp`
nicojs Jan 27, 2021
b3f1f2a
Delete report.ts
nicojs Jan 27, 2021
34d29da
Remove duplicate `;;`
nicojs Jan 27, 2021
0399af4
Import from package root in api tests
nicojs Jan 27, 2021
53d2a84
rename `child` -> `childProcess`
nicojs Jan 27, 2021
90dd4b0
rename `fs` -> `fsPromises`
nicojs Jan 27, 2021
766c414
enable `--esModuleInterop` in performance tests
nicojs Jan 27, 2021
4c6a9d9
Revert package import in api tests
nicojs Jan 27, 2021
34c3640
Reconfigure snap files
nicojs Jan 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think thats an issue

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing it from mocha is optional. Mocha will make sure it is globally available. I've removed it since we're never importing it.

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.0",
"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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should JS and .D.TS files be on github tho? 🤔

Copy link
Member Author

@nicojs nicojs Jan 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question!

I would actually like to have it as a *.ts file, but that would mean we would need to compile those files in place (not to the dist directory), because I want this import to work: import { File } from '@stryker-mutator/api/core' and that can only be done with a file called "core.js" inside api (on node < 12.7).

When we drop support for node < 12.7 we can start using exports and remove these root files altogether.

I don't want to make an exception for some files to be compiled in place, because that also means making an exception in our clean script and making the output files hidden in vscode config (i don't like hidden files 😢). This all adds complexity that I don't want.

Do you agree with this? In short: we should be able to remove these files once we can use exports in package.json.

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