Skip to content

Commit bfcc49c

Browse files
committed
Add node end-to-end tests for bundles
1 parent 5f46627 commit bfcc49c

File tree

112 files changed

+527
-25
lines changed

Some content is hidden

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

112 files changed

+527
-25
lines changed

.eslintignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
node_modules/**/*
1+
node_modules
22
dist

.github/workflows/nodejs.yml

+6-12
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ jobs:
2525
node-version: ${{ matrix.node-version }}
2626
- run: npm ci
2727
- run: npm run lint
28-
- run: npm test
28+
- run: npm run test
29+
- run: npm run test:build
2930
env:
3031
CI: true
3132
- run: npm run build
32-
package-ubuntu:
33+
package-ubuntu-full:
3334
runs-on: ubuntu-latest
3435
steps:
3536
- uses: actions/checkout@v2
@@ -38,18 +39,11 @@ jobs:
3839
with:
3940
node-version: 10.x
4041
- run: npm ci
41-
- name: Test npm package with minimal requirements
42+
- name: Test npm package and custom builds with minimal requirements
4243
run: |
43-
npm pack
44-
PACKAGE="exifreader-$(node -p "require('./package.json').version").tgz"
45-
mkdir my-project
46-
cd my-project
4744
PATH=$(echo "$PATH" | sed -e 's/:\/usr\/local\/bin://'):/usr/local/bin/npm:/usr/local/bin/node
48-
npm init -y
49-
npm install ../$PACKAGE
50-
node -p "const {writeFileSync} = require('fs'); const packageJson = require('./package.json'); packageJson.exifreader = {include: {jpeg: true, exif: true}}; writeFileSync('package.json', JSON.stringify(packageJson));"
51-
npm rebuild exifreader
52-
package-windows:
45+
npm run test:build:custom
46+
package-windows-basic:
5347
runs-on: windows-latest
5448
steps:
5549
- uses: actions/checkout@v2

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ test/cypress/videos
77
.tags
88
.tags1
99
.vscode
10+
exifreader-*.tgz
11+
test/build/tmp
12+
test/fixtures/images/custom_*
13+
test/fixtures/outputs/custom_*

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ Possible modules to include or exclude:
224224
| `tiff` | TIFF images. |
225225
| `png` | PNG images. |
226226
| `heic` | HEIC/HEIF images. |
227-
| `file` | JPEG image width, height etc. |
227+
| `file` | JPEG file details: image width, height etc. |
228+
| `png_file` | PNG file details: image width, height etc. |
228229
| `exif` | Regular Exif tags. If excluded, will also exclude `thumbnail`. For TIFF files, excluding this will also exclude IPTC and XMP. |
229230
| `iptc` | IPTC tags. |
230231
| `xmp` | XMP tags. |

cypress.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"baseUrl": "https://localhost:8080",
3-
"fixturesFolder": "test/cypress/fixtures",
3+
"fixturesFolder": "test/fixtures",
44
"integrationFolder": "test/cypress/integration",
55
"pluginsFile": "test/cypress/plugins/index.js",
66
"screenshotsFolder": "test/cypress/screenshots",

dist/exif-reader.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/exif-reader.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/nodejs/exif.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fs.readFile(filePath, function (error, data) {
2525
}
2626

2727
try {
28-
const tags = ExifReader.load(data.buffer);
28+
const tags = ExifReader.load((new Uint8Array(data)).buffer);
2929

3030
// The MakerNote tag can be really large. Remove it to lower memory
3131
// usage if you're parsing a lot of files and saving the tags.

package-lock.json

+56-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"mocha": "^7.1.1",
4040
"npm-run-all": "^4.1.5",
4141
"nyc": "^14.1.1",
42+
"rimraf": "^3.0.2",
4243
"string-replace-loader": "^2.2.0",
4344
"webpack": "^4.42.0",
4445
"webpack-cli": "^3.3.6",
@@ -52,7 +53,11 @@
5253
"precommit": "npm-run-all lint test",
5354
"start": "webpack-dev-server",
5455
"test": "cross-env BABEL_ENV=test mocha --require @babel/register --recursive \"test/unit/\"",
56+
"test:build": "mocha test/build/test.js",
57+
"test:build:custom": "mocha test/build/test-custom.js",
58+
"test:build:update": "node test/build/update.js",
5559
"test:e2e": "cypress run",
60+
"test:all": "npm-run-all test test:e2e test:build test:build:custom",
5661
"postinstall": "node bin/build.js --only-with-config"
5762
},
5863
"nyc": {

src/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
export default {
66
USE_FILE: true,
7+
USE_PNG_FILE: true,
78
USE_EXIF: true,
89
USE_IPTC: true,
910
USE_XMP: true,

src/exif-reader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export function loadView(dataView, options = {expanded: false}) {
119119
}
120120
}
121121

122-
if (Constants.USE_PNG && hasPngFileData(pngHeaderOffset)) {
122+
if (Constants.USE_PNG && Constants.USE_PNG_FILE && hasPngFileData(pngHeaderOffset)) {
123123
foundMetaData = true;
124124
const readTags = PngFileTags.read(dataView, pngHeaderOffset);
125125
if (options.expanded) {

src/image-header-png.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ function findPngOffsets(dataView) {
2828
const offsets = {
2929
hasAppMarkers: false
3030
};
31+
3132
let offset = PNG_ID.length;
3233

3334
while (offset + PNG_CHUNK_LENGTH_SIZE + PNG_CHUNK_TYPE_SIZE <= dataView.byteLength) {
34-
if (isPngImageHeaderChunk(dataView, offset)) {
35+
if (Constants.USE_PNG_FILE && isPngImageHeaderChunk(dataView, offset)) {
3536
offsets.hasAppMarkers = true;
3637
offsets.pngHeaderOffset = offset + PNG_CHUNK_DATA_OFFSET;
3738
} else if (Constants.USE_XMP && isPngXmpChunk(dataView, offset)) {

test/build/custom-builds.json

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
[
2+
{
3+
"id": "everything",
4+
"config": {
5+
"include": {
6+
"file": true,
7+
"png_file": true,
8+
"exif": true,
9+
"iptc": true,
10+
"xmp": true,
11+
"icc": true,
12+
"thumbnail": true,
13+
"tiff": true,
14+
"jpeg": true,
15+
"png": true,
16+
"heic": true
17+
}
18+
}
19+
},
20+
{
21+
"id": "full-tiff",
22+
"config": {
23+
"include": {
24+
"tiff": true,
25+
"exif": true,
26+
"iptc": true,
27+
"xmp": true
28+
}
29+
}
30+
},
31+
{
32+
"id": "partial-tiff",
33+
"config": {
34+
"include": {
35+
"tiff": true,
36+
"exif": ["DateTime", "ExposureProgram", "DateTimeOriginal", "ComponentsConfiguration", "Flash", "GPSLatitude", "GPSLatitudeRef"],
37+
"iptc": ["File Format", "Coded Character Set", "By-line", "Keywords"]
38+
}
39+
}
40+
},
41+
{
42+
"id": "full-jpeg",
43+
"config": {
44+
"include": {
45+
"jpeg": true,
46+
"file": true,
47+
"exif": true,
48+
"iptc": true,
49+
"xmp": true,
50+
"icc": true,
51+
"thumbnail": true
52+
}
53+
}
54+
},
55+
{
56+
"id": "partial-jpeg",
57+
"config": {
58+
"include": {
59+
"jpeg": true,
60+
"exif": ["DateTime", "ExposureProgram", "DateTimeOriginal", "ComponentsConfiguration", "Flash", "GPSLatitude", "GPSLatitudeRef"],
61+
"iptc": ["File Format", "Coded Character Set", "By-line", "Keywords"]
62+
}
63+
}
64+
},
65+
{
66+
"id": "full-png",
67+
"config": {
68+
"include": {
69+
"png": true,
70+
"png_file": true,
71+
"xmp": true
72+
}
73+
}
74+
},
75+
{
76+
"id": "small-png",
77+
"config": {
78+
"include": {
79+
"png": true,
80+
"xmp": true
81+
}
82+
}
83+
},
84+
{
85+
"id": "full-heic",
86+
"config": {
87+
"include": {
88+
"heic": true,
89+
"exif": true
90+
}
91+
}
92+
},
93+
{
94+
"id": "partial-heic",
95+
"config": {
96+
"include": {
97+
"heic": true,
98+
"exif": ["DateTime", "ExposureProgram", "DateTimeOriginal", "ComponentsConfiguration", "Flash", "GPSLatitude", "GPSLatitudeRef"]
99+
}
100+
}
101+
},
102+
{
103+
"id": "tiff-png",
104+
"config": {
105+
"include": {
106+
"tiff": true,
107+
"png": true,
108+
"exif": true,
109+
"xmp": true
110+
}
111+
}
112+
},
113+
{
114+
"id": "jpeg-heic",
115+
"config": {
116+
"include": {
117+
"jpeg": true,
118+
"heic": true,
119+
"exif": true
120+
}
121+
}
122+
}
123+
]

test/build/exif.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
4+
module.exports = {
5+
parse
6+
};
7+
8+
function parse(imagePath, libraryDir = '../..') {
9+
const exifReaderPath = require.resolve(path.join(libraryDir, 'dist/exif-reader'));
10+
delete require.cache[exifReaderPath];
11+
const ExifReader = require(exifReaderPath);
12+
const data = (new Uint8Array(fs.readFileSync(imagePath))).buffer;
13+
14+
try {
15+
const result = {
16+
combined: ExifReader.load(data),
17+
expanded: ExifReader.load(data, {expanded: true})
18+
};
19+
if (result.combined.Thumbnail && result.combined.Thumbnail.image) {
20+
result.combined.Thumbnail.image = (new Uint8Array(result.combined.Thumbnail.image)).map((char) => Number(char)).toString();
21+
}
22+
if (result.expanded.Thumbnail && result.expanded.Thumbnail.image) {
23+
result.expanded.Thumbnail.image = (new Uint8Array(result.expanded.Thumbnail.image)).map((char) => Number(char)).toString();
24+
}
25+
return result;
26+
} catch (error) {
27+
if (error instanceof ExifReader.errors.MetadataMissingError) {
28+
return 'No Exif data found';
29+
}
30+
return error.toString();
31+
}
32+
}

0 commit comments

Comments
 (0)