mattermost/e2e-tests/cypress/tests/plugins/get_pdf_content.js
sabril 6b28864fdc
E2E/Cypress: Upgrade cypress to 15.11 (#35466)
* chore: upgrade cypress to 15.11

* update per comment

* update flaky test (while here)

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
2026-03-09 16:01:04 +08:00

22 lines
678 B
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
const fs = require('fs');
const {PDFParse} = require('pdf-parse');
/**
* Checks whether a file exist in the tests/downloads folder and return the content of it.
* @param {string} filePath - pdf file path
*/
module.exports = async (filePath) => {
const dataBuffer = fs.readFileSync(filePath);
const parser = new PDFParse({data: dataBuffer});
try {
const text = await parser.getText();
const info = await parser.getInfo();
return {text, info, numpages: info.numPages};
} finally {
await parser.destroy();
}
};