mattermost/e2e-tests/cypress/tests/plugins/file_util.js
sabril 8bf422d6e2
E2E/Cypress: Upgrade dependencies (#33665)
* upgrade cypress and other dependecies

* fix eslint

* remove axios-retry and update eslint

* fix tests

* fix lint on trailing spaces

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
2025-09-01 14:14:13 +08:00

38 lines
1 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
const fs = require('fs');
const path = require('path');
/**
* Checks whether a file exist in the fixtures folder
* @param {string} filename - filename to check if it exists
*/
const fileExist = (filename) => {
const filePath = path.resolve(__dirname, `../fixtures/${filename}`);
return fs.existsSync(filePath);
};
/**
* Write data to a file in the fixtures folder
* @param {string} filename - filename where to write data into
* @param {string} fixturesFolder - folder at tests/fixtures
* @param {string} data - The data to write
*/
const writeToFile = ({filename, fixturesFolder, data = ''}) => {
const folder = path.resolve(__dirname, `../fixtures/${fixturesFolder}`);
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder, {recursive: true});
}
const filePath = `${folder}/${filename}`;
fs.writeFileSync(filePath, data);
return null;
};
module.exports = {
fileExist,
writeToFile,
};