Skip to content

Commit 2d7a84d

Browse files
jennifer-shehanecypress-bot[bot]ryanthemanuel
authored
dependency: update trash dep and convert trash files from JS to TS (#31667)
* dependency: bump trash dir * update trash files to TypeScript * Run on binaries + other OSes * index on update-trash: d37e059 Run on binaries + other OSes * index on update-trash: d37e059 Run on binaries + other OSes * index on update-trash: d37e059 Run on binaries + other OSes * fix build * changelog entry --------- Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com> Co-authored-by: Ryan Manuel <ryanm@cypress.io>
1 parent 77cd150 commit 2d7a84d

File tree

13 files changed

+259
-380
lines changed

13 files changed

+259
-380
lines changed

.circleci/workflows.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mainBuildFilters: &mainBuildFilters
3838
- /^release\/\d+\.\d+\.\d+$/
3939
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
4040
- 'update-v8-snapshot-cache-on-develop'
41-
- 'ryanm/fix/having-trouble-debugging-your-ci-failures'
41+
- 'update-trash'
4242

4343
# usually we don't build Mac app - it takes a long time
4444
# but sometimes we want to really confirm we are doing the right thing
@@ -49,11 +49,7 @@ macWorkflowFilters: &darwin-workflow-filters
4949
- equal: [ develop, << pipeline.git.branch >> ]
5050
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
5151
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
52-
- equal:
53-
[
54-
'ryanm/fix/having-trouble-debugging-your-ci-failures',
55-
<< pipeline.git.branch >>
56-
]
52+
- equal: [ 'update-trash', << pipeline.git.branch >> ]
5753
- matches:
5854
pattern: /^release\/\d+\.\d+\.\d+$/
5955
value: << pipeline.git.branch >>
@@ -64,11 +60,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
6460
- equal: [ develop, << pipeline.git.branch >> ]
6561
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
6662
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
67-
- equal:
68-
[
69-
'ryanm/fix/having-trouble-debugging-your-ci-failures',
70-
<< pipeline.git.branch >>
71-
]
63+
- equal: [ 'update-trash', << pipeline.git.branch >> ]
7264
- matches:
7365
pattern: /^release\/\d+\.\d+\.\d+$/
7466
value: << pipeline.git.branch >>
@@ -165,7 +157,7 @@ commands:
165157
name: Set environment variable to determine whether or not to persist artifacts
166158
command: |
167159
echo "Setting SHOULD_PERSIST_ARTIFACTS variable"
168-
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "ryanm/fix/having-trouble-debugging-your-ci-failures" ]]; then
160+
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "update-trash" ]]; then
169161
export SHOULD_PERSIST_ARTIFACTS=true
170162
fi' >> "$BASH_ENV"
171163
# You must run `setup_should_persist_artifacts` command and be using bash before running this command

cli/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
2+
## 14.3.4
3+
4+
_Released 5/20/2025 (PENDING)_
5+
6+
**Dependency Updates:**
7+
8+
- Upgraded `trash` from `5.2.0` to `7.2.0`. Addressed in [#31667](https://github.com/cypress-io/cypress/pull/31667).
9+
10+
211
## 14.3.3
312

413
_Released 5/6/2025_

packages/server/lib/modes/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ async function trashAssets (config: Cfg) {
216216
try {
217217
await Promise.all([
218218
trash.folder(config.videosFolder),
219-
trash.folder(config.screenshotsFolder),
219+
typeof config.screenshotsFolder === 'string' ? trash.folder(config.screenshotsFolder) : Promise.resolve(),
220220
trash.folder(config.downloadsFolder),
221221
])
222222
} catch (err) {

packages/server/lib/util/trash.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/server/lib/util/trash.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { fs } from './fs'
2+
import os from 'os'
3+
import path from 'path'
4+
import trash from 'trash'
5+
import Bluebird from 'bluebird'
6+
7+
// Moves a folder's contents to the trash (or empties it on Linux)
8+
export const folder = async (pathToFolder: string): Promise<void> => {
9+
try {
10+
await fs.statAsync(pathToFolder)
11+
12+
if (os.platform() === 'linux') {
13+
await fs.emptyDir(pathToFolder)
14+
15+
return
16+
}
17+
18+
const items = await fs.readdir(pathToFolder)
19+
20+
await Bluebird.map(items, (item: string) => {
21+
return trash([path.join(pathToFolder, item)])
22+
})
23+
} catch (error) {
24+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
25+
return
26+
}
27+
28+
throw error
29+
}
30+
}
31+
32+
export default {
33+
folder,
34+
}

packages/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
"term-size": "2.1.0",
129129
"through": "2.3.8",
130130
"tough-cookie": "4.1.3",
131-
"trash": "5.2.0",
131+
"trash": "7.2.0",
132132
"ts-node": "^10.9.2",
133133
"tslib": "2.3.1",
134134
"underscore.string": "3.3.6",

packages/server/test/unit/util/trash_spec.js

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import fs from 'fs'
2+
import os from 'os'
3+
import path from 'path'
4+
import trash from '../../../lib/util/trash'
5+
import sinon from 'sinon'
6+
import { expect } from 'chai'
7+
8+
require('../../spec_helper')
9+
10+
// Creates test directories and files for trash testing
11+
const populateDirectories = (basePath: string): void => {
12+
fs.mkdirSync(basePath, { recursive: true })
13+
fs.mkdirSync(path.resolve(basePath, 'bar'), { recursive: true })
14+
fs.mkdirSync(path.resolve(basePath, 'bar', 'baz'), { recursive: true })
15+
16+
fs.writeFileSync(path.resolve(basePath, 'a.txt'), '')
17+
fs.writeFileSync(path.resolve(basePath, 'bar', 'b.txt'), '')
18+
fs.writeFileSync(path.resolve(basePath, 'bar', 'baz', 'c.txt'), '')
19+
20+
expect(fs.existsSync(path.resolve(basePath, 'a.txt'))).to.be.true
21+
expect(fs.existsSync(path.resolve(basePath, 'bar', 'b.txt'))).to.be.true
22+
expect(fs.existsSync(path.resolve(basePath, 'bar', 'baz', 'c.txt'))).to.be.true
23+
}
24+
25+
// Verifies that directories exist but their contents have been removed
26+
const expectDirectoriesExist = (basePath: string): void => {
27+
expect(fs.existsSync(basePath)).to.be.true
28+
expect(fs.existsSync(path.resolve(basePath, 'a.txt'))).to.be.false
29+
expect(fs.existsSync(path.resolve(basePath, 'bar', 'b.txt'))).to.be.false
30+
expect(fs.existsSync(path.resolve(basePath, 'bar', 'baz', 'c.txt'))).to.be.false
31+
}
32+
33+
describe('lib/util/trash', () => {
34+
let tempDir: string
35+
36+
beforeEach(() => {
37+
tempDir = path.join(os.tmpdir(), `cypress-test-${Date.now()}`)
38+
fs.mkdirSync(tempDir, { recursive: true })
39+
})
40+
41+
afterEach(() => {
42+
if (fs.existsSync(tempDir)) {
43+
fs.rmSync(tempDir, { recursive: true, force: true })
44+
}
45+
})
46+
47+
context('.folder', () => {
48+
it('trashes contents of directory in non-Linux', async () => {
49+
sinon.stub(os, 'platform').returns('darwin')
50+
const basePath = path.join(tempDir, 'foo')
51+
52+
populateDirectories(basePath)
53+
54+
await trash.folder(basePath)
55+
expectDirectoriesExist(basePath)
56+
fs.rmdirSync(basePath)
57+
})
58+
59+
it('doesn\'t fail if directory is non-existent', async () => {
60+
await trash.folder(path.join(tempDir, 'bar'))
61+
})
62+
63+
it('completely removes directory on Linux', async () => {
64+
sinon.stub(os, 'platform').returns('linux')
65+
const basePath = path.join(tempDir, 'foo')
66+
67+
populateDirectories(basePath)
68+
69+
await trash.folder(basePath)
70+
expectDirectoriesExist(basePath)
71+
fs.rmdirSync(basePath)
72+
})
73+
})
74+
})

scripts/binary/binary-cleanup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const getDependencyPathsToKeep = async (buildAppDir) => {
5151
'node_modules/html-webpack-plugin-5/index.js',
5252
'node_modules/mocha-7.2.0/index.js',
5353
'packages/server/node_modules/webdriver/build/index.js',
54+
'packages/server/node_modules/@wdio/utils/build/node.js',
5455
// dependencies needed for geckodriver when running firefox in the binary
5556
'node_modules/pump/index.js',
5657
'node_modules/sprintf-js/src/sprintf.js',

0 commit comments

Comments
 (0)