mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-24 09:29:35 -05:00
31ee30b6f3
* chore: rename snapshots and spec files to fit vitest convention (#32405) * chore: move compiled files to dist directory to make vitest convertion easier (#32406) * chore: convert utils to vitest (#32407) * chore: convert logger to vitest * chore: convert errors spec to vitest * chore: convert cypress spec to vitest * chore: convert `exec` directory to `vitest` (#32428) * chore: cut over exec directory to vitest * Update cli/test/lib/exec/run.spec.ts * Update cli/test/lib/exec/run.spec.ts * Update cli/test/lib/exec/run.spec.ts * chore: convert the CLI and build script specs over to vitest (#32438) * chore: convert tasks directory to vitest (#32434) change way verify module is exported due to issues interpreting module (thinks its an esm) rework scripts as we cannot run an empty mocha suite chore: fix snapshots and verify requires that are internal to the cypress project fix stubbing issues with fs-extra which is also used by request-progress under the hood fix issues where xvfb was stopping prematurely * chore: remove files no longer used now that mocha tests are converted to vitest (#32455) * build binaries * chore: fix CLI tests (#32484) * chore: remove CI branch
37 lines
968 B
TypeScript
37 lines
968 B
TypeScript
import fs from 'fs-extra'
|
|
import { join } from 'path'
|
|
import Bluebird from 'bluebird'
|
|
|
|
/**
|
|
* Get the size of a folder or a file.
|
|
*
|
|
* This function returns the actual file size of the folder (size), not the allocated space on disk (size on disk).
|
|
* For more details between the difference, check this link:
|
|
* https://www.howtogeek.com/180369/why-is-there-a-big-difference-between-size-and-size-on-disk/
|
|
*
|
|
* @param {string} path path to the file or the folder.
|
|
*/
|
|
async function getSize (path: string): Promise<number> {
|
|
const stat = await fs.lstat(path)
|
|
|
|
if (stat.isDirectory()) {
|
|
const list = await fs.readdir(path)
|
|
|
|
return Bluebird.resolve(list).reduce(async (prev: number, curr: string) => {
|
|
const currPath = join(path, curr)
|
|
|
|
const s = await fs.lstat(currPath)
|
|
|
|
if (s.isDirectory()) {
|
|
return prev + await getSize(currPath)
|
|
}
|
|
|
|
return prev + s.size
|
|
}, 0)
|
|
}
|
|
|
|
return stat.size
|
|
}
|
|
|
|
export default getSize
|