1 | # Package
|
2 |
|
3 | ## Installation
|
4 |
|
5 | ```
|
6 | npm install --save-dev @mishguru/package
|
7 | ```
|
8 |
|
9 | ## Recommended Scripts
|
10 |
|
11 | Copy 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 |
|
26 | To 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 |
|
35 | If you need to use a 3rd party library that doesn't have typescript support,
|
36 | you can provide your own type declarations.
|
37 |
|
38 | There are some strict rules you need to follow for this to work:
|
39 |
|
40 | 1. You must only mock one dependency per file.
|
41 | 1. You must place the file inside the `./src/types/` folder.
|
42 | 2. The filename must be the same as the dependency name.
|
43 | 3. The extension must be `.d.ts`.
|
44 |
|
45 | For example, if you are providing types for `file-exists`, the types must be
|
46 | saved in `./src/types/file-exists.d.ts.`
|
47 |
|
48 | ### Providing Typescript types for a project written in JS
|
49 |
|
50 | If you are manually adding types for a non-typescript project, you must keep
|
51 | your 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
|
54 | contains the value: `"types": "types.d.ts"`.
|
55 |
|
56 | ## Lifecycle Test Helpers
|
57 |
|
58 | AVA does not support "before all" or "after all" functions, because it runs
|
59 | everything in parallel.
|
60 |
|
61 | Package has got your back though. If you need to setup/teardown a database,
|
62 | then this is for you.
|
63 |
|
64 | Please note, that if you run AVA in watch mode, the "after all" function will
|
65 | not be called until you exit AVA.
|
66 |
|
67 | ### Before All
|
68 |
|
69 | Create a file called `testHelpers/beforeAll.js` in the root of your project,
|
70 | and it will be executed before the tests begin.
|
71 |
|
72 | ### After All
|
73 |
|
74 | Create a file called `testHelpers/afterAll.js` in the root of your project,
|
75 | and it will be executed after the tests finish.
|
76 |
|
77 | It will be called regardless of whether the tests passed or failed.
|
78 |
|
79 | ## Different Folder Structure
|
80 |
|
81 | ### srcPath
|
82 |
|
83 | If your code is kept in a folder that isn't `src` then you can change the path
|
84 | by adding the following to your `package.json`
|
85 |
|
86 | ```
|
87 | "srcPath": "lib",
|
88 | ```
|
89 |
|
90 | ### distPath
|
91 |
|
92 | Would 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 |
|
100 | Tests must be defined inside the `srcPath`, and by default match any files that
|
101 | end in `.spec.js`.
|
102 |
|
103 | ```
|
104 | "testsPath": "**/*.test.js",
|
105 | ```
|