test-fns 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Uladzimir Kasacheuski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ export declare const given: (desc: string, fn: () => Promise<void> | void) => void;
2
+ export declare const when: (desc: string, fn: () => Promise<void> | void) => void;
3
+ export declare const then: (desc: string, fn: () => Promise<void> | void) => void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.then = exports.when = exports.given = void 0;
4
+ const given = (desc, fn) => describe(`given: ${desc}`, fn);
5
+ exports.given = given;
6
+ const when = (desc, fn) => describe(`when: ${desc}`, fn);
7
+ exports.when = when;
8
+ const then = (desc, fn) => test(`then: ${desc}`, fn);
9
+ exports.then = then;
10
+ //# sourceMappingURL=givenWhenThen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"givenWhenThen.js","sourceRoot":"","sources":["../src/givenWhenThen.ts"],"names":[],"mappings":";;;AAAO,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAA8B,EAAQ,EAAE,CAC1E,QAAQ,CAAC,UAAU,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;AADpB,QAAA,KAAK,SACe;AAC1B,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,EAA8B,EAAQ,EAAE,CACzE,QAAQ,CAAC,SAAS,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;AADnB,QAAA,IAAI,QACe;AACzB,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,EAA8B,EAAQ,EAAE,CACzE,IAAI,CAAC,SAAS,IAAI,EAAE,EAAE,EAAS,CAAC,CAAC;AADtB,QAAA,IAAI,QACkB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const givenWhenThen_1 = require("./givenWhenThen");
4
+ const doesPlantNeedWater = (plant) => plant.hydration === 'DRY';
5
+ describe('doesPlantNeedWater', () => {
6
+ (0, givenWhenThen_1.given)('a plant', () => {
7
+ (0, givenWhenThen_1.when)('the plant doesnt have enough water', () => {
8
+ const plant = {
9
+ id: 7,
10
+ hydration: 'DRY',
11
+ };
12
+ (0, givenWhenThen_1.then)('it should return true', () => {
13
+ expect(doesPlantNeedWater(plant)).toEqual(true);
14
+ });
15
+ });
16
+ });
17
+ });
18
+ //# sourceMappingURL=givenWhenThen.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"givenWhenThen.test.js","sourceRoot":"","sources":["../src/givenWhenThen.test.ts"],"names":[],"mappings":";;AAAA,mDAAoD;AAGpD,MAAM,kBAAkB,GAAG,CAAC,KAAY,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC;AAEvE,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,IAAA,qBAAK,EAAC,SAAS,EAAE,GAAG,EAAE;QACpB,IAAA,oBAAI,EAAC,oCAAoC,EAAE,GAAG,EAAE;YAC9C,MAAM,KAAK,GAAU;gBACnB,EAAE,EAAE,CAAC;gBACL,SAAS,EAAE,KAAK;aACjB,CAAC;YACF,IAAA,oBAAI,EAAC,uBAAuB,EAAE,GAAG,EAAE;gBACjC,MAAM,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "test-fns",
3
+ "author": "ehmpathy",
4
+ "description": "write usecase driven tests systematically for simpler, safer, and more readable code",
5
+ "version": "1.0.0",
6
+ "repository": "ehmpathy/test-fns",
7
+ "homepage": "https://github.com/ehmpathy/test-fns",
8
+ "keywords": [
9
+ "test",
10
+ "usecase",
11
+ "given",
12
+ "when",
13
+ "then",
14
+ "behavior"
15
+ ],
16
+ "bugs": "https://github.com/ehmpathy/test-fns/issues",
17
+ "main": "dist/index.js",
18
+ "engines": {
19
+ "node": ">=8.0.0"
20
+ },
21
+ "files": [
22
+ "/dist"
23
+ ],
24
+ "scripts": {
25
+ "commit:with-cli": "npx cz",
26
+ "fix:format:prettier": "prettier --write '**/*.ts' --config ./prettier.config.js",
27
+ "fix:format": "npm run fix:format:prettier",
28
+ "fix:lint": "eslint -c ./.eslintrc.js src/**/*.ts --fix",
29
+ "build:artifact": "echo 'no artifact'",
30
+ "build:clean": "rm dist/ -rf",
31
+ "build:compile": "tsc -p ./tsconfig.build.json",
32
+ "build": "npm run build:clean && npm run build:compile",
33
+ "test:commits": "LAST_TAG=$(git describe --tags --abbrev=0 @^ 2> /dev/null || git rev-list --max-parents=0 HEAD) && npx commitlint --from $LAST_TAG --to HEAD --verbose",
34
+ "test:types": "tsc -p ./tsconfig.build.json --noEmit",
35
+ "test:format:prettier": "prettier --parser typescript --check 'src/**/*.ts' --config ./prettier.config.js",
36
+ "test:format": "npm run test:format:prettier",
37
+ "test:lint:deps": "npx depcheck -c ./depcheckrc.yml",
38
+ "test:lint:eslint": "eslint -c ./.eslintrc.js src/**/*.ts",
39
+ "test:lint": "npm run test:lint:eslint && npm run test:lint:deps",
40
+ "test:unit": "jest -c ./jest.unit.config.ts --forceExit --verbose --passWithNoTests",
41
+ "test:integration": "jest -c ./jest.integration.config.ts --forceExit --verbose --passWithNoTests",
42
+ "test:acceptance:locally": "npm run build && LOCALLY=true jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests",
43
+ "test": "npm run test:commits && npm run test:types && npm run test:format && npm run test:lint && npm run test:unit && npm run test:integration && npm run test:acceptance:locally",
44
+ "test:acceptance": "npm run build && jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests",
45
+ "prepush": "npm run test && npm run build",
46
+ "prepublish": "npm run build",
47
+ "preversion": "npm run prepush",
48
+ "postversion": "git push origin HEAD --tags --no-verify",
49
+ "postinstall": "[ -d .git ] && npx husky install || exit 0"
50
+ },
51
+ "devDependencies": {
52
+ "@commitlint/cli": "17.7.1",
53
+ "@commitlint/config-conventional": "13.1.0",
54
+ "@trivago/prettier-plugin-sort-imports": "2.0.4",
55
+ "@tsconfig/node-lts-strictest": "18.12.1",
56
+ "@types/jest": "29.2.4",
57
+ "@typescript-eslint/eslint-plugin": "5.46.1",
58
+ "@typescript-eslint/parser": "5.46.1",
59
+ "core-js": "3.26.1",
60
+ "cz-conventional-changelog": "3.3.0",
61
+ "declapract": "0.11.2",
62
+ "declapract-typescript-ehmpathy": "0.27.2",
63
+ "depcheck": "1.4.3",
64
+ "eslint": "8.30.0",
65
+ "eslint-config-airbnb-typescript": "17.0.0",
66
+ "eslint-config-prettier": "8.5.0",
67
+ "eslint-plugin-import": "2.26.0",
68
+ "eslint-plugin-prettier": "4.2.1",
69
+ "husky": "8.0.3",
70
+ "jest": "29.3.1",
71
+ "prettier": "2.8.1",
72
+ "ts-jest": "29.0.3",
73
+ "ts-node": "10.9.1",
74
+ "typescript": "4.9.4"
75
+ },
76
+ "config": {
77
+ "commitizen": {
78
+ "path": "./node_modules/cz-conventional-changelog"
79
+ }
80
+ },
81
+ "license": "MIT"
82
+ }
package/readme.md ADDED
@@ -0,0 +1,52 @@
1
+ # test-fns
2
+
3
+ ![ci_on_commit](https://github.com/ehmpathy/test-fns/workflows/ci_on_commit/badge.svg)
4
+ ![deploy_on_tag](https://github.com/ehmpathy/test-fns/workflows/deploy_on_tag/badge.svg)
5
+
6
+ write usecase driven tests systematically for simpler, safer, and more readable code
7
+
8
+ # purpose
9
+
10
+ establishes a pattern of writing tests for simpler, safer, and more readable code.
11
+
12
+ by defining tests in terms of usecases (`given`, `when`, `then`) your tests are
13
+ - simpler to write
14
+ - easier to read
15
+ - safer to trust
16
+
17
+ # install
18
+
19
+ ```sh
20
+ npm install --save test-fns
21
+ ```
22
+
23
+ # use
24
+
25
+ ```ts
26
+ type Plant = { id: number, hydration: 'DRY' | 'WET' };
27
+ const doesPlantNeedWater = (plant: Plant) => plant.hydration === 'DRY';
28
+
29
+ describe('doesPlantNeedWater', () => {
30
+ given('a plant', () => {
31
+ when('the plant doesnt have enough water', () => {
32
+ const plant: Plant = {
33
+ id: 7,
34
+ hydration: 'DRY',
35
+ };
36
+ then('it should return true', () => {
37
+ expect(doesPlantNeedWater(plant)).toEqual(true)
38
+ })
39
+ })
40
+ })
41
+ })
42
+ ```
43
+
44
+ produces
45
+
46
+ ```sh
47
+ PASS src/givenWhenThen.test.ts
48
+ doesPlantNeedWater
49
+ given: a plant
50
+ when: the plant doesnt have enough water
51
+ ✓ then: it should return true (1 ms)
52
+ ```