Skip to content

Commit

Permalink
Merge pull request #219 from TimothyJones/match-pact-js-lint
Browse files Browse the repository at this point in the history
Match pact js lint
  • Loading branch information
YOU54F authored May 9, 2023
2 parents 88b35f0 + 291774c commit d655ba1
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 64 deletions.
65 changes: 65 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "import", "jest"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"airbnb-base",
"airbnb-typescript/base",
"prettier"
],
"settings": {
"import/resolver": {
"typescript": {
"project": ["tsconfig.json"]
}
}
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"project": ["tsconfig.json"]
},
"rules": {
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/no-empty-function": [
"error",
{ "allow": ["constructors"] }
],
"import/prefer-default-export": "off",
"no-underscore-dangle": "off",
"class-methods-use-this": "off"
},
"overrides": [
{
"files": ["**/*.spec.ts", "**/*.test.ts"],
"env": {
"jest": true
},
"extends": ["plugin:jest/recommended"],
"rules": {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ "varsIgnorePattern": "unused", "argsIgnorePattern": "^_" }
],
"@typescript-eslint/no-var-requires": "off",
"global-require": "off",
"jest/expect-expect": "off",
"import/no-dynamic-require": "off",
"no-console": "off",
"no-new": "off"
}
}
],
"globals": {
"NodeJS": true
}
}
23 changes: 12 additions & 11 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
module.exports = {
globals: {
"ts-jest": {
tsconfig: "tsconfig.json"
}
},
moduleFileExtensions: ["ts", "js", "json"],
moduleFileExtensions: ['ts', 'js', 'json'],

transform: {
"^.+\\.(ts|tsx)$": "ts-jest"
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: 'tsconfig.json',
},
],
},
testMatch: ["**/*.test.(ts)"],
testEnvironment: "node",
reporters: ["default", [ "jest-junit", { output: "./coverage/junit/unit" } ]],
watchPathIgnorePatterns: ["pact/logs/*","pact/pacts/*"]
testMatch: ['**/*.test.(ts)'],
testEnvironment: 'node',
reporters: ['default', ['jest-junit', { output: './coverage/junit/unit' }]],
watchPathIgnorePatterns: ['pact/logs/*', 'pact/pacts/*'],
};
19 changes: 14 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "a pact adaptor for jest",
"main": "dist/index.js",
"scripts": {
"lint": "tslint --project . --fix",
"lint": "eslint ./src --ext .ts --config .eslintrc",
"lint:fix": "npm run lint -- --fix",
"build": "rimraf dist && tsc --project tsconfig.dist.json",
"test": "jest --coverage --runInBand --verbose --coverageReporters=lcov",
"dist": "npm run lint && npm run test && npm run build",
Expand Down Expand Up @@ -41,10 +42,20 @@
"@commitlint/config-conventional": "^10.0.0",
"@pact-foundation/pact": "^11.0.2",
"@pact-foundation/pact-js-prettier-config": "^1.0.0",
"@tsconfig/node14": "^1.0.3",
"@types/jest": "^29.2.3",
"@types/supertest": "2.0.8",
"@typescript-eslint/eslint-plugin": "^5.47.0",
"@typescript-eslint/parser": "^5.47.0",
"coveralls": "3.1.1",
"cross-env": "7.0.2",
"eslint": "^8.30.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.7",
"husky": "^4.3.8",
"jest": "^29.3.1",
"jest-junit": "14.0.1",
Expand All @@ -55,8 +66,6 @@
"supertest": "6.2.3",
"ts-jest": "^29.0.3",
"ts-node": "8.6.2",
"tslint": "5.20.1",
"tslint-config-prettier": "1.18.0",
"typescript": "4.6.4"
},
"peerDependencies": {
Expand All @@ -65,8 +74,8 @@
},
"lint-staged": {
"src/**/*.ts": [
"prettier --write",
"tslint --fix"
"npm run format:fix",
"npm run lint:fix"
]
},
"husky": {
Expand Down
3 changes: 1 addition & 2 deletions src/internal/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PactfileWriteMode } from '@pact-foundation/pact';
import { LogLevel } from '@pact-foundation/pact';
import { PactfileWriteMode, LogLevel } from '@pact-foundation/pact';
import * as path from 'path';
import { JestMessageConsumerOptions, JestPactOptions } from '../types';

Expand Down
2 changes: 1 addition & 1 deletion src/internal/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const extendPactWith = <
W extends WrapperFn<O, P>
>(
wrapper: W
) => {
): WrapperWithOnlyAndSkip<O, P> => {
const ret = describePactWith<O, P, W>(
describe,
wrapper
Expand Down
2 changes: 1 addition & 1 deletion src/pactWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const setupProvider = (options: JestPactOptions): Pact => {
};

// This should be moved to pact-js, probably
export const getProviderBaseUrl = (provider: Pact) =>
export const getProviderBaseUrl = (provider: Pact): string =>
provider.mockService
? provider.mockService.baseUrl
: `http://${provider.opts.host}:${provider.opts.port}`;
Expand Down
19 changes: 17 additions & 2 deletions src/test/fpactwith.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import { Pact } from '@pact-foundation/pact';
import { InteractionObject, Pact } from '@pact-foundation/pact';
import supertest = require('supertest');
import { fpactWith } from '../index';
import { getClient, postValidRequest } from './pactwith.test';

const getClient = (provider: Pact) => supertest(provider.mockService.baseUrl);

const postValidRequest: InteractionObject = {
state: 'A pet 1845563262948980200 exists',
uponReceiving: 'A get request to get a pet 1845563262948980200',
willRespondWith: {
status: 200,
},
withRequest: {
method: 'GET',
path: '/v2/pet/1845563262948980200',
headers: { api_key: '[]' },
},
};

describe('fpactwith', () => {
fpactWith(
Expand Down
7 changes: 3 additions & 4 deletions src/test/messagePactWith.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const { like, term } = Matchers;

const arbitraryPact = (provider: MessageConsumerPact) => {
describe('receive dog event', () => {
it('accepts a valid dog', () => {
return provider
it('accepts a valid dog', () =>
provider
.given('some state')
.expectsToReceive('a request for a dog')
.withContent({
Expand All @@ -40,8 +40,7 @@ const arbitraryPact = (provider: MessageConsumerPact) => {
synchronousBodyHandler(
(dogApiHandler as unknown) as (body: AnyJson | Buffer) => void
)
);
});
));
});
};

Expand Down
19 changes: 17 additions & 2 deletions src/test/pactwith.only.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import { Pact } from '@pact-foundation/pact';
import { InteractionObject, Pact } from '@pact-foundation/pact';
import supertest = require('supertest');
import { pactWith } from '../index';
import { getClient, postValidRequest } from './pactwith.test';

const getClient = (provider: Pact) => supertest(provider.mockService.baseUrl);

const postValidRequest: InteractionObject = {
state: 'A pet 1845563262948980200 exists',
uponReceiving: 'A get request to get a pet 1845563262948980200',
willRespondWith: {
status: 200,
},
withRequest: {
method: 'GET',
path: '/v2/pet/1845563262948980200',
headers: { api_key: '[]' },
},
};

describe('pactwith.only', () => {
pactWith.only(
Expand Down
2 changes: 1 addition & 1 deletion src/test/pactwith.skip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { pactWith } from '../index';
describe('pactwith.skip', () => {
pactWith.skip(
{ consumer: 'MyConsumer', provider: 'NoOtherProvider' },
(provider: Pact) => {
(_provider: Pact) => {
test('the test that should be skipped', () => {
throw new Error('tests inside xpactWith should not run');
});
Expand Down
14 changes: 7 additions & 7 deletions src/test/pactwith.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { InteractionObject, Pact } from '@pact-foundation/pact';
import { agent } from 'supertest';
import { getProviderBaseUrl, pactWith } from '../index';

export const getClient = (provider: Pact) =>
const getClient = (provider: Pact) =>
agent(provider.mockService.baseUrl);
const pactPort: number = 5001;
const pactPort = 5001;

export const postValidRequest: InteractionObject = {
const postValidRequest: InteractionObject = {
state: 'A pet 1845563262948980200 exists',
uponReceiving: 'A get request to get a pet 1845563262948980200',
willRespondWith: {
Expand Down Expand Up @@ -60,7 +60,7 @@ pactWith(
pactWith(
{ consumer: 'MyConsumer', provider: 'pactWith2' },
(provider: Pact) => {
describe('pact integration', () => {
describe('pact integration 2', () => {
beforeEach(() => provider.addInteraction(postValidRequest));

test('should be ok if i dont provide a port', () =>
Expand All @@ -70,11 +70,11 @@ pactWith(
.expect(200));
});

describe('provider object', () => {
describe('provider object 2', () => {
beforeEach(() => provider.addInteraction(postValidRequest));

test('should show the randomly assigned port in the URL', () => {
expect(provider.mockService.baseUrl).toMatch(new RegExp(`\\d{4,5}$`));
expect(provider.mockService.baseUrl).toMatch(/\d{4,5}$/);
return getClient(provider)
.get('/v2/pet/1845563262948980200')
.set('api_key', '[]')
Expand All @@ -83,7 +83,7 @@ pactWith(

test('should return the host on getProviderBaseUrl', () => {
expect(getProviderBaseUrl(provider)).toMatch(
new RegExp('^http://127.0.0.1:\\d{4,5}$')
/^http:\/\/127.0.0.1:\d{4,5}$/
);
return getClient(provider)
.get('/v2/pet/1845563262948980200')
Expand Down
2 changes: 1 addition & 1 deletion src/test/xpactwith.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { xpactWith } from '../index';
describe('xpactwith', () => {
xpactWith(
{ consumer: 'MyConsumer', provider: 'NoOtherProvider' },
(provider: Pact) => {
(_provider: Pact) => {
test('the test that should be skipped', () => {
throw new Error('tests inside xpactWith should not run');
});
Expand Down
8 changes: 6 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { MessageConsumerPact, Pact } from '@pact-foundation/pact';
import { MessageConsumerOptions, PactOptions } from '@pact-foundation/pact';
import {
MessageConsumerPact,
Pact,
MessageConsumerOptions,
PactOptions,
} from '@pact-foundation/pact';
import { WrapperWithOnlyAndSkip } from './internal/types';

interface ExtraOptions {
Expand Down
9 changes: 6 additions & 3 deletions src/v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ const describeString = (options: JestPactOptionsV3) =>
export const pactWith = (
options: JestPactOptionsV3,
tests: JestProvidedDescribeFnV3
) => describe(describeString(options), () => jestPactWrapper(options, tests));
): void =>
describe(describeString(options), () => jestPactWrapper(options, tests));

export const xpactWith = (
options: JestPactOptionsV3,
tests: JestProvidedDescribeFnV3
) => xdescribe(describeString(options), () => jestPactWrapper(options, tests));
): void =>
xdescribe(describeString(options), () => jestPactWrapper(options, tests));

export const fpactWith = (
options: JestPactOptionsV3,
tests: JestProvidedDescribeFnV3
) => fdescribe(describeString(options), () => jestPactWrapper(options, tests));
): void =>
fdescribe(describeString(options), () => jestPactWrapper(options, tests));
22 changes: 16 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
{
"extends": "@tsconfig/node14/tsconfig.json",
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"types": ["node", "jest"],
"declaration": true,
"outDir": "./dist",
"strict": true,
"rootDir": "./src",
"esModuleInterop": true,
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noPropertyAccessFromIndexSignature": true,
"noUnusedLocals": true,
"esModuleInterop": true
"outDir": "./dist",
"removeComments": true,
"rootDir": "./src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": true,
"stripInternal": true,
"suppressImplicitAnyIndexErrors": true
},
"exclude": ["./node_modules/*"],
"include": ["./src/**/*.ts"]
Expand Down
16 changes: 0 additions & 16 deletions tslint.json

This file was deleted.

0 comments on commit d655ba1

Please sign in to comment.