-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AXON-37] Implement headless e2e testing
- Loading branch information
1 parent
7a40bb7
commit d250db2
Showing
9 changed files
with
123 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,6 @@ TEMP-* | |
yalc.lock | ||
.env | ||
coverage | ||
.test-extensions/ | ||
.generated/ | ||
e2e/.resources/ | ||
e2e/.test-extensions/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
FROM node:20 | ||
|
||
# Install dependencies and xvfb | ||
RUN apt-get update && apt-get install -y wget gpg xvfb xauth --no-install-recommends | ||
|
||
# Download vscode .deb package and install it (from https://go.microsoft.com/fwlink/?LinkID=760868) | ||
# Otherwise vscode fails to run, probably due to missing dependencies | ||
RUN wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg \ | ||
&& install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg \ | ||
&& echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" | tee /etc/apt/sources.list.d/vscode.list > /dev/null \ | ||
&& rm -f packages.microsoft.gpg \ | ||
&& apt install -y apt-transport-https \ | ||
&& apt update \ | ||
&& apt install -y code \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& npm install -g npm@latest | ||
|
||
# Running vscode as root is not recommended, so let's create a user. | ||
# We need that user's $HOME to exist for the test process to work properly. | ||
RUN useradd -m -s /bin/bash atlascode | ||
|
||
# Set the working directory | ||
# We will mount the whole project directory to WORKDIR | ||
# so it's best to match the WORKDIR folder name with the project directory name, | ||
# otherwise tsc might generate wrong paths for e2e tests | ||
WORKDIR /atlascode | ||
|
||
# Where our vscode, chromedriver, images etc. will go | ||
ENV TEST_RESOURCES=/atlascode/e2e/.resources | ||
|
||
# We want to run `xvfb-run` with the parameters passed to `docker run` | ||
# However, using `xvfb-run` as an entrypoint directly causes docker to hang (?!) | ||
# So, let's create an entrypoint to pass parameters to xvfb-run. | ||
# We'll do this in-place to not have any build context for this Dockerfile: | ||
RUN cat <<EOF > /usr/bin/entrypoint.sh && chmod +x /usr/bin/entrypoint.sh | ||
#!/usr/bin/env bash | ||
echo "Invoking xvfb-run with the following arguments: \$@" | ||
xvfb-run \$@ | ||
EOF | ||
|
||
ENTRYPOINT ["/usr/bin/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Build the docker iamge for e2e tests | ||
# Explicitly using empty context to avoid unnecessary rebuilds, | ||
# since we'll be mounting the whole work folder when using the image | ||
docker build --platform linux/amd64 --tag atlascode-e2e - <e2e/Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Usage: | ||
# e2e/scripts/in-docker some-fancy-command --with-args | ||
|
||
docker run \ | ||
--platform linux/amd64 \ | ||
-v $(pwd):/atlascode \ | ||
--user atlascode \ | ||
-it \ | ||
atlascode-e2e $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,62 @@ | ||
// import the webdriver and the high level browser wrapper | ||
import { assert } from 'chai'; | ||
import { before, VSBrowser, WebDriver } from 'vscode-extension-tester'; | ||
import { expect } from 'chai'; | ||
import { before, VSBrowser, WebDriver, ActivityBar, after } from 'vscode-extension-tester'; | ||
import { describe, it } from 'mocha'; | ||
|
||
// Let's make sure we can import something from the src folder if needed | ||
import { AuthInfoVersionKey } from '../../src/constants'; | ||
|
||
// Create a Mocha suite | ||
describe('My Test Suite', () => { | ||
describe('Atlassian Extension', async () => { | ||
let browser: VSBrowser; | ||
let driver: WebDriver; | ||
|
||
console.log('Oh look, a constant from src!'); | ||
console.log('AuthInfoVersionKey:', AuthInfoVersionKey); | ||
|
||
const { log, debug, info, warn } = console; | ||
// initialize the browser and webdriver | ||
before(async () => { | ||
// Mocking console.log | ||
global.console = { | ||
...console, | ||
log: () => {}, | ||
debug: () => {}, | ||
info: () => {}, | ||
warn: () => {}, | ||
}; | ||
|
||
browser = VSBrowser.instance; | ||
driver = browser.driver; | ||
}); | ||
|
||
after(async () => { | ||
// reset global.console | ||
global.console = { | ||
...console, | ||
log, | ||
debug, | ||
info, | ||
warn, | ||
}; | ||
}); | ||
|
||
// test whatever we want using webdriver, here we are just checking the page title | ||
it('My Test Case', async () => { | ||
const title = await driver.getTitle(); | ||
assert.isTrue(title === 'Getting Started' || title === 'Walkthrough: Setup VS Code'); | ||
expect(title).to.be.oneOf([ | ||
'Getting Started', | ||
'Walkthrough: Setup VS Code', | ||
'Getting Started - Visual Studio Code', | ||
]); | ||
}); | ||
|
||
it('should be installed', async () => { | ||
const activityBar = new ActivityBar(); | ||
const controls = await activityBar.getViewControls(); | ||
// Get title from every control | ||
const titles = await Promise.all(controls.map(async (control) => control.getTitle())); | ||
|
||
expect('Atlassian').to.be.oneOf(titles); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters