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 1 commit
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
Jump to file
Failed to load files.
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions packages/core/src/reporters/event-recorder-reporter.ts
@@ -1,5 +1,5 @@
import path from 'path';
import { promises as fs } from 'fs';
import { promises as fsPromises } from 'fs';

import { StrykerOptions } from '@stryker-mutator/api/core';
import { Logger } from '@stryker-mutator/api/logging';
Expand All @@ -24,7 +24,7 @@ export class EventRecorderReporter implements StrictReporter {
private writeToFile(methodName: keyof Reporter, data: any) {
const filename = path.join(this.options.eventReporter.baseDir, `${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 fsPromises.writeFile(filename, JSON.stringify(data), { encoding: 'utf8' });
}

private format(input: number) {
Expand Down
@@ -1,4 +1,4 @@
import { promises as fs } from 'fs';
import { promises as fsPromises } from 'fs';

import { expect } from 'chai';
import chaiJestSnapshot from 'chai-jest-snapshot';
Expand All @@ -22,7 +22,7 @@ describe(`${disableTypeChecks.name} integration`, () => {

async function arrangeAndActAssert(fileName: string, options = createInstrumenterOptions()) {
const fullFileName = resolveTestResource('disable-type-checks', fileName);
const file = new File(fullFileName, await fs.readFile(fullFileName));
const file = new File(fullFileName, await fsPromises.readFile(fullFileName));
const result = await disableTypeChecks(file, options);
chaiJestSnapshot.setFilename(resolveTestResource(`${fileName}.out.snap`));
expect(result.textContent).matchSnapshot();
Expand Down
4 changes: 2 additions & 2 deletions packages/instrumenter/test/integration/parsers.it.spec.ts
@@ -1,4 +1,4 @@
import { promises as fs } from 'fs';
import { promises as fsPromises } from 'fs';

import { expect } from 'chai';

Expand Down Expand Up @@ -73,7 +73,7 @@ describe('parsers integration', () => {

async function act(testResourceFileName: string, options: ParserOptions) {
const fileName = resolveParserTestResource(testResourceFileName);
const input = await fs.readFile(fileName, 'utf8');
const input = await fsPromises.readFile(fileName, 'utf8');
const actual = await createParser(options)(input, fileName);
cleanFileName(actual, testResourceFileName);
return actual;
Expand Down
6 changes: 3 additions & 3 deletions packages/instrumenter/test/integration/printers.it.spec.ts
@@ -1,4 +1,4 @@
import { promises as fs } from 'fs';
import { promises as fsPromises } from 'fs';

import { normalizeWhitespaces } from '@stryker-mutator/util';
import { expect } from 'chai';
Expand All @@ -18,7 +18,7 @@ describe('parse and print integration', () => {

async function actArrangeAndAssert(relativeFileName: string) {
const fileName = resolvePrinterTestResource('echo', relativeFileName);
const code = await fs.readFile(fileName, 'utf8');
const code = await fsPromises.readFile(fileName, 'utf8');
const parsed = await createParser(createParserOptions())(code, fileName);
const output = print(parsed);
expect(normalizeWhitespaces(output)).eq(normalizeWhitespaces(code));
Expand All @@ -32,7 +32,7 @@ describe('parse and print integration', () => {
async function actArrangeAndAssert(testCase: string) {
const inputFileName = resolvePrinterTestResource('html', `${testCase}.in.html`);
const outputFileName = resolvePrinterTestResource('html', `${testCase}.out.html`);
const [input, expectedOutput] = await Promise.all([fs.readFile(inputFileName, 'utf8'), fs.readFile(outputFileName, 'utf8')]);
const [input, expectedOutput] = await Promise.all([fsPromises.readFile(inputFileName, 'utf8'), fsPromises.readFile(outputFileName, 'utf8')]);
const parsed = await createParser(createParserOptions())(input, inputFileName);
const actualOutput = print(parsed);
expect(normalizeWhitespaces(actualOutput)).eq(normalizeWhitespaces(expectedOutput));
Expand Down