MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / isFileExists

Function isFileExists

lib/helper/FileSystem.js:223–248  ·  view source on GitHub ↗

* @param {string} file * @param {number} timeout * @private * @returns {Promise }

(file, timeout)

Source from the content-addressed store, hash-verified

221 * @returns {Promise<any>}
222 */
223function isFileExists(file, timeout) {
224 return new Promise((resolve, reject) => {
225 const timer = setTimeout(() => {
226 watcher.close()
227 reject(new Error('File did not exists and was not created during the timeout.'))
228 }, timeout)
229
230 const dir = path.dirname(file)
231 const basename = path.basename(file)
232 const watcher = fs.watch(dir, (eventType, filename) => {
233 if (eventType === 'rename' && filename === basename) {
234 clearTimeout(timer)
235 watcher.close()
236 resolve()
237 }
238 })
239
240 fs.access(file, fs.constants.R_OK, err => {
241 if (!err) {
242 clearTimeout(timer)
243 watcher.close()
244 resolve()
245 }
246 })
247 })
248}

Callers 1

waitForFileMethod · 0.85

Calls 1

resolveFunction · 0.85

Tested by

no test coverage detected