Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"module": "./dist/pdfparser.js",
"types": "./dist/pdfparser.d.ts",
"scripts": {
"test:unit": "node --test --test-timeout=15000 test/_test_.cjs test/_test_cli.cjs test/_test_errors.cjs test/_test_sortBidiTexts.cjs test/_test_stream.cjs test/_test_testMultipleDataPDF.cjs test/_test_type3glyph.cjs",
"test:coverage": "node -e \"fs.mkdirSync('coverage',{recursive:true})\" && node --test --test-timeout=15000 --experimental-test-coverage --test-coverage-exclude=\"test/**\" --test-coverage-exclude=\"base/**\" --test-coverage-exclude=\"lib/pdfjs-code.js\" --test-reporter=spec --test-reporter=lcov --test-reporter-destination=stdout --test-reporter-destination=coverage/lcov.info test/_test_.cjs test/_test_cli.cjs test/_test_errors.cjs test/_test_sortBidiTexts.cjs test/_test_stream.cjs test/_test_testMultipleDataPDF.cjs test/_test_type3glyph.cjs",
"test:unit": "node --test --test-timeout=15000 \"test/_test_*.cjs\"",
"test:coverage": "mkdir -p coverage && node --test --test-timeout=15000 --experimental-test-coverage --test-coverage-exclude=\"test/**\" --test-coverage-exclude=\"base/**\" --test-coverage-exclude=\"lib/pdfjs-code.js\" --test-reporter=spec --test-reporter=lcov --test-reporter-destination=stdout --test-reporter-destination=coverage/lcov.info \"test/_test_*.cjs\"",
"test": "npm run test:unit && npm run parse-r && npm run parse-fd && npm run test:deno && npm run test:bun",
"lint": "eslint .",
"test:forms": "cd ./test && sh p2j.forms.sh",
"test:misc": "cd ./test && sh p2j.one.sh misc . \"Expected: 16 success, 6 fail exception with stack trace\" ",
"test:forms": "cd ./test && bash p2j.forms.sh",
"test:misc": "cd ./test && bash p2j.one.sh misc .",
"parse": "node ./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form",
"parse-s": "node ./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s",
"parse-t": "node ./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s -t",
Expand All @@ -50,10 +50,10 @@
"parse-tc": "node ./bin/pdf2json.js -f ./test/pdf/misc/i293_pdfpac.pdf -o ./test/target/misc",
"parse-rectFix": "node ./bin/pdf2json.js -f ./test/pdf/misc/pr298_rect_fix_from_upstream.pdf -o ./test/target/misc",
"parse-e": "node ./bin/pdf2json.js -f ./test/pdf/misc/i418_precompilato_fake.pdf -o ./test/target/misc -c",
"build:rollup": "npx rollup -c ./rollup.config.js",
"build:rollup": "rollup -c ./rollup.config.js",
"build:bundle-pdfjs-base": "node rollup/bundle-pdfjs-base.js",
"build": "npm run build:bundle-pdfjs-base && npm run build:rollup",
"build:clean": "node -e \"delete process.env.npm_config_allow_scripts; require('node:child_process').execSync('npm ci && npm run build', {stdio: 'inherit'})\"",
"build:clean": "unset npm_config_allow_scripts && npm ci && npm run build",
"test:deno": "deno --allow-read --allow-write --allow-net --allow-env --no-check ./bin/pdf2json.js -f ./test/pdf/fd/form/ -o ./test/target/fd/form -t -c -m -r",
"test:bun": "bun ./bin/pdf2json.js -f ./test/pdf/fd/form/ -o ./test/target/fd/form -t -c -m -r"
},
Expand Down
14 changes: 1 addition & 13 deletions test/p2j.forms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,13 @@ AGENCIES=("dc" "de" "ef" "fd" "nd" "or" "pa" "sc" "va")
FAILED_AGENCIES=()
for i in "${AGENCIES[@]}"
do
sh ./p2j.one.sh $i form "Expected: NO Exception, All Parsed OK"
bash ./p2j.one.sh "$i" form
STATUS=$?
if [ $STATUS -ne 0 ]; then
FAILED_AGENCIES+=("$i")
fi
done

# Travis CI doesn't seem to support arrays in bash for testing.
# Reverting to a bunch of commands so that build button can be shown.
# sh ./p2j.one.sh dc
# sh ./p2j.one.sh de
# sh ./p2j.one.sh ef
# sh ./p2j.one.sh fd
# sh ./p2j.one.sh nd
# sh ./p2j.one.sh or
# sh ./p2j.one.sh pa
# sh ./p2j.one.sh sc
# sh ./p2j.one.sh va

ENDTIME=$(date +%s)
echo "It takes $(($ENDTIME - $STARTTIME)) seconds to process all PDFs ..."

Expand Down
23 changes: 13 additions & 10 deletions test/p2j.one.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/usr/bin/env bash
IN_DIR_BASE=./pdf
OUT_DIR_BASE=./target
DATA_DIR_BASE=./data
PDF2JSON=../bin/pdf2json.js
AGENCY_NAME=$1
FORM_BASE=$2
EXPECTED_RESULT=$3

echo "-----------------------------------------------------"
echo "Clean up existing $AGENCY_NAME JSON"
Expand All @@ -16,25 +14,30 @@ echo "-----------------------------------------------------"
echo "Update $AGENCY_NAME PDF"
echo "-----------------------------------------------------"
mkdir -p $OUT_DIR_BASE/$AGENCY_NAME/$FORM_BASE
node $PDF2JSON -f $IN_DIR_BASE/$AGENCY_NAME/$FORM_BASE -o $OUT_DIR_BASE/$AGENCY_NAME/$FORM_BASE -s -t -c -m
PARSER_OUT=$(node $PDF2JSON -f $IN_DIR_BASE/$AGENCY_NAME/$FORM_BASE -o $OUT_DIR_BASE/$AGENCY_NAME/$FORM_BASE -s -t -c -m 2>&1)
PARSER_EXIT=$?
printf '%s\n' "$PARSER_OUT"

if [ "$AGENCY_NAME" = "misc" ]; then
if [ $PARSER_EXIT -ne 1 ]; then
echo "ERROR: Expected exit code 1 for misc, got $PARSER_EXIT"
exit 1
fi
if [[ "$PARSER_OUT" =~ ([0-9]+)[[:space:]]+input[[:space:]]+files[[:space:]]+([0-9]+)[[:space:]]+success[[:space:]]+([0-9]+)[[:space:]]+fail ]]; then
SUCCESS="${BASH_REMATCH[2]}"
FAIL="${BASH_REMATCH[3]}"
if [ "$SUCCESS" -ne 16 ] || [ "$FAIL" -ne 6 ]; then
echo "ERROR: Expected 16 success, 6 fail for misc, got $SUCCESS success, $FAIL fail"
exit 1
fi
else
echo "ERROR: Could not parse success/failure summary for misc"
exit 1
fi
else
if [ $PARSER_EXIT -ne 0 ]; then
echo "ERROR: PDF parsing failed for $AGENCY_NAME with exit code $PARSER_EXIT"
exit 1
fi
fi

# Baseline diff disabled: test/data contains legacy v0.6.8 structures ({formImage}) and lacks .merged.json; structured equivalence is validated via test/_test_.cjs
# diff -rq $OUT_DIR_BASE/$AGENCY_NAME/$FORM_BASE/ $DATA_DIR_BASE/$AGENCY_NAME/$FORM_BASE/

echo "-----------------------------------------------------"
echo "$IN_DIR_BASE/$AGENCY_NAME/$FORM_BASE : $EXPECTED_RESULT"
echo "-----------------------------------------------------"

Loading