exiftool-vendored
Version:
Efficient, cross-platform access to ExifTool
80 lines • 3.88 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = __importDefault(require("node:path"));
const ExifTool_1 = require("./ExifTool");
const _chai_spec_1 = require("./_chai.spec");
describe("RewriteAllTagsTask", () => {
for (const opts of [
{ maxProcs: 1, maxRetries: 0 },
{ maxProcs: 3, maxRetries: 3 },
]) {
describe(`new ExifTool(${JSON.stringify(opts)})`, () => {
const exiftool = new ExifTool_1.ExifTool(opts);
const d = new Date();
d.setMilliseconds(0);
after(() => (0, _chai_spec_1.end)(exiftool));
it("throws on missing input", async function () {
this.slow(500);
return (0, _chai_spec_1.expect)(exiftool.rewriteAllTags("missing.jpg", "ignored.jpg")).to.be.rejectedWith(/Error opening file.{0,80}missing\.jpg/);
});
function expectSameYmdHms(a, b) {
(0, _chai_spec_1.expect)([a.year, a.month, a.day, a.hour, a.minute, a.second]).to.eql([
b.getUTCFullYear(),
b.getUTCMonth() + 1,
b.getUTCDate(),
b.getUTCHours(),
b.getUTCMinutes(),
b.getUTCSeconds(),
]);
}
it("test file is not problematic", async () => {
const img = await (0, _chai_spec_1.testImg)();
await exiftool.write(img, { CreateDate: d.toISOString() });
const tags = await exiftool.read(img);
expectSameYmdHms(tags.CreateDate, d);
return;
});
describe("with problematic file", () => {
const writeTags = {
CreateDate: d.toISOString(),
FNumber: null,
};
const expectedMeta = {
Make: "SAMSUNG",
Model: "GT-i7500",
MIMEType: "image/jpeg",
ExposureTime: "1/10",
FNumber: 2.8,
ExposureProgram: "Aperture-priority AE",
ISO: 200,
Flash: "No Flash",
};
it("matches expected metadata", async () => {
const img = await (0, _chai_spec_1.testImg)({ srcBasename: "problematic.jpg" });
(0, _chai_spec_1.expect)(await exiftool.read(img)).to.containSubset(expectedMeta);
});
it("problematic file is problematic", async () => {
const img = await (0, _chai_spec_1.testImg)({ srcBasename: "problematic.jpg" });
return (0, _chai_spec_1.expect)(exiftool.write(img, writeTags)).to.be.rejectedWith(/Error reading ThumbnailImage data/);
});
it("problematic file is not problematic after rewriting", async () => {
const img = await (0, _chai_spec_1.testImg)({ srcBasename: "problematic.jpg" });
const f = node_path_1.default.parse(img);
const rewritten = node_path_1.default.join(f.dir, "rewritten.jpg");
await exiftool.rewriteAllTags(img, rewritten);
await exiftool.write(rewritten, writeTags);
const tags = await exiftool.read(rewritten);
(0, _chai_spec_1.expect)(tags).to.containSubset({
...expectedMeta,
FNumber: undefined,
});
expectSameYmdHms(tags.CreateDate, d);
});
});
});
}
});
//# sourceMappingURL=RewriteAllTags.spec.js.map