Skip to content

Commit c5725b5

Browse files
committed
Run tests on Node 18.x, 20.x, 22.x and Bun 1.x
1 parent f516266 commit c5725b5

3 files changed

Lines changed: 86 additions & 38 deletions

File tree

.github/workflows/ci.yml

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,53 @@
1-
name: Node.js CI/CD
1+
name: CI/CD
22

33
on:
44
pull_request:
5-
branches: [ "*" ]
65

76
jobs:
8-
build:
7+
node:
8+
name: Node.js (${{ matrix.node-version }})
9+
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
node-version: [18, 20, 22]
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
23+
- name: Setup Bun
24+
uses: oven-sh/setup-bun@v2
25+
with:
26+
bun-version: latest
27+
28+
- name: Install Dependencies
29+
run: bun install
30+
31+
- name: Run Tests
32+
run: bun run test:node
33+
34+
bun:
35+
name: Bun (${{ matrix.bun-version }})
936
runs-on: ubuntu-latest
10-
outputs:
11-
test-result: ${{ steps.test.outcome }}
37+
strategy:
38+
matrix:
39+
bun-version: [latest]
1240

1341
steps:
14-
- uses: actions/checkout@v3
42+
- uses: actions/checkout@v4
1543

16-
- name: Use Node.js 20.x # Updated for Node 20
17-
uses: actions/setup-node@v3
44+
- name: Setup Bun
45+
uses: oven-sh/setup-bun@v2
1846
with:
19-
node-version: 20.x
47+
bun-version: ${{ matrix.bun-version }}
2048

21-
- name: Run ci
22-
run: npm ci
49+
- name: Install Dependencies
50+
run: bun install
2351

24-
- name: Run tests
25-
id: test
26-
run: npm test
52+
- name: Run Tests
53+
run: bun run test:bun

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
"module": "./dist/pdfparser.js",
3434
"typings": "./pdfparser.d.ts",
3535
"scripts": {
36-
"pretest": "npm run build",
37-
"test:jest": "jest --config ./jest.config.json",
38-
"test": "jest --config ./jest.config.json && npm run parse-r && npm run parse-fd",
36+
"pretest:node": "npm run build",
37+
"test:node": "jest && npm run parse-r && npm run parse-fd",
38+
"pretest:bun": "npm run build",
39+
"test:bun": "bun test && npm run parse-r && npm run parse-fd",
40+
"test": "bun test",
3941
"test:forms": "cd ./test && sh p2j.forms.sh",
4042
"test:misc": "cd ./test && sh p2j.one.sh misc . \"Expected: 14 success, 5 fail exception with stack trace\" ",
4143
"parse": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form",
@@ -52,7 +54,7 @@
5254
"build:rollup": "rollup -c ./rollup.config.js",
5355
"build:bundle-pdfjs-base": "node rollup/bundle-pdfjs-base.js",
5456
"build": "npm run build:bundle-pdfjs-base && npm run build:rollup",
55-
"build:clean": "rm -rf node_modules && rm -f package-lock.json && npm i && npm run build"
57+
"build:clean": "rm -rf node_modules && rm -f package-lock.json && npm install && npm run build"
5658
},
5759
"engines": {
5860
"node": ">=20.18.0",

readme.md

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
![GitHub top language](https://img.shields.io/github/languages/top/modesty/pdf2json)
99
![GitHub last commit](https://img.shields.io/github/last-commit/modesty/pdf2json?color=red)
1010

11-
pdf2json is a [node.js](http://nodejs.org/) module converts binary PDF to JSON and text. Built with [pdf.js](https://github.com/mozilla/pdf.js/), it extracts text content and interactive form elements for server-side processing and command-line use.
11+
pdf2json is a [node.js](https://nodejs.org/) module that converts binary PDF to JSON and text. Built with [pdf.js](https://github.com/mozilla/pdf.js/), it extracts text content and interactive form elements for server-side processing and command-line use.
1212

1313
## Features
1414

@@ -20,45 +20,62 @@ pdf2json is a [node.js](http://nodejs.org/) module converts binary PDF to JSON a
2020

2121
## Install
2222

23-
> npm i pdf2json
23+
You can install it using npm or bun:
2424

25-
Or, install it globally:
25+
```bash
26+
npm install pdf2json
27+
bun add pdf2json
28+
```
2629

27-
> npm i pdf2json -g
30+
If you want to use the `pdf2json` CLI, you can install it globally:
2831

29-
To update with latest version:
32+
```bash
33+
npm install pdf2json -g
34+
bun install pdf2json -g
35+
```
3036

31-
> npm update pdf2json -g
37+
## Usage
3238

33-
To Run in RESTful Web Service or as command line Utility
39+
```javascript
40+
import PDFParser from "pdf2json";
3441

35-
- More details can be found at the bottom of this document.
42+
const pdfParser = new PDFParser();
43+
```
3644

37-
## Test
45+
The module is tested with [Node.js](https://nodejs.org/) 18+ and [Bun](https://bun.sh/) 1+.
3846

39-
After install, run command line:
47+
## Test
4048

41-
> npm test
49+
You can run tests in Bun, or in Node.js using Jest.
4250

43-
`pretest` step builds bundles and source maps for both ES Module and CommonJS, output to `./dist` directory. The Jest test suit is defined in `./test/_test_.cjs` with commonJS, test run will also cover `parse-r` and `parse-fd` with ES Modules via command line.
51+
```bash
52+
bun run test:bun # runs in Bun
53+
bun run test:node # runs in Node.js using Jest
54+
```
4455

45-
The default Jest test suits are essential tests for all PRs. But it only covers a portion of all testing PDFs, for more broader coverage, run:
56+
The `pretest` script builds bundles and source maps for both ES Module and CommonJS, then outputs to `./dist` directory. The test suit is defined in `./test/p2j.test.js` with CommonJS, and will also cover `parse-r` and `parse-fd` with ES Modules via command line.
4657

47-
> npm run test:forms
58+
The default test suits are essential tests for all PRs. But it only covers a portion of all testing PDFs, for more broader coverage, run:
4859

49-
It'll scan and parse _260_ PDF AcroForm files under _*./test/pdf*_, runs with _*-s -t -c -m*_ command line options, generates primary output JSON, additional text content JSON, form fields JSON and merged text file for each PDF. It usually takes ~20s in my MacBook Pro to complete, check _*./test/target/*_ for outputs.
60+
```bash
61+
bun run test:forms
62+
```
5063

51-
_update on 4/27/2024_: parsing 260 PDFs by `npm run test:forms` on M2 Mac takes 7~8s
64+
It'll scan and parse _260_ PDF AcroForm files under _*./test/pdf*_, runs with _*-s -t -c -m*_ command line options, generates primary output JSON, additional text content JSON, form fields JSON and merged text file for each PDF. It usually takes ~8s in my MacBook Pro to complete, check _*./test/target/*_ for outputs.
5265

53-
To run Jest test suits with commonJS bundle only
66+
To run the test suite with CommonJS bundle only, run:
5467

55-
> npm run test:jest
68+
```bash
69+
bun run test
70+
```
5671

5772
### Test Exception Handlings
5873

5974
After install, run command line:
6075

61-
> npm run test:misc
76+
```bash
77+
bun run test:misc
78+
```
6279

6380
It'll scan and parse all PDF files under _*./test/pdf/misc*_, also runs with _*-s -t -c -m*_ command line options, generates primary output JSON, additional text content JSON, form fields JSON and merged text JSON file for 15 PDF fields, 12 are expected to success while the other three's exceptions are expected to catch with stack trace for:
6481

@@ -70,7 +87,9 @@ It'll scan and parse all PDF files under _*./test/pdf/misc*_, also runs with _*-
7087

7188
After install, run command line:
7289

73-
> npm run parse-r
90+
```bash
91+
bun run parse-r
92+
```
7493

7594
It scans 165 PDF files under _*./test/pdf/fd/form/*_, parses with [Stream API](https://nodejs.org/dist/latest-v14.x/docs/api/stream.html), then generates output to _*./test/target/fd/form/*_.
7695

0 commit comments

Comments
 (0)