UNPKG

2.55 kBMarkdownView Raw
1# Package
2
3## Installation
4
5```
6npm install --save-dev @mishguru/package
7```
8
9## Recommended Scripts
10
11Copy the following into your `package.json`.
12
13```json
14"scripts": {
15 "build": "pkg-build",
16 "lint": "pkg-lint",
17 "tidy": "pkg-tidy",
18 "test": "NODE_ENV=test pkg-test",
19 "coverage": "NODE_ENV=test pkg-coverage",
20 "precommit": "pkg-precommit"
21}
22```
23
24## Using Typescript
25
26To enable typescipt support, set the `types` property in your `package.json`.
27
28```json
29"main": "./dist/index.js",
30"types": "./dist/index.d.ts",
31```
32
33### Type declarations
34
35If you need to use a 3rd party library that doesn't have typescript support,
36you can provide your own type declarations.
37
38There are some strict rules you need to follow for this to work:
39
401. You must only mock one dependency per file.
411. You must place the file inside the `./src/types/` folder.
422. The filename must be the same as the dependency name.
433. The extension must be `.d.ts`.
44
45For example, if you are providing types for `file-exists`, the types must be
46saved in `./src/types/file-exists.d.ts.`
47
48### Providing Typescript types for a project written in JS
49
50If you are manually adding types for a non-typescript project, you must keep
51your types in the root of your project, in a file named `types.d.ts`.
52
53`@mishguru/package` will not use the typescript compiler if your package.json
54contains the value: `"types": "types.d.ts"`.
55
56## Lifecycle Test Helpers
57
58AVA does not support "before all" or "after all" functions, because it runs
59everything in parallel.
60
61Package has got your back though. If you need to setup/teardown a database,
62then this is for you.
63
64Please note, that if you run AVA in watch mode, the "after all" function will
65not be called until you exit AVA.
66
67### Before All
68
69Create a file called `testHelpers/beforeAll.js` in the root of your project,
70and it will be executed before the tests begin.
71
72### After All
73
74Create a file called `testHelpers/afterAll.js` in the root of your project,
75and it will be executed after the tests finish.
76
77It will be called regardless of whether the tests passed or failed.
78
79## Different Folder Structure
80
81### srcPath
82
83If your code is kept in a folder that isn't `src` then you can change the path
84by adding the following to your `package.json`
85
86```
87"srcPath": "lib",
88```
89
90### distPath
91
92Would you like your compiled code to be in a folder that isn't named `dist`?
93
94```
95"distPath": "public"
96```
97
98### testsPath
99
100Tests must be defined inside the `srcPath`, and by default match any files that
101end in `.spec.js`.
102
103```
104"testsPath": "**/*.test.js",
105```