diff --git a/.github/workflows/e2e-linux.yml b/.github/workflows/e2e-linux.yml index 746ddb1795..ccdc268300 100644 --- a/.github/workflows/e2e-linux.yml +++ b/.github/workflows/e2e-linux.yml @@ -16,6 +16,7 @@ jobs: ELECTRON_CUSTOM_VERSION: 23.0.0 DISPLAY: ":99.0" TEST_MODE: true + IS_CI: true steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 diff --git a/.github/workflows/e2e-mac.yml b/.github/workflows/e2e-mac.yml index 97dcbdfe00..cc363591a2 100644 --- a/.github/workflows/e2e-mac.yml +++ b/.github/workflows/e2e-mac.yml @@ -9,6 +9,7 @@ jobs: ELECTRON_CUSTOM_VERSION: 23.0.0 TEST_MODE: true IS_E2E: true + IS_CI: true steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 diff --git a/.github/workflows/e2e-win.yml b/.github/workflows/e2e-win.yml index 98ec12837e..3c6b32f20e 100644 --- a/.github/workflows/e2e-win.yml +++ b/.github/workflows/e2e-win.yml @@ -11,6 +11,7 @@ jobs: ELECTRON_CUSTOM_VERSION: 23.0.0 TEST_MODE: true E2E: true + IS_CI: true steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 59c0741d0f..e545278684 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ * Add utilities for emoji detection in messages and make all-emoji message larger font size ([#519](https://github.com/TryQuiet/quiet/issues/519)) +# Chores + +* Cleanup data directory at end of e2e tests + [2.1.2] # Refactorings: diff --git a/packages/common/src/dir.ts b/packages/common/src/dir.ts new file mode 100644 index 0000000000..4130a7ed4d --- /dev/null +++ b/packages/common/src/dir.ts @@ -0,0 +1,19 @@ +import path from 'path' +import { DESKTOP_DATA_DIR, DESKTOP_DEV_DATA_DIR } from './static' + +export type GetDataAppPathDefaults = { + appDataPath?: string + dataDir?: string +} + +export const getAppDataPath = (defaults: GetDataAppPathDefaults = {}): string => { + const defaultAppDataPath = defaults.appDataPath || process.env.APPDATA + const defaultDataDir = defaults.dataDir || process.env.DATA_DIR + + const dataPath = + defaultAppDataPath || + (process.platform === 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + '/.config') + const appPath = defaultDataDir || (process.env.NODE_ENV === 'development' ? DESKTOP_DEV_DATA_DIR : DESKTOP_DATA_DIR) + + return path.join(dataPath, appPath) +} diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index f15cd34520..81cc0eb155 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -11,3 +11,4 @@ export * from './libp2p' export * from './tests' export * from './auth' export * from './messages' +export * from './dir' diff --git a/packages/desktop/src/renderer/store/reducers.ts b/packages/desktop/src/renderer/store/reducers.ts index 2cea0e75a8..8d987605e1 100644 --- a/packages/desktop/src/renderer/store/reducers.ts +++ b/packages/desktop/src/renderer/store/reducers.ts @@ -27,17 +27,11 @@ import { navigationReducer } from './navigation/navigation.slice' import appHandlers from './handlers/app' import { Store } from '../sagas/store.types' -import { DESKTOP_DATA_DIR, DESKTOP_DEV_DATA_DIR } from '@quiet/common' - -const dataPath = - process.env.APPDATA || - (process.platform === 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + '/.config') -const appPath = - process.env.DATA_DIR || (process.env.NODE_ENV === 'development' ? DESKTOP_DEV_DATA_DIR : DESKTOP_DATA_DIR) +import { getAppDataPath } from '@quiet/common' const options = { projectName: 'quiet', - cwd: path.join(dataPath, appPath), + cwd: getAppDataPath(), } const store = new ElectronStore(options) diff --git a/packages/e2e-tests/src/selectors.ts b/packages/e2e-tests/src/selectors.ts index 95e7a2e4d8..bcd637b221 100644 --- a/packages/e2e-tests/src/selectors.ts +++ b/packages/e2e-tests/src/selectors.ts @@ -51,6 +51,14 @@ export class App { console.log('App closed', this.buildSetup.dataDir) } + async cleanup() { + console.log(`Performing app cleanup`, this.buildSetup.dataDir) + if (this.isOpened) { + throw new Error(`App with dataDir ${this.buildSetup.dataDir} is still open, close before cleaning up!`) + } + this.buildSetup.clearDataDir() + } + get saveStateButton() { return this.driver.wait(until.elementLocated(By.xpath('//div[@data-testid="save-state-button"]'))) } diff --git a/packages/e2e-tests/src/tests/backwardsCompatibility.test.ts b/packages/e2e-tests/src/tests/backwardsCompatibility.test.ts index 4d6f44b452..8f0c349de6 100644 --- a/packages/e2e-tests/src/tests/backwardsCompatibility.test.ts +++ b/packages/e2e-tests/src/tests/backwardsCompatibility.test.ts @@ -42,6 +42,9 @@ describe('Backwards Compatibility', () => { afterAll(async () => { await new Promise(resolve => setTimeout(() => resolve(), 5000)) await ownerAppNewVersion?.close() + await ownerAppNewVersion?.cleanup() + await ownerAppOldVersion?.close() + await ownerAppOldVersion?.cleanup() }) describe('User opens app for the first time', () => { it('Owner opens the app', async () => { diff --git a/packages/e2e-tests/src/tests/invitationLink.test.ts b/packages/e2e-tests/src/tests/invitationLink.test.ts index 6deef6627c..472780f041 100644 --- a/packages/e2e-tests/src/tests/invitationLink.test.ts +++ b/packages/e2e-tests/src/tests/invitationLink.test.ts @@ -34,7 +34,9 @@ describe('New user joins using invitation link while having app opened', () => { afterAll(async () => { await ownerApp?.close() + await ownerApp?.cleanup() await guestApp?.close() + await guestApp?.cleanup() }) describe('Stages:', () => { diff --git a/packages/e2e-tests/src/tests/multipleClients.test.ts b/packages/e2e-tests/src/tests/multipleClients.test.ts index 8da0cade98..59ad62e03a 100644 --- a/packages/e2e-tests/src/tests/multipleClients.test.ts +++ b/packages/e2e-tests/src/tests/multipleClients.test.ts @@ -78,6 +78,7 @@ describe('Multiple Clients', () => { afterAll(async () => { for (const user of Object.values(users)) { await user.app.close() + await user.app.cleanup() } }) diff --git a/packages/e2e-tests/src/tests/oneClient.test.ts b/packages/e2e-tests/src/tests/oneClient.test.ts index 05d22a077f..1dab965c39 100644 --- a/packages/e2e-tests/src/tests/oneClient.test.ts +++ b/packages/e2e-tests/src/tests/oneClient.test.ts @@ -23,6 +23,7 @@ describe('One Client', () => { afterAll(async () => { await app.close() + await app.cleanup() }) describe('User opens app for the first time', () => { it('Get opened app process data', () => { diff --git a/packages/e2e-tests/src/tests/userProfile.test.ts b/packages/e2e-tests/src/tests/userProfile.test.ts index efd0e67d47..6584dc5175 100644 --- a/packages/e2e-tests/src/tests/userProfile.test.ts +++ b/packages/e2e-tests/src/tests/userProfile.test.ts @@ -50,6 +50,7 @@ describe('User Profile Feature', () => { afterAll(async () => { for (const user of Object.values(users)) { await user.app.close() + await user.app.cleanup() } }) diff --git a/packages/e2e-tests/src/utils.ts b/packages/e2e-tests/src/utils.ts index c6cb437999..7bf4a0ca6e 100644 --- a/packages/e2e-tests/src/utils.ts +++ b/packages/e2e-tests/src/utils.ts @@ -4,7 +4,7 @@ import { type SupportedPlatformDesktop } from '@quiet/types' import getPort from 'get-port' import path from 'path' import fs from 'fs' -import { DESKTOP_DATA_DIR } from '@quiet/common' +import { DESKTOP_DATA_DIR, getAppDataPath } from '@quiet/common' export const BACKWARD_COMPATIBILITY_BASE_VERSION = '2.0.1' // Pre-latest production version const appImagesPath = `${__dirname}/../Quiet` @@ -22,6 +22,7 @@ export class BuildSetup { public port?: number public debugPort?: number public dataDir?: string + public dataDirPath: string private child?: ChildProcessWithoutNullStreams private defaultDataDir: boolean private fileName?: string @@ -36,6 +37,7 @@ export class BuildSetup { if (!this.dataDir) { this.dataDir = `e2e_${(Math.random() * 10 ** 18).toString(36)}` } + this.dataDirPath = getAppDataPath({ dataDir: this.dataDir }) } async initPorts() { @@ -224,6 +226,15 @@ export class BuildSetup { await this.driver?.close() } + public clearDataDir() { + if (process.env.IS_CI === 'true') { + console.warn('Not deleting data directory because we are running in CI') + return + } + console.log(`Deleting data directory at ${this.dataDirPath}`) + fs.rmdirSync(this.dataDirPath, { recursive: true }) + } + public getProcessData = () => { let dataDirPath = '' let resourcesPath = ''