@@ -5,11 +5,14 @@ In this tutorial we are gonna build simplified version of
5
5
watch size of a single file and doesn't support gzip. We are gonna use yarn in this tutorial but you
6
6
can pick npm as well. Lets' start!
7
7
8
+ ## Scaffolding
9
+
8
10
We want our check to be fully reusable so we are gonna create new npm package just for it.
9
11
10
12
``` sh
11
13
mkdir simple-build-size-watcher
12
14
cd simple-build-size-watcher
15
+ # creates package.json
13
16
yarn init -y
14
17
```
15
18
@@ -19,17 +22,24 @@ Let's install codechecks client.
19
22
yarn add --dev @codechecks/client
20
23
```
21
24
22
- Let's start developing index.js file. Our check is just a function that takes a path to a file that
23
- we want to observe and it a default export of a module.
25
+ Let's start developing ` index.js ` file. Our check is just a function that takes options object, in
26
+ this example it's a path to a file that we want to observe. The function is a default export of a
27
+ module.
24
28
25
29
``` js
26
30
const { codechecks } = require (" @codechecks/client" );
27
31
28
- module .exports = function (path ) {
29
- // it's alive!
32
+ module .exports = function ({ path }) {
33
+ // just print out the path
34
+ codechecks .success ({ name: " Simple build size" , shortDescription: path });
30
35
};
31
36
```
32
37
38
+ At this point we have already something very simple that should work. To test it we need to create a
39
+ ` codechecks.yml ` file that actually uses this file.
40
+
41
+ ## Getting real
42
+
33
43
Lets calculate size of a file pointed by a path. After quick visit at stackoverflow we can come up
34
44
with a function getSize:
35
45
@@ -105,7 +115,7 @@ function getSize(path) {
105
115
106
116
That's it. Whole code is placed in ` /example ` directory of this repo.
107
117
108
- ## Testing
118
+ # Testing
109
119
110
120
Because codechecks client is an external dependency that is supposed to be imported by your modules
111
121
this makes testing a little bit harder. We recommend to use jest mocking super powers. Tests for
@@ -114,7 +124,7 @@ this project are part of `/example` dir.
114
124
You can find more complicated example here:
115
125
https://github.com/codechecks/build-size-watcher/tree/master/src/__tests __
116
126
117
- ## Debugging
127
+ # Debugging
118
128
119
129
For compatibility with codechecks client, to provide debug logs use ` debug ` package with
120
130
` codechecks:YOUR_CHECK_NAME ` namespace.
0 commit comments