From c1b91daf5d0c2c73747cf303f47728aae99d4a91 Mon Sep 17 00:00:00 2001 From: AtofStryker Date: Mon, 19 Aug 2024 12:11:30 -0400 Subject: [PATCH] chore: add failing unit test to show issue (still needs fix) --- packages/server/lib/util/app_data.js | 12 ++++--- .../server/test/unit/util/app_data_spec.js | 31 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/packages/server/lib/util/app_data.js b/packages/server/lib/util/app_data.js index efe9cb21f1de..c2eba7464949 100644 --- a/packages/server/lib/util/app_data.js +++ b/packages/server/lib/util/app_data.js @@ -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') @@ -98,7 +102,7 @@ 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) @@ -106,7 +110,7 @@ module.exports = { }, electronPartitionsPath () { - return path.join(ELECTRON_APP_DATA_PATH, 'Partitions') + return path.join(getElectronAppDataPath(), 'Partitions') }, projectsPath (...paths) { diff --git a/packages/server/test/unit/util/app_data_spec.js b/packages/server/test/unit/util/app_data_spec.js index f05405245fe4..b10fde6a940c 100644 --- a/packages/server/test/unit/util/app_data_spec.js +++ b/packages/server/test/unit/util/app_data_spec.js @@ -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`) @@ -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`) + }) }) })