Skip to content

Commit

Permalink
Merge pull request #936 from notaphplover/chore/add-libraries-mutatio…
Browse files Browse the repository at this point in the history
…n-testing

Add mutation testing
  • Loading branch information
notaphplover committed Feb 3, 2024
2 parents 1fd1e00 + 72dcf68 commit a858b6a
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"checkers": ["typescript"],
"cleanTempDir": "always",
"coverageAnalysis": "perTest",
"disableTypeChecks": "src/**/*.ts",
"jest": {
Expand Down
1 change: 1 addition & 0 deletions packages/backend/libraries/backend-db/stryker.conf.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"checkers": ["typescript"],
"cleanTempDir": "always",
"coverageAnalysis": "perTest",
"disableTypeChecks": "src/**/*.ts",
"jest": {
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/libraries/backend-graphql/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
# test coverage reports
/coverage

# Stryker reports
/reports

# Stryker temp files
/stryker-tmp

# Turborepo files
.turbo/

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getJestTsProjectConfig } from '@cornie-js/backend-jest-config';

const tsGlobalConfig = getJestTsProjectConfig(
'All',
['/node_modules', '.int.spec.ts'],
'.spec.ts',
);

export default tsGlobalConfig;
4 changes: 4 additions & 0 deletions packages/backend/libraries/backend-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
},
"devDependencies": {
"@jest/globals": "29.7.0",
"@stryker-mutator/core": "8.2.3",
"@stryker-mutator/jest-runner": "8.2.3",
"@stryker-mutator/typescript-checker": "8.2.3",
"@types/node": "20.11.16",
"@typescript-eslint/eslint-plugin": "6.20.0",
"@typescript-eslint/parser": "6.20.0",
Expand Down Expand Up @@ -48,6 +51,7 @@
"test:integration:js": "pnpm run test:js --selectProjects Integration",
"test:js": "jest --config=jest.js.config.mjs --runInBand",
"test:js:coverage": "pnpm run test:js --coverage",
"test:mutation": "stryker run",
"test:uncommitted": "pnpm run test --changedSince=HEAD",
"test:unit:js": "pnpm run test:js --selectProjects Unit"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,89 @@ describe(GraphQlErrorFromErrorBuilder.name, () => {
});

describe('.build', () => {
let appErrorFixture: AppError;
let statusCodeFixture: number;
describe.each<[unknown]>([[undefined], [null], [{}]])(
'having a non AppError',
(errorFixture: unknown) => {
describe('when called', () => {
let result: unknown;

beforeAll(() => {
appErrorFixture = new AppError(AppErrorKind.contractViolation);
statusCodeFixture = HttpStatus.ACCEPTED;
});
beforeAll(() => {
result = graphQlErrorFromAppErrorBuilder.build(errorFixture);
});

describe('when called', () => {
let result: unknown;
afterAll(() => {
jest.clearAllMocks();
});

beforeAll(() => {
httpStatusCodeFromErrorBuilderMock.build.mockReturnValueOnce(
statusCodeFixture,
);
it('should return a GraphQLError', () => {
const expectedProperties: Partial<GraphQLError> = {
extensions: {
http: {
status: HttpStatus.INTERNAL_SERVER_ERROR,
},
},
};

result = graphQlErrorFromAppErrorBuilder.build(appErrorFixture);
});
expect(result).toBeInstanceOf(GraphQLError);
expect(result).toStrictEqual(
expect.objectContaining(expectedProperties),
);
});
});
},
);

afterAll(() => {
jest.clearAllMocks();
});
describe('having an AppError', () => {
let appErrorFixture: AppError;

it('should call httpStatusCodeFromErrorBuilder.build()', () => {
expect(httpStatusCodeFromErrorBuilderMock.build).toHaveBeenCalledTimes(
1,
);
expect(httpStatusCodeFromErrorBuilderMock.build).toHaveBeenCalledWith(
appErrorFixture,
);
beforeAll(() => {
appErrorFixture = new AppError(AppErrorKind.contractViolation);
});

it('should return a GraphQLError', () => {
const expectedProperties: Partial<GraphQLError> = {
extensions: {
code: 'API_ERROR',
http: {
status: statusCodeFixture,
describe('when called', () => {
let statusCodeFixture: number;

let result: unknown;

beforeAll(() => {
statusCodeFixture = HttpStatus.ACCEPTED;

httpStatusCodeFromErrorBuilderMock.build.mockReturnValueOnce(
statusCodeFixture,
);

result = graphQlErrorFromAppErrorBuilder.build(appErrorFixture);
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call httpStatusCodeFromErrorBuilder.build()', () => {
expect(
httpStatusCodeFromErrorBuilderMock.build,
).toHaveBeenCalledTimes(1);
expect(httpStatusCodeFromErrorBuilderMock.build).toHaveBeenCalledWith(
appErrorFixture,
);
});

it('should return a GraphQLError', () => {
const expectedProperties: Partial<GraphQLError> = {
extensions: {
code: 'API_ERROR',
http: {
status: statusCodeFixture,
},
},
},
message: appErrorFixture.message,
};

expect(result).toBeInstanceOf(GraphQLError);
expect(result).toStrictEqual(
expect.objectContaining(expectedProperties),
);
message: appErrorFixture.message,
};

expect(result).toBeInstanceOf(GraphQLError);
expect(result).toStrictEqual(
expect.objectContaining(expectedProperties),
);
});
});
});
});
Expand Down
24 changes: 24 additions & 0 deletions packages/backend/libraries/backend-graphql/stryker.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"checkers": ["typescript"],
"cleanTempDir": "always",
"coverageAnalysis": "perTest",
"disableTypeChecks": "src/**/*.ts",
"jest": {
"configFile": "./jest.config.stryker.mjs",
"enableFindRelatedTests": true,
"projectType": "custom"
},
"mutate": [
"src/**/*.ts",
"!src/**/*.spec.ts",
"!src/**/*{Fixtures,Mocks}.ts"
],
"packageManager": "pnpm",
"plugins": [
"@stryker-mutator/jest-runner",
"@stryker-mutator/typescript-checker"
],
"tempDirName": "stryker-tmp",
"testRunner": "jest",
"tsconfigFile": "./tsconfig.json"
}
6 changes: 6 additions & 0 deletions packages/backend/libraries/backend-http/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
# test coverage reports
/coverage

# Stryker reports
/reports

# Stryker temp files
/stryker-tmp

# Turborepo files
.turbo/
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getJestTsProjectConfig } from '@cornie-js/backend-jest-config';

const tsGlobalConfig = getJestTsProjectConfig(
'All',
['/node_modules', '.int.spec.ts'],
'.spec.ts',
);

export default tsGlobalConfig;
4 changes: 4 additions & 0 deletions packages/backend/libraries/backend-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
},
"devDependencies": {
"@jest/globals": "29.7.0",
"@stryker-mutator/core": "8.2.3",
"@stryker-mutator/jest-runner": "8.2.3",
"@stryker-mutator/typescript-checker": "8.2.3",
"@types/node": "20.11.16",
"@typescript-eslint/eslint-plugin": "6.20.0",
"@typescript-eslint/parser": "6.20.0",
Expand Down Expand Up @@ -51,6 +54,7 @@
"test:integration:js": "pnpm run test:js --selectProjects Integration",
"test:js": "jest --config=jest.js.config.mjs --runInBand",
"test:js:coverage": "pnpm run test:js --coverage",
"test:mutation": "stryker run",
"test:uncommitted": "pnpm run test --changedSince=HEAD",
"test:unit:js": "pnpm run test:js --selectProjects Unit"
},
Expand Down
24 changes: 24 additions & 0 deletions packages/backend/libraries/backend-http/stryker.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"checkers": ["typescript"],
"cleanTempDir": "always",
"coverageAnalysis": "perTest",
"disableTypeChecks": "src/**/*.ts",
"jest": {
"configFile": "./jest.config.stryker.mjs",
"enableFindRelatedTests": true,
"projectType": "custom"
},
"mutate": [
"src/**/*.ts",
"!src/**/*.spec.ts",
"!src/**/*{Fixtures,Mocks}.ts"
],
"packageManager": "pnpm",
"plugins": [
"@stryker-mutator/jest-runner",
"@stryker-mutator/typescript-checker"
],
"tempDirName": "stryker-tmp",
"testRunner": "jest",
"tsconfigFile": "./tsconfig.json"
}
6 changes: 6 additions & 0 deletions packages/backend/libraries/backend-jwt/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
# test coverage reports
/coverage

# Stryker reports
/reports

# Stryker temp files
/stryker-tmp

# Turborepo files
.turbo/
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getJestTsProjectConfig } from '@cornie-js/backend-jest-config';

const tsGlobalConfig = getJestTsProjectConfig(
'All',
['/node_modules', '.int.spec.ts'],
'.spec.ts',
);

export default tsGlobalConfig;
4 changes: 4 additions & 0 deletions packages/backend/libraries/backend-jwt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
},
"devDependencies": {
"@jest/globals": "29.7.0",
"@stryker-mutator/core": "8.2.3",
"@stryker-mutator/jest-runner": "8.2.3",
"@stryker-mutator/typescript-checker": "8.2.3",
"@types/node": "20.11.16",
"@typescript-eslint/eslint-plugin": "6.20.0",
"@typescript-eslint/parser": "6.20.0",
Expand Down Expand Up @@ -47,6 +50,7 @@
"test:integration:js": "pnpm run test:js --selectProjects Integration",
"test:js": "jest --config=jest.js.config.mjs --runInBand",
"test:js:coverage": "pnpm run test:js --coverage",
"test:mutation": "stryker run",
"test:uncommitted": "pnpm run test --changedSince=HEAD",
"test:unit:js": "pnpm run test:js --selectProjects Unit"
},
Expand Down
24 changes: 24 additions & 0 deletions packages/backend/libraries/backend-jwt/stryker.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"checkers": ["typescript"],
"cleanTempDir": "always",
"coverageAnalysis": "perTest",
"disableTypeChecks": "src/**/*.ts",
"jest": {
"configFile": "./jest.config.stryker.mjs",
"enableFindRelatedTests": true,
"projectType": "custom"
},
"mutate": [
"src/**/*.ts",
"!src/**/*.spec.ts",
"!src/**/*{Fixtures,Mocks}.ts"
],
"packageManager": "pnpm",
"plugins": [
"@stryker-mutator/jest-runner",
"@stryker-mutator/typescript-checker"
],
"tempDirName": "stryker-tmp",
"testRunner": "jest",
"tsconfigFile": "./tsconfig.json"
}

0 comments on commit a858b6a

Please sign in to comment.