Skip to content

Commit

Permalink
chore(2420): Cleanup data directory at end of e2e tests (#2421)
Browse files Browse the repository at this point in the history
* Cleanup data directory at end of e2e tests

* Update CHANGELOG.md

* Don't clear on CI
  • Loading branch information
Isla Koenigsknecht authored Apr 8, 2024
1 parent 232707f commit fa3a9b6
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/e2e-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/e2e-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions packages/common/src/dir.ts
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './libp2p'
export * from './tests'
export * from './auth'
export * from './messages'
export * from './dir'
10 changes: 2 additions & 8 deletions packages/desktop/src/renderer/store/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Store>(options)
Expand Down
8 changes: 8 additions & 0 deletions packages/e2e-tests/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]')))
}
Expand Down
3 changes: 3 additions & 0 deletions packages/e2e-tests/src/tests/backwardsCompatibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ describe('Backwards Compatibility', () => {
afterAll(async () => {
await new Promise<void>(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 () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/e2e-tests/src/tests/invitationLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-tests/src/tests/multipleClients.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe('Multiple Clients', () => {
afterAll(async () => {
for (const user of Object.values(users)) {
await user.app.close()
await user.app.cleanup()
}
})

Expand Down
1 change: 1 addition & 0 deletions packages/e2e-tests/src/tests/oneClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-tests/src/tests/userProfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})

Expand Down
13 changes: 12 additions & 1 deletion packages/e2e-tests/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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 = ''
Expand Down

0 comments on commit fa3a9b6

Please sign in to comment.