Skip to content

Commit 7f71f5d

Browse files
authored
refactor: switch over to common JS configs and resolve issues (#3)
1 parent d1b17ef commit 7f71f5d

16 files changed

+736
-1507
lines changed

README.md

Lines changed: 140 additions & 140 deletions
Large diffs are not rendered by default.

example/deep-thought.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// eslint-disable-next-line @typescript-eslint/require-await
22
export const calculateAnswer = async (): Promise<number> => {
3-
throw new Error(`calculateAnswer() not implemented`);
4-
};
3+
throw new Error(`calculateAnswer() not implemented`)
4+
}

example/earth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// eslint-disable-next-line @typescript-eslint/require-await
22
export const calculateQuestion = async (answer: number): Promise<string> => {
3-
throw new Error(`calculateQuestion(${answer}) not implemented`);
4-
};
3+
throw new Error(`calculateQuestion(${answer}) not implemented`)
4+
}

example/meaning-of-life.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { vi, describe, afterEach, it, expect } from 'vitest';
2-
import { when } from '../src/vitest-when.ts';
1+
import { vi, describe, afterEach, it, expect } from 'vitest'
2+
import { when } from '../src/vitest-when.ts'
33

4-
import * as deepThought from './deep-thought.ts';
5-
import * as earth from './earth.ts';
6-
import * as subject from './meaning-of-life.ts';
4+
import * as deepThought from './deep-thought.ts'
5+
import * as earth from './earth.ts'
6+
import * as subject from './meaning-of-life.ts'
77

8-
vi.mock('./deep-thought.ts');
9-
vi.mock('./earth.ts');
8+
vi.mock('./deep-thought.ts')
9+
vi.mock('./earth.ts')
1010

1111
describe('get the meaning of life', () => {
1212
afterEach(() => {
13-
vi.resetAllMocks();
14-
});
13+
vi.resetAllMocks()
14+
})
1515

1616
it('should get the answer and the question', async () => {
17-
when(deepThought.calculateAnswer).calledWith().thenResolve(42);
18-
when(earth.calculateQuestion).calledWith(42).thenResolve("What's 6 by 9?");
17+
when(deepThought.calculateAnswer).calledWith().thenResolve(42)
18+
when(earth.calculateQuestion).calledWith(42).thenResolve("What's 6 by 9?")
1919

20-
const result = await subject.createMeaning();
20+
const result = await subject.createMeaning()
2121

22-
expect(result).toEqual({ question: "What's 6 by 9?", answer: 42 });
23-
});
24-
});
22+
expect(result).toEqual({ question: "What's 6 by 9?", answer: 42 })
23+
})
24+
})

example/meaning-of-life.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { calculateAnswer } from './deep-thought.ts';
2-
import { calculateQuestion } from './earth.ts';
1+
import { calculateAnswer } from './deep-thought.ts'
2+
import { calculateQuestion } from './earth.ts'
33

44
export interface Meaning {
5-
question: string;
6-
answer: number;
5+
question: string
6+
answer: number
77
}
88

99
export const createMeaning = async (): Promise<Meaning> => {
10-
const answer = await calculateAnswer();
11-
const question = await calculateQuestion(answer);
10+
const answer = await calculateAnswer()
11+
const question = await calculateQuestion(answer)
1212

13-
return { question, answer };
14-
};
13+
return { question, answer }
14+
}

package.json

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
"name": "vitest-when",
33
"version": "0.1.2",
44
"description": "Stub behaviors of Vitest mock functions with a small, readable API.",
5+
"keywords": [
6+
"tdd",
7+
"testing",
8+
"mocking"
9+
],
10+
"homepage": "https://github.com/mcous/vitest-when#readme",
11+
"bugs": {
12+
"url": "https://github.com/mcous/vitest-when/issues"
13+
},
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/mcous/vitest-when.git"
17+
},
18+
"license": "MIT",
19+
"author": "Michael Cousins <[email protected]> (https://mike.cousins.io)",
520
"type": "module",
621
"exports": {
722
".": {
@@ -15,75 +30,57 @@
1530
"dist",
1631
"src"
1732
],
18-
"publishConfig": {
19-
"access": "public",
20-
"provenance": true
21-
},
22-
"packageManager": "[email protected]",
23-
"author": "Michael Cousins <[email protected]> (https://mike.cousins.io)",
24-
"license": "MIT",
25-
"repository": {
26-
"type": "git",
27-
"url": "https://github.com/mcous/vitest-when.git"
28-
},
29-
"bugs": {
30-
"url": "https://github.com/mcous/vitest-when/issues"
31-
},
32-
"homepage": "https://github.com/mcous/vitest-when#readme",
33-
"keywords": [
34-
"tdd",
35-
"testing",
36-
"mocking"
37-
],
3833
"scripts": {
34+
"_eslint": "eslint --ignore-path .lintignore \"**/*.ts\"",
35+
"_prettier": "prettier --ignore-path .lintignore \"**/*.@(ts|json|yaml|md)\"",
3936
"all": "concurrently -g pnpm:coverage pnpm:build pnpm:check:*",
40-
"build-and-check": "concurrently -g pnpm:build pnpm:check:*",
4137
"build": "tsup --clean --sourcemap --dts --format esm,cjs --target node14 src/vitest-when.ts",
42-
"test": "vitest",
43-
"coverage": "vitest run --coverage",
38+
"build-and-check": "concurrently -g pnpm:build pnpm:check:*",
4439
"check:format": "pnpm run _prettier --check",
4540
"check:lint": "pnpm run _eslint",
4641
"check:types": "vitest typecheck --run",
42+
"coverage": "vitest run --coverage",
4743
"format": "pnpm run _prettier --write && pnpm run _eslint --fix",
48-
"_eslint": "eslint --ignore-path .lintignore \"**/*.ts\"",
49-
"_prettier": "prettier --ignore-path .lintignore \"**/*.@(ts|json|yaml)\""
44+
"test": "vitest"
5045
},
46+
"prettier": "@mcous/prettier-config",
5147
"eslintConfig": {
52-
"extends": "@viamrobotics/eslint-config",
5348
"parserOptions": {
5449
"project": "./tsconfig.json"
5550
},
56-
"settings": {
57-
"import/resolver": {
58-
"typescript": {
59-
"project": "./tsconfig.json"
60-
}
61-
}
62-
}
63-
},
64-
"prettier": "@viamrobotics/prettier-config",
65-
"peerDependencies": {
66-
"vitest": ">=0.31.0 <1.0.0",
67-
"@vitest/expect": ">=0.31.0 <1.0.0"
51+
"extends": "@mcous/eslint-config"
6852
},
6953
"devDependencies": {
70-
"@typescript-eslint/eslint-plugin": "^5.59.5",
71-
"@typescript-eslint/parser": "^5.59.5",
72-
"@viamrobotics/eslint-config": "^0.0.4",
73-
"@viamrobotics/prettier-config": "^0.0.1",
74-
"@viamrobotics/typescript-config": "^0.0.3",
54+
"@mcous/eslint-config": "0.3.3",
55+
"@mcous/prettier-config": "0.3.0",
56+
"@mcous/typescript-config": "0.2.1",
57+
"@typescript-eslint/eslint-plugin": "6.7.4",
58+
"@typescript-eslint/parser": "6.7.4",
7559
"@vitest/coverage-istanbul": "^0.31.0",
7660
"@vitest/expect": "^0.31.0",
7761
"concurrently": "^8.0.1",
78-
"eslint": "^8.40.0",
79-
"eslint-config-prettier": "^8.8.0",
80-
"eslint-import-resolver-typescript": "^3.5.5",
81-
"eslint-plugin-import": "^2.27.5",
82-
"eslint-plugin-sonarjs": "^0.19.0",
83-
"eslint-plugin-unicorn": "^46.0.1",
84-
"prettier": "^2.8.8",
62+
"eslint": "8.51.0",
63+
"eslint-config-prettier": "9.0.0",
64+
"eslint-plugin-promise": "6.1.1",
65+
"eslint-plugin-sonarjs": "0.21.0",
66+
"eslint-plugin-unicorn": "48.0.1",
67+
"prettier": "3.0.3",
8568
"tsup": "^6.7.0",
86-
"typescript": "^5.0.4",
69+
"typescript": "5.2.2",
8770
"vitest": "^0.31.0"
71+
},
72+
"peerDependencies": {
73+
"@vitest/expect": ">=0.31.0 <1.0.0",
74+
"vitest": ">=0.31.0 <1.0.0"
75+
},
76+
"peerDependenciesMeta": {
77+
"@vitest/expect": {
78+
"optional": true
79+
}
80+
},
81+
"packageManager": "[email protected]+sha256.d713a5750e41c3660d1e090608c7f607ad00d1dd5ba9b6552b5f390bf37924e9",
82+
"publishConfig": {
83+
"access": "public",
84+
"provenance": true
8885
}
8986
}

0 commit comments

Comments
 (0)