Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: switch over to common JS configs and resolve issues #3

Merged
merged 1 commit into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
280 changes: 140 additions & 140 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions example/deep-thought.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// eslint-disable-next-line @typescript-eslint/require-await
export const calculateAnswer = async (): Promise<number> => {
throw new Error(`calculateAnswer() not implemented`);
};
throw new Error(`calculateAnswer() not implemented`)
}
4 changes: 2 additions & 2 deletions example/earth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// eslint-disable-next-line @typescript-eslint/require-await
export const calculateQuestion = async (answer: number): Promise<string> => {
throw new Error(`calculateQuestion(${answer}) not implemented`);
};
throw new Error(`calculateQuestion(${answer}) not implemented`)
}
30 changes: 15 additions & 15 deletions example/meaning-of-life.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { vi, describe, afterEach, it, expect } from 'vitest';
import { when } from '../src/vitest-when.ts';
import { vi, describe, afterEach, it, expect } from 'vitest'
import { when } from '../src/vitest-when.ts'

import * as deepThought from './deep-thought.ts';
import * as earth from './earth.ts';
import * as subject from './meaning-of-life.ts';
import * as deepThought from './deep-thought.ts'
import * as earth from './earth.ts'
import * as subject from './meaning-of-life.ts'

vi.mock('./deep-thought.ts');
vi.mock('./earth.ts');
vi.mock('./deep-thought.ts')
vi.mock('./earth.ts')

describe('get the meaning of life', () => {
afterEach(() => {
vi.resetAllMocks();
});
vi.resetAllMocks()
})

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

const result = await subject.createMeaning();
const result = await subject.createMeaning()

expect(result).toEqual({ question: "What's 6 by 9?", answer: 42 });
});
});
expect(result).toEqual({ question: "What's 6 by 9?", answer: 42 })
})
})
16 changes: 8 additions & 8 deletions example/meaning-of-life.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { calculateAnswer } from './deep-thought.ts';
import { calculateQuestion } from './earth.ts';
import { calculateAnswer } from './deep-thought.ts'
import { calculateQuestion } from './earth.ts'

export interface Meaning {
question: string;
answer: number;
question: string
answer: number
}

export const createMeaning = async (): Promise<Meaning> => {
const answer = await calculateAnswer();
const question = await calculateQuestion(answer);
const answer = await calculateAnswer()
const question = await calculateQuestion(answer)

return { question, answer };
};
return { question, answer }
}
99 changes: 48 additions & 51 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
"name": "vitest-when",
"version": "0.1.2",
"description": "Stub behaviors of Vitest mock functions with a small, readable API.",
"keywords": [
"tdd",
"testing",
"mocking"
],
"homepage": "https://github.com/mcous/vitest-when#readme",
"bugs": {
"url": "https://github.com/mcous/vitest-when/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/mcous/vitest-when.git"
},
"license": "MIT",
"author": "Michael Cousins <[email protected]> (https://mike.cousins.io)",
"type": "module",
"exports": {
".": {
Expand All @@ -15,75 +30,57 @@
"dist",
"src"
],
"publishConfig": {
"access": "public",
"provenance": true
},
"packageManager": "[email protected]",
"author": "Michael Cousins <[email protected]> (https://mike.cousins.io)",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/mcous/vitest-when.git"
},
"bugs": {
"url": "https://github.com/mcous/vitest-when/issues"
},
"homepage": "https://github.com/mcous/vitest-when#readme",
"keywords": [
"tdd",
"testing",
"mocking"
],
"scripts": {
"_eslint": "eslint --ignore-path .lintignore \"**/*.ts\"",
"_prettier": "prettier --ignore-path .lintignore \"**/*.@(ts|json|yaml|md)\"",
"all": "concurrently -g pnpm:coverage pnpm:build pnpm:check:*",
"build-and-check": "concurrently -g pnpm:build pnpm:check:*",
"build": "tsup --clean --sourcemap --dts --format esm,cjs --target node14 src/vitest-when.ts",
"test": "vitest",
"coverage": "vitest run --coverage",
"build-and-check": "concurrently -g pnpm:build pnpm:check:*",
"check:format": "pnpm run _prettier --check",
"check:lint": "pnpm run _eslint",
"check:types": "vitest typecheck --run",
"coverage": "vitest run --coverage",
"format": "pnpm run _prettier --write && pnpm run _eslint --fix",
"_eslint": "eslint --ignore-path .lintignore \"**/*.ts\"",
"_prettier": "prettier --ignore-path .lintignore \"**/*.@(ts|json|yaml)\""
"test": "vitest"
},
"prettier": "@mcous/prettier-config",
"eslintConfig": {
"extends": "@viamrobotics/eslint-config",
"parserOptions": {
"project": "./tsconfig.json"
},
"settings": {
"import/resolver": {
"typescript": {
"project": "./tsconfig.json"
}
}
}
},
"prettier": "@viamrobotics/prettier-config",
"peerDependencies": {
"vitest": ">=0.31.0 <1.0.0",
"@vitest/expect": ">=0.31.0 <1.0.0"
"extends": "@mcous/eslint-config"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.59.5",
"@typescript-eslint/parser": "^5.59.5",
"@viamrobotics/eslint-config": "^0.0.4",
"@viamrobotics/prettier-config": "^0.0.1",
"@viamrobotics/typescript-config": "^0.0.3",
"@mcous/eslint-config": "0.3.3",
"@mcous/prettier-config": "0.3.0",
"@mcous/typescript-config": "0.2.1",
"@typescript-eslint/eslint-plugin": "6.7.4",
"@typescript-eslint/parser": "6.7.4",
"@vitest/coverage-istanbul": "^0.31.0",
"@vitest/expect": "^0.31.0",
"concurrently": "^8.0.1",
"eslint": "^8.40.0",
"eslint-config-prettier": "^8.8.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-sonarjs": "^0.19.0",
"eslint-plugin-unicorn": "^46.0.1",
"prettier": "^2.8.8",
"eslint": "8.51.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-sonarjs": "0.21.0",
"eslint-plugin-unicorn": "48.0.1",
"prettier": "3.0.3",
"tsup": "^6.7.0",
"typescript": "^5.0.4",
"typescript": "5.2.2",
"vitest": "^0.31.0"
},
"peerDependencies": {
"@vitest/expect": ">=0.31.0 <1.0.0",
"vitest": ">=0.31.0 <1.0.0"
},
"peerDependenciesMeta": {
"@vitest/expect": {
"optional": true
}
},
"packageManager": "[email protected]+sha256.d713a5750e41c3660d1e090608c7f607ad00d1dd5ba9b6552b5f390bf37924e9",
"publishConfig": {
"access": "public",
"provenance": true
}
}
Loading