Skip to content

Commit 8b4aacf

Browse files
committed
test(e2e): adds e2e tests using snapshot images
Implements integration tests with Jest for testing snapshots of PS and SVG images, and image snapshots of PNG ones. Updates documentation with relevant examples from e2e tests.
1 parent 3bd4855 commit 8b4aacf

File tree

89 files changed

+2107
-1219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2107
-1219
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ build
77
.zint
88
lib
99
.nyc_output
10+
test/e2e/__rendered__/*
11+
!test/e2e/__rendered__/.keep

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
test
2+
docs
3+
build
4+
lib
5+
.zint
6+
.github

commitlint.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
module.exports = {extends: ['@commitlint/config-conventional']}
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional']
3+
}

docs/guide/symbologies/one-dimensional.md

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ One-Dimensional symbols are what most people associate with the term barcode. Th
88

99
Developed by Intermec in 1977, Code 11 is similar to [Code 2 of 5 Matrix](#code-2-of-5) and is primarily used in telecommunications. The symbol can encode any length string consisting of the digits `0-9` and the dash character (`-`). One modulo-11 check digit is calculated.
1010

11+
#### Example
12+
13+
The following will render a Code 11 symbol encoding `8765432164`:
14+
15+
```js
16+
symbology.createStream({
17+
symbology: symbology.Barcode.CODE11
18+
}, '8765432164')
19+
```
20+
1121
## Code 2 of 5
1222

1323
![ITF-14](/assets/barcodes/barcode_15.png)
@@ -18,6 +28,17 @@ Code 2 of 5 is a family of one-dimensional symbols, 8 of which are supported. No
1828

1929
Also known as **Code 2 of 5 Matrix**, this symbology is a self-checking code used in industrial applications and photo development. Standard Code 2 of 5 will encode any length numeric input (digits `0-9`).
2030

31+
#### Example
32+
33+
The following will render a standard Code 2 of 5 symbol encoding `32109876543211`:
34+
35+
```js
36+
symbology.createStream({
37+
symbology: symbology.Barcode.C25IATA,
38+
borderWidth: 6
39+
}, '32109876543211')
40+
```
41+
2142
### IATA Code 2 of 5
2243

2344
Used for baggage handling in the air-transport industry by the International Air Transport Agency, this self-checking code will encode any length numeric input (digits `0-9`) and does not include a check digit.
@@ -58,9 +79,9 @@ UPC-A is used in the United States for retail applications. The symbol requires
5879

5980
```js
6081
symbology.createStream({
61-
symbology: Symbology.Barcode.UPCA,
62-
mode: 1, // TODO
63-
primary: '331234567890', // TODO
82+
symbology: symbology.Barcode.UPCA,
83+
mode: 1,
84+
primary: '331234567890'
6485
}, '72527270270+12345')
6586
```
6687

@@ -80,7 +101,7 @@ This library also supports Number System 1 encoding by entering a 7-digit articl
80101

81102
```js
82103
symbology.createStream({
83-
symbology: Symbology.Barcode.UPCE
104+
symbology: symbology.Barcode.UPCE
84105
}, '1123456')
85106
```
86107

@@ -110,7 +131,7 @@ The following example will encode a standalone EAN-5:
110131

111132
```js
112133
symbology.createStream({
113-
symbology: Symbology.Barcode.EANX
134+
symbology: symbology.Barcode.EANX
114135
}, '54321')
115136
```
116137

@@ -162,11 +183,24 @@ The table below shows the options available:
162183
| 3 | Modulo-11 |
163184
| 4 | Modulo-11 & Modulo-10 |
164185

186+
187+
#### Example
188+
189+
The following example will create an MSI Plessey symbol with modulo-10 check digit encoding `7432365`:
190+
191+
```js
192+
symbology.createStream({
193+
symbology: symbology.Barcode.MSI_PLESSEY,
194+
option2: 1
195+
}, '7432365')
196+
```
197+
165198
:::tip Note
166199
Any length numeric (digits `0-9`) input can be encoded.
167200
:::
168201

169202
## Telepen
203+
170204
### Telepen Alpha
171205

172206
![Telepen](/assets/barcodes/barcode_19.png)
@@ -187,6 +221,16 @@ Data can consist of pairs of numbers or pairs consisting of a numerical digit fo
187221

188222
Standard Code 39 was developed in 1974 by Intermec. Input data can be of any length and can include the characters `0-9`, `A-Z`, dash (`-`), full stop (`.`), space (` `), asterisk (`*`), dollar (`$`), slash (`/`), plus (`+`) and percent (`%`).
189223

224+
#### Example
225+
226+
The following example will create a Code 39 symbol with modulo-10 check digit encoding `CODE39`:
227+
228+
```js
229+
symbology.createStream({
230+
symbology: symbology.Barcode.CODE39
231+
}, 'CODE39')
232+
```
233+
190234
:::tip Note
191235
The standard does not require a check digit, but a modulo-43 check digit can be added via `option2`.
192236
:::
@@ -249,6 +293,16 @@ No check digit is generated.
249293

250294
Developed by Laetus, Pharmacode is used for the identification of pharmaceuticals. The symbology is able to encode whole numbers between `3` and `131070`.
251295

296+
#### Example
297+
298+
The following example will create a Pharmacode symbol with modulo-10 check digit encoding `131070`:
299+
300+
```js
301+
symbology.createStream({
302+
symbology: symbology.Barcode.PHARMA
303+
}, '131070')
304+
```
305+
252306
## Code 128
253307

254308
### Standard Code 128 (ISO 15417)
@@ -377,6 +431,17 @@ The maximum values permitted depend on the number of channels used:
377431
| 7 | 000000 | 576688 |
378432
| 8 | 0000000 | 7742862 |
379433

434+
#### Example
435+
436+
The following example renders a 5-channel Channel Code symbol:
437+
438+
```js
439+
symbology.createStream({
440+
symbology: symbology.Barcode.CHANNEL,
441+
option2: 6
442+
}, '12345')
443+
```
444+
380445
:::tip Note
381446
Channel codes `7` and `8` require a processor-intensive algorithm to generate and so response times when generating these codes will be relatively slow.
382-
:::
447+
:::

docs/guide/symbologies/stacked.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ This is a stacked symbology based on [Code 128](one-dimensional.md#code-128) whi
1010

1111
The width of the Codablock-F symbol can be specified via `option2` **or** the height (number of rows) can be specified via `option1`. The encoding of GS1 data in Codablock-F symbols is not supported.
1212

13+
#### Example
14+
15+
The following renders a a 5-row Codablock-F symbol:
16+
17+
```js
18+
symbology.createStream({
19+
symbology: symbology.Barcode.CODABLOCKF,
20+
option1: 5,
21+
}, '11010000100101111011101001000011010100011000101000110001010001100010100011000110011001101100011101011')
22+
```
23+
1324
## Code 16k (EN 12323)
1425

1526
![Code 16K](/assets/barcodes/barcode_27.png)
@@ -40,6 +51,17 @@ The width of the generated PDF417 symbol can be specified by setting `option2` t
4051
A separate symbology ID can be used to encode [Health Industry Barcode (HIBC)](one-dimensional.md#hibc-code-39) data which adds a leading `+` character and a modulo-49 check digit to the encoded data.
4152
:::
4253

54+
#### Example
55+
56+
The following renders a 5-row Codablock-F symbol:
57+
58+
```js
59+
symbology.createStream({
60+
symbology: symbology.Barcode.CODABLOCKF,
61+
option1: 5,
62+
}, '11010000100101111011101001000011010100011000101000110001010001100010100011000110011001101100011101011')
63+
```
64+
4365
## Compact PDF417
4466

4567
Also known as truncated PDF417. Options are the same as for PDF417 above.
@@ -104,8 +126,18 @@ The width of the symbol can be altered by setting `option2` to the desired width
104126
This symbol can be generated with a two-dimensional component to make a composite symbol. For symbols with a 2D component, the number of columns must be at least `2`.
105127
:::
106128

129+
#### Example
130+
131+
```js
132+
symbology.createStream({
133+
symbology: symbology.Barcode.EANX_CC,
134+
option1: 1,
135+
primary: '331234567890'
136+
}, '[99]1234-abcd')
137+
```
138+
107139
## Code 49
108140

109141
![Code 49](/assets/barcodes/barcode_33.png)
110142

111-
Developed in 1987 at Intermec, Code 49 is a cross between UPC and Code 39. It it one of the earliest stacked symbologies and influenced the design of Code 16K a few years later. It supports full 7-bit ASCII input up to a maximum of 49 characters or 81 numeric digits. GS1 data encoding is also supported.
143+
Developed in 1987 at Intermec, Code 49 is a cross between UPC and Code 39. It it one of the earliest stacked symbologies and influenced the design of Code 16K a few years later. It supports full 7-bit ASCII input up to a maximum of 49 characters or 81 numeric digits. GS1 data encoding is also supported.

docs/guide/symbologies/two-dimensional.md

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ Four levels of error correction are available by setting `option1` to one of the
8888
| 3 | Q | Approx 55% of symbol | Approx 25% |
8989
| 4 | H | Approx 65% of symbol | Approx 30% |
9090

91+
#### Example
92+
93+
The following example creates a QR code:
94+
95+
```js
96+
symbology.createStream({
97+
symbology: symbology.Barcode.QRCODE,
98+
option2: 1
99+
}, '12345')
100+
```
101+
91102
### QR Code Size
92103

93104
The size of the symbol can be set to the QR Code version required (1-40). The size of symbol generated can be set by passing `option2` to one of the following input values:
@@ -170,11 +181,11 @@ The following example creates a symbol from data saved in an ISO-8859-2 file:
170181

171182
```js
172183
symbology.createStream({
173-
symbology: Symbology.Barcode.MAXICODE,
184+
symbology: symbology.Barcode.UPNQR,
174185
option1: 2,
175186
borderWidth: 5,
176187
scale: 3,
177-
inputMode: symbology.InputModes.DATA_MODE
188+
inputMode: symbology.Encoding.DATA_MODE
178189
}, 'to je testna črtna koda')
179190
```
180191

@@ -206,7 +217,7 @@ The primary message can be set via the `primary` option. The secondary message u
206217

207218
```js
208219
symbology.createStream({
209-
symbology: Symbology.Barcode.MAXICODE,
220+
symbology: symbology.Barcode.MAXICODE,
210221
option1: 2,
211222
primary: '999999999840012'
212223
}, 'Secondary Message Here')
@@ -228,7 +239,7 @@ Modes `4`, `5`, and `6` do not require a primary message.
228239

229240
```js
230241
symbology.createStream({
231-
symbology: Symbology.Barcode.MAXICODE,
242+
symbology: symbology.Barcode.MAXICODE,
232243
option1: 4
233244
}, 'A MaxiCode Message in Mode 4')
234245
```
@@ -312,6 +323,18 @@ To specify the desired size of the symbol, set `option2` to one of the following
312323
| 17 | 71 x 71 | 35 | 147 x 147 |
313324
| 18 | 75 x 75 | 36 | 151 x 151 |
314325

326+
#### Example
327+
328+
The following will render a 45x45 Aztec Code symbol with 23% error correction capacity:
329+
330+
```js
331+
symbology.createStream({
332+
symbology: symbology.Barcode.AZTEC,
333+
option1: 2,
334+
option2: 11
335+
}, '12345')
336+
```
337+
315338
:::tip Note
316339
The symbols marked with an asterisk (*) in the table below are "compact" symbols, meaning they have a smaller bulls-eye pattern at the centre of the symbol.
317340
:::
@@ -326,6 +349,16 @@ It is not possible to select both symbol size and error correction capacity for
326349

327350
Defined in [ISO/IEC 24778 (Annex A)](https://www.iso.org/standard/41548.html), a truncated version of compact [Aztec Code](l#aztec-code-iso-24778) for encoding whole integers between `0` and `255`. Includes [Reed-Solomon error correction](https://en.wikipedia.org/wiki/Reed%E2%80%93Solomon_error_correction).
328351

352+
#### Example
353+
354+
The following will render an Aztec Runes symbol encoding `123`:
355+
356+
```js
357+
symbology.createStream({
358+
symbology: symbology.Barcode.AZRUNE
359+
}, '123')
360+
```
361+
329362
## Code One
330363

331364
![Code One](/assets/barcodes/barcode_50.png)
@@ -352,6 +385,17 @@ The type can be specified by setting `option2` to one of the following input val
352385
| 9 | S | 8X height | 18 | **N/A** |
353386
| 10 | T | 16X height | 90 | 55 |
354387

388+
#### Example
389+
390+
The following will render a 22x22 Code One symbol encoding `An Example`:
391+
392+
```js
393+
symbology.createStream({
394+
symbology: symbology.Barcode.CODEONE,
395+
option2: 2
396+
}, 'An Example')
397+
```
398+
355399
:::warning Important
356400
* Version `S` symbols can only encode numeric data.
357401
* The widths of version `S` and version `T` symbols are determined by the lengths of their input data.
@@ -405,6 +449,18 @@ The symbol size can be specified by setting the `option2` value to one of the fo
405449
| 12 | 150 x 150 |
406450
| 13 | 162 x 162 |
407451

452+
#### Example
453+
454+
The following will render a 30x30 Grid Matrix symbol with 20% error correction encoding `12345`:
455+
456+
```js
457+
symbology.createStream({
458+
symbology: symbology.Barcode.GRIDMATRIX,
459+
option1: 2,
460+
option2: 2
461+
}, '12345')
462+
```
463+
408464
:::warning Important
409465
If you specify both of these values, this library will make a 'best-fit' attempt to satisfy both conditions.
410466
:::
@@ -419,6 +475,16 @@ DotCode uses a grid of dots in a rectangular formation to encode characters up t
419475

420476
By default, the library will produce a symbol which is approximately square. However, the width of the symbol can be adjusted by setting `option2` to the desired width (in pixels).
421477

478+
#### Example
479+
480+
The following will render a DotCode symbol encoding `12345`:
481+
482+
```js
483+
symbology.createStream({
484+
symbology: symbology.Barcode.DOTCODE
485+
}, '12345')
486+
```
487+
422488
:::warning Important
423489
Outputting DotCode to PNG will require setting the scale of the image to a larger value than the default (~10 pixels) for the dots to be plotted correctly.
424490
:::
@@ -507,6 +573,18 @@ The size of the symbol can be specified by setting `option2` to one of the follo
507573
| 41 | 103 x 103 | 83 | 187 x 187 |
508574
| 42 | 105 x 105 | 84 | 189 x 189 |
509575

576+
#### Example
577+
578+
The following will render a 33x33 Han Xin symbol encoding `12345` with ~23% error correction:
579+
580+
```js
581+
symbology.createStream({
582+
symbology: symbology.Barcode.HANXIN,
583+
option1: 3,
584+
option2: 6
585+
}, '12345')
586+
```
587+
510588
:::warning Important
511589
It is not possible to select both symbol size and error correction capacity for the same symbol. If both options are selected then the error correction capacity selection will be ignored.
512590
:::

0 commit comments

Comments
 (0)