Skip to content

Commit

Permalink
chore: add failing unit test to show issue (still needs fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
AtofStryker committed Aug 19, 2024
1 parent 482358b commit c1b91da
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/server/lib/util/app_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ const md5 = require('md5')
const sanitize = require('sanitize-filename')

const PRODUCT_NAME = pkg.productName || pkg.name
const OS_DATA_PATH = ospath.data()

const ELECTRON_APP_DATA_PATH = path.join(OS_DATA_PATH, PRODUCT_NAME)
const getElectronAppDataPath = () => {
const OS_DATA_PATH = ospath.data()
const ELECTRON_APP_DATA_PATH = path.join(OS_DATA_PATH, PRODUCT_NAME)

return ELECTRON_APP_DATA_PATH
}

if (!PRODUCT_NAME) {
throw new Error('Root package is missing name')
Expand Down Expand Up @@ -98,15 +102,15 @@ module.exports = {
folder = `${folder}-e2e-test`
}

const p = path.join(ELECTRON_APP_DATA_PATH, 'cy', folder, ...paths)
const p = path.join(getElectronAppDataPath(), 'cy', folder, ...paths)

log('path: %s', p)

return p
},

electronPartitionsPath () {
return path.join(ELECTRON_APP_DATA_PATH, 'Partitions')
return path.join(getElectronAppDataPath(), 'Partitions')
},

projectsPath (...paths) {
Expand Down
31 changes: 31 additions & 0 deletions packages/server/test/unit/util/app_data_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
require('../../spec_helper')
const os = require('os')
const osPath = require('ospath')
const path = require('path')

const AppData = require(`../../../lib/util/app_data`)

Expand Down Expand Up @@ -38,5 +41,33 @@ describe('lib/util/app_data', () => {
expect(result).to.contain(expectedPrefix)
expect(result).to.contain(imagePath)
})

it('issue #8599: can find a path to bundle preprocessor files that live outside the project directory (windows)', () => {
// mock / stub out path and os variables as if we were on Windows
sinon.stub(os, 'platform')
sinon.stub(osPath, 'data')
sinon.stub(path, 'basename')
sinon.stub(path, 'dirname')
sinon.stub(path, 'isAbsolute')
sinon.stub(path, 'join')

os.platform.returns('win32')
osPath.data.returns(`C:\\Users\\foo\\AppData\\Roaming`)

path.basename.callsFake((...args) => path.win32.basename(...args))
path.dirname.callsFake((...args) => path.win32.dirname(...args))
path.isAbsolute.callsFake((...args) => path.win32.isAbsolute(...args))
path.join.callsFake((...args) => path.win32.join(...args))

const filePathNotInProjectDirectory = `C:\\Users\\foo\\project\\support\\index.js`

const projectRoot = `C:\\Users\\foo\\project\\nested-project`

const result = AppData.getBundledFilePath(projectRoot, filePathNotInProjectDirectory)

// currently is: 'C:\\Users\\foo\\AppData\\Roaming\\Cypress\\cy\\test\\projects\\nested-project-5ddfc54488859fd4a685e789cc5259c9\\bundles\\C:\\Users\\foo\\project\\support\\index.js'
// likely should be something like this: 'C:\\Users\\foo\\AppData\\Roaming\\Cypress\\cy\\test\\projects\\nested-project-5ddfc54488859fd4a685e789cc5259c9\\bundles\\support\\index.js'
expect(result).to.equal(`C:\\Users\\foo\\AppData\\Roaming\\Cypress\\cy\\test\\projects\\nested-project-5ddfc54488859fd4a685e789cc5259c9\\bundles\\support\\index.js`)
})
})
})

0 comments on commit c1b91da

Please sign in to comment.