Skip to content

Commit

Permalink
refactor(e2e): clean up settings test suite
Browse files Browse the repository at this point in the history
- Sets "waitFor" timeout globally
- Extracts some functions to helper files
- Generally cleans up the test suite

Signed-off-by: Zacharias Fragkiadakis <[email protected]>
  • Loading branch information
QZera committed Jan 6, 2025
1 parent 88d7fbe commit b79dae5
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 68 deletions.
8 changes: 8 additions & 0 deletions test/e2e/helpers/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import type { Workbench } from 'wdio-vscode-service'
import { Key } from 'webdriverio'

export async function clearInput(input: WebdriverIO.Element) {
// Focus the input, sometimes clicking doesn't work
await input.setValue('')
await browser.keys([Key.Ctrl, 'a'])
await browser.keys(Key.Backspace)
}

/**
* Opens the Radicle view container in the sidebar, by clicking the radicle button in the
Expand Down
29 changes: 22 additions & 7 deletions test/e2e/helpers/assertions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import { browser } from '@wdio/globals'
import type { Workbench } from 'wdio-vscode-service'
import type { OutputView, Workbench } from 'wdio-vscode-service'

/**
* Asserts the output view contains the expected text.
*/
export async function expectOutputToContain(outputView: OutputView, expected: string) {
await browser.waitUntil(
async () => {
/**
* The text in the output console is split by newlines, which can be affected by the size
* of the window. To avoid this, we join the text into a single string.
*/
const joinedText = (await outputView.getText()).join('')

return joinedText.includes(expected)
},
{
timeoutMsg: `expected the output text to contain "${expected}"`,
},
)
}

/**
* Asserts that the CLI Commands and Patches sections are visible in the sidebar. This is
Expand All @@ -23,11 +43,6 @@ export async function expectStandardSidebarViewsToBeVisible(workbench: Workbench
return false
}
},
{
timeoutMsg: 'expected the standard sidebar views to be visible',
// TODO: zac fine tune these (globally?)
timeout: 20000,
interval: 500,
},
{ timeoutMsg: 'expected the standard sidebar views to be visible' },
)
}
98 changes: 38 additions & 60 deletions test/e2e/specs/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ import isEqual from 'lodash/isEqual'
import { Key } from 'webdriverio'
import { $ } from 'zx'
import { getFirstWelcomeViewText } from '../helpers/queries'
import { expectStandardSidebarViewsToBeVisible } from '../helpers/assertions'
import { closeRadicleViewContainer, openRadicleViewContainer } from '../helpers/actions'
import {
expectOutputToContain,
expectStandardSidebarViewsToBeVisible,
} from '../helpers/assertions'
import {
clearInput,
closeRadicleViewContainer,
openRadicleViewContainer,
} from '../helpers/actions'
import { nodeHomePath } from '../constants/config'

const tempNodeHomePath = `${nodeHomePath}.temp`

describe('Settings', () => {
let workbench: Workbench
let settings: SettingsEditor
Expand Down Expand Up @@ -35,8 +44,7 @@ describe('Settings', () => {
})

after(async () => {
const searchBox = await getSettingsSearchBox(settings)
await clearInput(searchBox)
await clearInput(await getSettingsSearchBox(settings))
})

afterEach(async () => {
Expand All @@ -46,14 +54,12 @@ describe('Settings', () => {
})

it('warns the user if the rad binary is not found', async () => {
await browser.pause(1000)
await setTextSettingValue(pathToRadBinarySetting, '/tmp')

await expectRadBinaryNotFoundToBeVisible(workbench)
})

it('recognizes the rad binary when a valid path is specified', async () => {
const tempNodeHomePath = `${nodeHomePath}.temp`
await $`cp -r ${nodeHomePath} ${tempNodeHomePath}`

await setTextSettingValue(pathToRadBinarySetting, `/tmp`)
Expand All @@ -70,8 +76,6 @@ describe('Settings', () => {
// This functionality does not seem to work
// eslint-disable-next-line max-len
it.skip('recognizes if the directory is created *after* the setting is updated', async () => {
const tempNodeHomePath = `${nodeHomePath}.temp`

await setTextSettingValue(pathToRadBinarySetting, tempNodeHomePath)

await expectRadBinaryNotFoundToBeVisible(workbench)
Expand All @@ -80,13 +84,18 @@ describe('Settings', () => {

await expectStandardSidebarViewsToBeVisible(workbench)

await clearTextSetting(pathToRadBinarySetting)

await $`rm -rf ${tempNodeHomePath}`
})
})

describe('VS Code, when updating the "Path to Radicle to Node Home" setting,', () => {
/**
* In Linux CI:
* - The extension is having issues resolving the correct node home directory (RAD_HOME).
* - Even when node home is set explicitly in the settings, the extension incorrectly reports it
* as non-authenticated.
*/
// eslint-disable-next-line max-len
describe('VS Code, when updating the "Path to Radicle to Node Home" setting, @skipLinuxCI', () => {
let pathToNodeHomeSetting: Setting
let outputView: OutputView

Expand All @@ -101,56 +110,47 @@ describe('Settings', () => {
})

after(async () => {
const searchBox = await getSettingsSearchBox(settings)
await clearInput(searchBox)
await clearInput(await getSettingsSearchBox(settings))
})

afterEach(async () => {
await outputView.clearText()
await clearTextSetting(pathToNodeHomeSetting)

await expectOutputToContain(outputView, 'Using already unsealed Radicle identity')
await expectRadicleIdentityToBeFound(outputView)
})

/**
* In Linux CI:
* - The extension is having issues resolving the correct node home directory (RAD_HOME).
* - Even when set explicitly in the settings, the extension incorrectly reports it as
* non-authenticated.
*/
it('logs an error in the output console if the path is invalid @skipLinuxCI', async () => {
it('logs an error in the output console if the path is invalid', async () => {
await outputView.clearText()

await setTextSettingValue(pathToNodeHomeSetting, '/tmp')

await expectOutputToContain(outputView, '✗ Error: Radicle profile not found in')
await expectRadicleProfileNotToBeFound(outputView)
})

it('recognizes when a valid path is specified @skipLinuxCI', async () => {
const tempNodeHomePath = `${nodeHomePath}.temp`
it('recognizes when a valid path is specified', async () => {
await $`cp -r ${nodeHomePath} ${tempNodeHomePath}`
await outputView.clearText()

await setTextSettingValue(pathToNodeHomeSetting, tempNodeHomePath)

await expectOutputToContain(outputView, 'Using already unsealed Radicle identity')
await expectRadicleIdentityToBeFound(outputView)

await $`rm -rf ${tempNodeHomePath}`
})

// This functionality does not seem to work
// eslint-disable-next-line max-len
it.skip('recognizes if the directory is created *after* the setting is updated @skipLinuxCI', async () => {
const tempNodeHomePath = `${nodeHomePath}.temp`
it.skip('recognizes if the directory is created *after* the setting is updated', async () => {
await outputView.clearText()

await setTextSettingValue(pathToNodeHomeSetting, tempNodeHomePath)

await expectOutputToContain(outputView, '✗ Error: Radicle profile not found in')
await expectRadicleProfileNotToBeFound(outputView)

await $`cp -r ${nodeHomePath} ${tempNodeHomePath}`

await expectOutputToContain(outputView, 'Using already unsealed Radicle identity')
await expectRadicleIdentityToBeFound(outputView)

await $`rm -rf ${tempNodeHomePath}`
})
Expand All @@ -162,8 +162,6 @@ async function expectRadBinaryNotFoundToBeVisible(workbench: Workbench) {
async () => {
const welcomeText = await getFirstWelcomeViewText(workbench)

console.log({ welcomeText })

return isEqual(welcomeText, [
/* eslint-disable max-len */
'Failed resolving the Radicle CLI binary.',
Expand All @@ -172,15 +170,18 @@ async function expectRadBinaryNotFoundToBeVisible(workbench: Workbench) {
/* eslint-enable max-len */
])
},
{
timeoutMsg: 'expected the rad binary not found message to be visible',
// TODO: zac fine tune these (globally?)
timeout: 20000,
interval: 500,
},
{ timeoutMsg: 'expected the rad binary not found message to be visible' },
)
}

async function expectRadicleIdentityToBeFound(outputView: OutputView) {
await expectOutputToContain(outputView, 'Using already unsealed Radicle identity')
}

async function expectRadicleProfileNotToBeFound(outputView: OutputView) {
await expectOutputToContain(outputView, '✗ Error: Radicle profile not found in')
}

/**
* Workaround to get the value of a `TextSetting`.
* The `getValue` method of a `TextSetting` seems to be wrongly implemented and returns null.
Expand Down Expand Up @@ -214,26 +215,3 @@ async function clearTextSetting(setting: Setting) {
async function getSettingsSearchBox(settings: SettingsEditor) {
return await settings.elem.$(settings.locatorMap.Editor['inputArea'] as string)
}

async function clearInput(input: WebdriverIO.Element) {
await input.setValue('')
await browser.keys([Key.Ctrl, 'a'])
await browser.keys(Key.Backspace)
}

async function expectOutputToContain(outputView: OutputView, expected: string) {
await browser.waitUntil(
async () => {
/**
* The text in the output console is split by newlines, which can be affected by the size
* of the window. To avoid this, we join the text into a single string.
*/
const joinedText = (await outputView.getText()).join('')

return joinedText.includes(expected)
},
{
timeoutMsg: `expected the output text to contain "${expected}"`,
},
)
}
2 changes: 1 addition & 1 deletion test/e2e/wdio.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const config: Options.Testrunner = {
},
],
logLevel: 'warn',
waitforTimeout: 10000,
waitforTimeout: 20000,
services: [['vscode', { cachePath: path.join(rootDirPath, 'node_modules/.cache/wdio') }]],
framework: 'mocha',
reporters: ['spec'],
Expand Down

0 comments on commit b79dae5

Please sign in to comment.