-
Notifications
You must be signed in to change notification settings - Fork 3.3k
dependency: update trash dep and convert trash files from JS to TS #31667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b1af11a
4ba22c0
d37e059
cae1bdd
978129f
5b27ac4
f2ea412
71b0c66
ce3f185
88e3dc3
651e75e
7bf55dd
9549718
9fd87fa
cd0eeb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { fs } from './fs' | ||
import os from 'os' | ||
import path from 'path' | ||
import trash from 'trash' | ||
import Bluebird from 'bluebird' | ||
|
||
// Moves a folder's contents to the trash (or empties it on Linux) | ||
export const folder = async (pathToFolder: string): Promise<void> => { | ||
try { | ||
await fs.statAsync(pathToFolder) | ||
|
||
if (os.platform() === 'linux') { | ||
await fs.emptyDir(pathToFolder) | ||
|
||
return | ||
} | ||
|
||
const items = await fs.readdir(pathToFolder) | ||
|
||
await Bluebird.map(items, (item: string) => { | ||
return trash([path.join(pathToFolder, item)]) | ||
}) | ||
} catch (error) { | ||
if ((error as NodeJS.ErrnoException).code === 'ENOENT') { | ||
return | ||
} | ||
|
||
throw error | ||
} | ||
} | ||
|
||
export default { | ||
folder, | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import fs from 'fs' | ||
import os from 'os' | ||
import path from 'path' | ||
import trash from '../../../lib/util/trash' | ||
import sinon from 'sinon' | ||
import { expect } from 'chai' | ||
|
||
require('../../spec_helper') | ||
|
||
// Creates test directories and files for trash testing | ||
const populateDirectories = (basePath: string): void => { | ||
fs.mkdirSync(basePath, { recursive: true }) | ||
fs.mkdirSync(path.resolve(basePath, 'bar'), { recursive: true }) | ||
fs.mkdirSync(path.resolve(basePath, 'bar', 'baz'), { recursive: true }) | ||
|
||
fs.writeFileSync(path.resolve(basePath, 'a.txt'), '') | ||
fs.writeFileSync(path.resolve(basePath, 'bar', 'b.txt'), '') | ||
fs.writeFileSync(path.resolve(basePath, 'bar', 'baz', 'c.txt'), '') | ||
|
||
expect(fs.existsSync(path.resolve(basePath, 'a.txt'))).to.be.true | ||
expect(fs.existsSync(path.resolve(basePath, 'bar', 'b.txt'))).to.be.true | ||
expect(fs.existsSync(path.resolve(basePath, 'bar', 'baz', 'c.txt'))).to.be.true | ||
} | ||
|
||
// Verifies that directories exist but their contents have been removed | ||
const expectDirectoriesExist = (basePath: string): void => { | ||
expect(fs.existsSync(basePath)).to.be.true | ||
expect(fs.existsSync(path.resolve(basePath, 'a.txt'))).to.be.false | ||
expect(fs.existsSync(path.resolve(basePath, 'bar', 'b.txt'))).to.be.false | ||
expect(fs.existsSync(path.resolve(basePath, 'bar', 'baz', 'c.txt'))).to.be.false | ||
} | ||
|
||
describe('lib/util/trash', () => { | ||
let tempDir: string | ||
|
||
beforeEach(() => { | ||
tempDir = path.join(os.tmpdir(), `cypress-test-${Date.now()}`) | ||
fs.mkdirSync(tempDir, { recursive: true }) | ||
}) | ||
|
||
afterEach(() => { | ||
if (fs.existsSync(tempDir)) { | ||
fs.rmSync(tempDir, { recursive: true, force: true }) | ||
} | ||
}) | ||
|
||
context('.folder', () => { | ||
it('trashes contents of directory in non-Linux', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test used to use mock-fs, but it would literally fail every time you ran it locally on a mac because the trash code was literally trying to trash a file that never existed, so this has been updated to just make temp directories during the tests outright. |
||
sinon.stub(os, 'platform').returns('darwin') | ||
const basePath = path.join(tempDir, 'foo') | ||
|
||
populateDirectories(basePath) | ||
|
||
await trash.folder(basePath) | ||
expectDirectoriesExist(basePath) | ||
fs.rmdirSync(basePath) | ||
}) | ||
|
||
it('doesn\'t fail if directory is non-existent', async () => { | ||
await trash.folder(path.join(tempDir, 'bar')) | ||
}) | ||
|
||
it('completely removes directory on Linux', async () => { | ||
sinon.stub(os, 'platform').returns('linux') | ||
const basePath = path.join(tempDir, 'foo') | ||
|
||
populateDirectories(basePath) | ||
|
||
await trash.folder(basePath) | ||
expectDirectoriesExist(basePath) | ||
fs.rmdirSync(basePath) | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ const getDependencyPathsToKeep = async (buildAppDir) => { | |
'node_modules/html-webpack-plugin-5/index.js', | ||
'node_modules/mocha-7.2.0/index.js', | ||
'packages/server/node_modules/webdriver/build/index.js', | ||
'packages/server/node_modules/@wdio/utils/build/node.js', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See this thread: https://cypressio.slack.com/archives/C06G5D5KFCJ/p1746724397061149 |
||
// dependencies needed for geckodriver when running firefox in the binary | ||
'node_modules/pump/index.js', | ||
'node_modules/sprintf-js/src/sprintf.js', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was rewritten a bit, so review carefully