Skip to content

Commit

Permalink
Make sure mutation test instrumentation would create a compiler error
Browse files Browse the repository at this point in the history
  • Loading branch information
nicojs committed May 6, 2020
1 parent a0fe603 commit ee31ece
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
6 changes: 4 additions & 2 deletions e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ export async function expectMetricsResult(expectedMetricsResult: Partial<Metrics

export async function expectMetrics(expectedMetrics: Partial<Metrics>) {
const actualMetricsResult = await readMutationTestResult();
const actualMetrics: Partial<Metrics> = {};
Object.entries(expectedMetrics).forEach(([key, value]) => {
if (key === 'mutationScore' || key === 'mutationScoreBasedOnCoveredCode') {
expect(parseFloat(actualMetricsResult.metrics[key].toFixed(2))).eq(value);
actualMetrics[key] = parseFloat(actualMetricsResult.metrics[key].toFixed(2));
} else {
expect(actualMetricsResult.metrics).property(key, value);
actualMetrics[key as keyof Metrics] = value;
}
});
expect(actualMetrics).deep.eq(expectedMetrics);
}

export function produceMetrics(metrics: Partial<Metrics>): Metrics {
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/jest-with-ts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-with-ts",
"description": "A test project for using stryker with jest and jest-ts preprocessor",
"description": "A test project for using stryker with jest and jest-ts preprocessor. Inspired by the stryker-dashboard source code.",
"scripts": {
"test": "stryker run",
"posttest": "mocha --require ../../tasks/ts-node-register.js verify/verify.ts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { OptimisticConcurrencyError } from '../errors';
jest.mock('../services/TableServiceAsPromised');

export class FooModel {
public partitionId: string;
public rowId: string;
public bar: number;
public partitionId!: string;
public rowId!: string;
public bar!: number;

public static createPartitionKey(entity: Pick<FooModel, 'partitionId'>): string {
return entity.partitionId;
Expand Down Expand Up @@ -136,7 +136,7 @@ describe(TableStorageMapper.name, () => {
TableServiceAsPromisedModuleMocked.insertEntityMock.mockResolvedValue({ ['.metadata']: { etag: 'next-etag' } });
const expected: FooModel = { bar: 42, partitionId: 'partId', rowId: 'rowId' };
const expectedResult: Result<FooModel> = { model: expected, etag: 'next-etag' };
const result = await helper.sut.insert(expected);
const result: Result<FooModel> = await helper.sut.insert(expected);
expect(result).toEqual(expectedResult);
expect(TableServiceAsPromisedModuleMocked.insertEntityMock).toHaveBeenCalledWith(FooModel.tableName, createRawEntity(expected), {});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class TableStorageMapper<TModel extends object, TPartitionKeyFiel
}
}

public async insert(model: TModel): Promise<Result<TModel>> {
public async insert(model: TModel) {
const entity = this.toEntity(model);
try {
const result = await this.tableService.insertEntity(this.ModelClass.tableName, entity, {});
Expand Down
1 change: 1 addition & 0 deletions e2e/test/jest-with-ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"types": [
"jest"
],
"strict": true,
"typeRoots": [
"./node_modules/@types"
],
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/jest-with-ts/verify/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Verify stryker has ran correctly', () => {
await expectMetrics({
ignored: 0,
killed: 26,
mutationScore: 66.67,
mutationScore: 54.55,
noCoverage: 0,
survived: 13,
timeout: 0,
Expand Down

0 comments on commit ee31ece

Please sign in to comment.