Skip to content

Commit d655ba1

Browse files
authored
Merge pull request #219 from TimothyJones/match-pact-js-lint
Match pact js lint
2 parents 88b35f0 + 291774c commit d655ba1

16 files changed

+168
-64
lines changed

.eslintrc

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"plugins": ["@typescript-eslint", "import", "jest"],
5+
"extends": [
6+
"eslint:recommended",
7+
"plugin:@typescript-eslint/recommended",
8+
"airbnb-base",
9+
"airbnb-typescript/base",
10+
"prettier"
11+
],
12+
"settings": {
13+
"import/resolver": {
14+
"typescript": {
15+
"project": ["tsconfig.json"]
16+
}
17+
}
18+
},
19+
"parserOptions": {
20+
"ecmaVersion": 2018,
21+
"sourceType": "module",
22+
"project": ["tsconfig.json"]
23+
},
24+
"rules": {
25+
"@typescript-eslint/no-unused-vars": "error",
26+
"@typescript-eslint/no-explicit-any": "error",
27+
"@typescript-eslint/no-shadow": "error",
28+
"@typescript-eslint/explicit-module-boundary-types": "error",
29+
"@typescript-eslint/no-empty-function": [
30+
"error",
31+
{ "allow": ["constructors"] }
32+
],
33+
"import/prefer-default-export": "off",
34+
"no-underscore-dangle": "off",
35+
"class-methods-use-this": "off"
36+
},
37+
"overrides": [
38+
{
39+
"files": ["**/*.spec.ts", "**/*.test.ts"],
40+
"env": {
41+
"jest": true
42+
},
43+
"extends": ["plugin:jest/recommended"],
44+
"rules": {
45+
"@typescript-eslint/ban-ts-comment": "off",
46+
"@typescript-eslint/no-explicit-any": "off",
47+
"@typescript-eslint/no-empty-function": "off",
48+
"@typescript-eslint/no-unused-expressions": "off",
49+
"@typescript-eslint/no-unused-vars": [
50+
"error",
51+
{ "varsIgnorePattern": "unused", "argsIgnorePattern": "^_" }
52+
],
53+
"@typescript-eslint/no-var-requires": "off",
54+
"global-require": "off",
55+
"jest/expect-expect": "off",
56+
"import/no-dynamic-require": "off",
57+
"no-console": "off",
58+
"no-new": "off"
59+
}
60+
}
61+
],
62+
"globals": {
63+
"NodeJS": true
64+
}
65+
}

jest.config.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
module.exports = {
2-
globals: {
3-
"ts-jest": {
4-
tsconfig: "tsconfig.json"
5-
}
6-
},
7-
moduleFileExtensions: ["ts", "js", "json"],
2+
moduleFileExtensions: ['ts', 'js', 'json'],
3+
84
transform: {
9-
"^.+\\.(ts|tsx)$": "ts-jest"
5+
'^.+\\.(ts|tsx)$': [
6+
'ts-jest',
7+
{
8+
tsconfig: 'tsconfig.json',
9+
},
10+
],
1011
},
11-
testMatch: ["**/*.test.(ts)"],
12-
testEnvironment: "node",
13-
reporters: ["default", [ "jest-junit", { output: "./coverage/junit/unit" } ]],
14-
watchPathIgnorePatterns: ["pact/logs/*","pact/pacts/*"]
12+
testMatch: ['**/*.test.(ts)'],
13+
testEnvironment: 'node',
14+
reporters: ['default', ['jest-junit', { output: './coverage/junit/unit' }]],
15+
watchPathIgnorePatterns: ['pact/logs/*', 'pact/pacts/*'],
1516
};

package.json

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "a pact adaptor for jest",
55
"main": "dist/index.js",
66
"scripts": {
7-
"lint": "tslint --project . --fix",
7+
"lint": "eslint ./src --ext .ts --config .eslintrc",
8+
"lint:fix": "npm run lint -- --fix",
89
"build": "rimraf dist && tsc --project tsconfig.dist.json",
910
"test": "jest --coverage --runInBand --verbose --coverageReporters=lcov",
1011
"dist": "npm run lint && npm run test && npm run build",
@@ -41,10 +42,20 @@
4142
"@commitlint/config-conventional": "^10.0.0",
4243
"@pact-foundation/pact": "^11.0.2",
4344
"@pact-foundation/pact-js-prettier-config": "^1.0.0",
45+
"@tsconfig/node14": "^1.0.3",
4446
"@types/jest": "^29.2.3",
4547
"@types/supertest": "2.0.8",
48+
"@typescript-eslint/eslint-plugin": "^5.47.0",
49+
"@typescript-eslint/parser": "^5.47.0",
4650
"coveralls": "3.1.1",
4751
"cross-env": "7.0.2",
52+
"eslint": "^8.30.0",
53+
"eslint-config-airbnb-base": "^15.0.0",
54+
"eslint-config-airbnb-typescript": "^17.0.0",
55+
"eslint-config-prettier": "^8.5.0",
56+
"eslint-import-resolver-typescript": "^3.5.2",
57+
"eslint-plugin-import": "^2.26.0",
58+
"eslint-plugin-jest": "^27.1.7",
4859
"husky": "^4.3.8",
4960
"jest": "^29.3.1",
5061
"jest-junit": "14.0.1",
@@ -55,8 +66,6 @@
5566
"supertest": "6.2.3",
5667
"ts-jest": "^29.0.3",
5768
"ts-node": "8.6.2",
58-
"tslint": "5.20.1",
59-
"tslint-config-prettier": "1.18.0",
6069
"typescript": "4.6.4"
6170
},
6271
"peerDependencies": {
@@ -65,8 +74,8 @@
6574
},
6675
"lint-staged": {
6776
"src/**/*.ts": [
68-
"prettier --write",
69-
"tslint --fix"
77+
"npm run format:fix",
78+
"npm run lint:fix"
7079
]
7180
},
7281
"husky": {

src/internal/config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { PactfileWriteMode } from '@pact-foundation/pact';
2-
import { LogLevel } from '@pact-foundation/pact';
1+
import { PactfileWriteMode, LogLevel } from '@pact-foundation/pact';
32
import * as path from 'path';
43
import { JestMessageConsumerOptions, JestPactOptions } from '../types';
54

src/internal/scaffold.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const extendPactWith = <
2020
W extends WrapperFn<O, P>
2121
>(
2222
wrapper: W
23-
) => {
23+
): WrapperWithOnlyAndSkip<O, P> => {
2424
const ret = describePactWith<O, P, W>(
2525
describe,
2626
wrapper

src/pactWith.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const setupProvider = (options: JestPactOptions): Pact => {
1717
};
1818

1919
// This should be moved to pact-js, probably
20-
export const getProviderBaseUrl = (provider: Pact) =>
20+
export const getProviderBaseUrl = (provider: Pact): string =>
2121
provider.mockService
2222
? provider.mockService.baseUrl
2323
: `http://${provider.opts.host}:${provider.opts.port}`;

src/test/fpactwith.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1-
import { Pact } from '@pact-foundation/pact';
1+
import { InteractionObject, Pact } from '@pact-foundation/pact';
2+
import supertest = require('supertest');
23
import { fpactWith } from '../index';
3-
import { getClient, postValidRequest } from './pactwith.test';
4+
5+
const getClient = (provider: Pact) => supertest(provider.mockService.baseUrl);
6+
7+
const postValidRequest: InteractionObject = {
8+
state: 'A pet 1845563262948980200 exists',
9+
uponReceiving: 'A get request to get a pet 1845563262948980200',
10+
willRespondWith: {
11+
status: 200,
12+
},
13+
withRequest: {
14+
method: 'GET',
15+
path: '/v2/pet/1845563262948980200',
16+
headers: { api_key: '[]' },
17+
},
18+
};
419

520
describe('fpactwith', () => {
621
fpactWith(

src/test/messagePactWith.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const { like, term } = Matchers;
2121

2222
const arbitraryPact = (provider: MessageConsumerPact) => {
2323
describe('receive dog event', () => {
24-
it('accepts a valid dog', () => {
25-
return provider
24+
it('accepts a valid dog', () =>
25+
provider
2626
.given('some state')
2727
.expectsToReceive('a request for a dog')
2828
.withContent({
@@ -40,8 +40,7 @@ const arbitraryPact = (provider: MessageConsumerPact) => {
4040
synchronousBodyHandler(
4141
(dogApiHandler as unknown) as (body: AnyJson | Buffer) => void
4242
)
43-
);
44-
});
43+
));
4544
});
4645
};
4746

src/test/pactwith.only.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1-
import { Pact } from '@pact-foundation/pact';
1+
import { InteractionObject, Pact } from '@pact-foundation/pact';
2+
import supertest = require('supertest');
23
import { pactWith } from '../index';
3-
import { getClient, postValidRequest } from './pactwith.test';
4+
5+
const getClient = (provider: Pact) => supertest(provider.mockService.baseUrl);
6+
7+
const postValidRequest: InteractionObject = {
8+
state: 'A pet 1845563262948980200 exists',
9+
uponReceiving: 'A get request to get a pet 1845563262948980200',
10+
willRespondWith: {
11+
status: 200,
12+
},
13+
withRequest: {
14+
method: 'GET',
15+
path: '/v2/pet/1845563262948980200',
16+
headers: { api_key: '[]' },
17+
},
18+
};
419

520
describe('pactwith.only', () => {
621
pactWith.only(

src/test/pactwith.skip.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { pactWith } from '../index';
44
describe('pactwith.skip', () => {
55
pactWith.skip(
66
{ consumer: 'MyConsumer', provider: 'NoOtherProvider' },
7-
(provider: Pact) => {
7+
(_provider: Pact) => {
88
test('the test that should be skipped', () => {
99
throw new Error('tests inside xpactWith should not run');
1010
});

src/test/pactwith.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { InteractionObject, Pact } from '@pact-foundation/pact';
22
import { agent } from 'supertest';
33
import { getProviderBaseUrl, pactWith } from '../index';
44

5-
export const getClient = (provider: Pact) =>
5+
const getClient = (provider: Pact) =>
66
agent(provider.mockService.baseUrl);
7-
const pactPort: number = 5001;
7+
const pactPort = 5001;
88

9-
export const postValidRequest: InteractionObject = {
9+
const postValidRequest: InteractionObject = {
1010
state: 'A pet 1845563262948980200 exists',
1111
uponReceiving: 'A get request to get a pet 1845563262948980200',
1212
willRespondWith: {
@@ -60,7 +60,7 @@ pactWith(
6060
pactWith(
6161
{ consumer: 'MyConsumer', provider: 'pactWith2' },
6262
(provider: Pact) => {
63-
describe('pact integration', () => {
63+
describe('pact integration 2', () => {
6464
beforeEach(() => provider.addInteraction(postValidRequest));
6565

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

73-
describe('provider object', () => {
73+
describe('provider object 2', () => {
7474
beforeEach(() => provider.addInteraction(postValidRequest));
7575

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

8484
test('should return the host on getProviderBaseUrl', () => {
8585
expect(getProviderBaseUrl(provider)).toMatch(
86-
new RegExp('^http://127.0.0.1:\\d{4,5}$')
86+
/^http:\/\/127.0.0.1:\d{4,5}$/
8787
);
8888
return getClient(provider)
8989
.get('/v2/pet/1845563262948980200')

src/test/xpactwith.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { xpactWith } from '../index';
44
describe('xpactwith', () => {
55
xpactWith(
66
{ consumer: 'MyConsumer', provider: 'NoOtherProvider' },
7-
(provider: Pact) => {
7+
(_provider: Pact) => {
88
test('the test that should be skipped', () => {
99
throw new Error('tests inside xpactWith should not run');
1010
});

src/types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { MessageConsumerPact, Pact } from '@pact-foundation/pact';
2-
import { MessageConsumerOptions, PactOptions } from '@pact-foundation/pact';
1+
import {
2+
MessageConsumerPact,
3+
Pact,
4+
MessageConsumerOptions,
5+
PactOptions,
6+
} from '@pact-foundation/pact';
37
import { WrapperWithOnlyAndSkip } from './internal/types';
48

59
interface ExtraOptions {

src/v3/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,17 @@ const describeString = (options: JestPactOptionsV3) =>
8585
export const pactWith = (
8686
options: JestPactOptionsV3,
8787
tests: JestProvidedDescribeFnV3
88-
) => describe(describeString(options), () => jestPactWrapper(options, tests));
88+
): void =>
89+
describe(describeString(options), () => jestPactWrapper(options, tests));
8990

9091
export const xpactWith = (
9192
options: JestPactOptionsV3,
9293
tests: JestProvidedDescribeFnV3
93-
) => xdescribe(describeString(options), () => jestPactWrapper(options, tests));
94+
): void =>
95+
xdescribe(describeString(options), () => jestPactWrapper(options, tests));
9496

9597
export const fpactWith = (
9698
options: JestPactOptionsV3,
9799
tests: JestProvidedDescribeFnV3
98-
) => fdescribe(describeString(options), () => jestPactWrapper(options, tests));
100+
): void =>
101+
fdescribe(describeString(options), () => jestPactWrapper(options, tests));

tsconfig.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
{
2+
"extends": "@tsconfig/node14/tsconfig.json",
23
"compilerOptions": {
3-
"target": "es5",
4-
"module": "commonjs",
4+
"types": ["node", "jest"],
55
"declaration": true,
6-
"outDir": "./dist",
7-
"strict": true,
8-
"rootDir": "./src",
6+
"esModuleInterop": true,
7+
"module": "commonjs",
98
"moduleResolution": "node",
109
"noImplicitAny": true,
10+
"noImplicitReturns": true,
11+
"noImplicitThis": true,
12+
"noPropertyAccessFromIndexSignature": true,
1113
"noUnusedLocals": true,
12-
"esModuleInterop": true
14+
"outDir": "./dist",
15+
"removeComments": true,
16+
"rootDir": "./src",
17+
"skipLibCheck": true,
18+
"sourceMap": true,
19+
"strict": true,
20+
"strictNullChecks": true,
21+
"stripInternal": true,
22+
"suppressImplicitAnyIndexErrors": true
1323
},
1424
"exclude": ["./node_modules/*"],
1525
"include": ["./src/**/*.ts"]

tslint.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)