Skip to content

Commit

Permalink
fix: e2e test for invitation link;
Browse files Browse the repository at this point in the history
chore: move DATA_DIR related statics to common package
  • Loading branch information
EmiM committed Nov 28, 2023
1 parent a0a0ffb commit 335677a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/backend/src/nest/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class AppModule {
res.end()
}
})

console.log('ok')
return { server, io }
},
inject: [EXPRESS_PROVIDER],
Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/static.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export const DESKTOP_DEV_DATA_DIR = 'Quietdev'
export const DESKTOP_DATA_DIR = 'Quiet2'

export enum Site {
DOMAIN = 'tryquiet.org',
MAIN_PAGE = 'https://tryquiet.org/',
Expand Down
13 changes: 9 additions & 4 deletions packages/desktop/src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ import { getPorts, ApplicationPorts, closeHangingBackendProcess } from './backen
import pkijs, { setEngine, CryptoEngine } from 'pkijs'
import { Crypto } from '@peculiar/webcrypto'
import logger from './logger'
import { DATA_DIR, DEV_DATA_DIR } from '../shared/static'
import { fork, ChildProcess } from 'child_process'
import { argvInvitationCode, getFilesData, parseInvitationCodeDeepUrl } from '@quiet/common'
import {
DESKTOP_DATA_DIR,
DESKTOP_DEV_DATA_DIR,
argvInvitationCode,
getFilesData,
parseInvitationCodeDeepUrl,
} from '@quiet/common'
import { updateDesktopFile, processInvitationCode } from './invitation'
const ElectronStore = require('electron-store')
ElectronStore.initRenderer()
Expand All @@ -33,13 +38,13 @@ const webcrypto = new Crypto()

global.crypto = webcrypto

let dataDir = DATA_DIR
let dataDir = DESKTOP_DATA_DIR
let mainWindow: BrowserWindow | null
let splash: BrowserWindow | null
let invitationUrl: string | null

if (isDev || process.env.DATA_DIR) {
dataDir = process.env.DATA_DIR || DEV_DATA_DIR
dataDir = process.env.DATA_DIR || DESKTOP_DEV_DATA_DIR
}

const appDataPath = path.join(app.getPath('appData'), dataDir)
Expand Down
5 changes: 3 additions & 2 deletions packages/desktop/src/renderer/store/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ import { navigationReducer } from './navigation/navigation.slice'

import appHandlers from './handlers/app'

import { DEV_DATA_DIR } from '../../shared/static'
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' ? DEV_DATA_DIR : 'Quiet')
const appPath =
process.env.DATA_DIR || (process.env.NODE_ENV === 'development' ? DESKTOP_DEV_DATA_DIR : DESKTOP_DATA_DIR)

const options = {
projectName: 'quiet',
Expand Down
3 changes: 0 additions & 3 deletions packages/desktop/src/shared/static.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import mirrorKey from 'keymirror'

export const DEV_DATA_DIR = 'Quietdev'
export const DATA_DIR = 'Quiet2'

export const actionTypes = mirrorKey({
SET_APP_VERSION: undefined,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export class DebugModeModal {
const log = await this.driver.executeScript('arguments[0].click();', button)
console.log('executeScript', log)
} catch (e) {
console.log('Probably click properly close modal')
console.log('Probably clicked hidden close button on debug modal', e)
}
await new Promise<void>(resolve => setTimeout(() => resolve(), 2000))
}
Expand Down
9 changes: 5 additions & 4 deletions packages/e2e-tests/src/tests/invitationLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import {
CreateCommunityModal,
DebugModeModal,
JoinCommunityModal,
JoiningLoadingPanel,
RegisterUsernameModal,
App,
Sidebar,
WarningModal,
} from '../selectors'
import { capitalizeFirstLetter, composeInvitationDeepUrl, parseInvitationCode, userJoinedMessage } from '@quiet/common'
import { composeInvitationDeepUrl, parseInvitationCode, userJoinedMessage } from '@quiet/common'
import { execSync } from 'child_process'
import { type SupportedPlatformDesktop } from '@quiet/types'

Expand All @@ -26,7 +25,7 @@ describe('New user joins using invitation link while having app opened', () => {

beforeAll(async () => {
ownerApp = new App()
guestApp = new App({ useDataDir: false })
guestApp = new App({ defaultDataDir: true })
})

beforeEach(async () => {
Expand Down Expand Up @@ -141,7 +140,9 @@ describe('New user joins using invitation link while having app opened', () => {
const copiedCode = url.hash.substring(1)
expect(() => parseInvitationCode(copiedCode)).not.toThrow()
const data = parseInvitationCode(copiedCode)
execSync(`${command[process.platform as SupportedPlatformDesktop]} "${composeInvitationDeepUrl(data)}"`)
const commandFull = `${command[process.platform as SupportedPlatformDesktop]} "${composeInvitationDeepUrl(data)}"`
console.log(`Calling ${commandFull}`)
execSync(commandFull)
console.log('Guest opened invitation link')
})

Expand Down
17 changes: 11 additions & 6 deletions packages/e2e-tests/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ 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'

export interface BuildSetupInit {
port?: number
debugPort?: number
useDataDir?: boolean
defaultDataDir?: boolean
dataDir?: string
fileName?: string
}
Expand All @@ -19,19 +20,20 @@ export class BuildSetup {
public debugPort?: number
public dataDir?: string
private child?: ChildProcessWithoutNullStreams
private useDataDir: boolean
private defaultDataDir: boolean
private fileName?: string

constructor({ port, debugPort, useDataDir = true, dataDir, fileName }: BuildSetupInit) {
constructor({ port, debugPort, defaultDataDir = false, dataDir, fileName }: BuildSetupInit) {
this.port = port
this.debugPort = debugPort
this.useDataDir = useDataDir
this.defaultDataDir = defaultDataDir
this.dataDir = dataDir
this.fileName = fileName
if (fileName) {
this.copyInstallerFile(fileName)
}
if (this.useDataDir && !this.dataDir) {
if (this.defaultDataDir) this.dataDir = DESKTOP_DATA_DIR
if (!this.dataDir) {
this.dataDir = `e2e_${(Math.random() * 10 ** 18).toString(36)}`
}
}
Expand Down Expand Up @@ -100,9 +102,12 @@ export class BuildSetup {
public async createChromeDriver() {
await this.initPorts()
const env = {
DATA_DIR: this.dataDir || 'Quiet',
DEBUG: 'backend*,desktop*,utils*',
DATA_DIR: this.dataDir,
}
// if (this.dataDir) {
// env = Object.assign(env, { DATA_DIR: this.dataDir })
// }
if (process.platform === 'win32') {
console.log('!WINDOWS!')
this.child = spawn(`cd node_modules/.bin & chromedriver.cmd --port=${this.port} --verbose`, [], {
Expand Down

0 comments on commit 335677a

Please sign in to comment.