-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: frontend test framework setup with playwright #268
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
7178168
test: frontend test framework setup with playwright
raaymax bd2c6cb
chore: added to CI
raaymax 61e2bc9
chore: disable frontend tests on CI
raaymax a248ec7
chore: fix linter errors in tests
raaymax b7065d1
tests: testing drag and drop of components
raaymax 1b5beec
refactor: playwright tests are now e2e_tests
raaymax 793c074
chore: added more tests
raaymax 7795b1e
ci: added e2e tests to ci workflow
raaymax 8e67c10
chore: working on adding e2e tests to ci
raaymax 5e2b521
chore: trying separate gh action for playwright
raaymax 18bb586
chore: CI test
raaymax 8f292a8
chore: package lock update
raaymax 699d01e
chore: fixed alferd ci
raaymax 2afd896
chore: ci job check
raaymax 82f4cdf
chore: fixed e2e action issue
raaymax 7a92821
chore: removed unnecesarry steps
raaymax 9cbf228
tests: fixing e2e tests on CI
raaymax 833bdb7
tests: added artifacts
raaymax ac68175
Merge branch 'dev' into frontend-tests
raaymax 9bddde8
chore: scripts to main package.json
raaymax 4dbfb26
chore: added missing script to package.json
raaymax 2dd527c
chore: date input fix
raaymax 3244c09
chore: fixed ocational server startup error
raaymax 379ea51
chore: fixed failing tests
raaymax f31fe0f
build: building all parts at once
raaymax eb08d1d
build: separated docs build from main build
raaymax b733cae
ci: add job for each browser
raaymax 54cea33
ci: use of matrix strategy to run tests in parallel
raaymax c144c5a
ci: fix e2e running in all ci runs
raaymax 45e26ea
fix: added masks to failing components
raaymax ee02678
ci: fixed firefox issues and installing only necessary packages
raaymax 494087f
Merge branch 'dev' into frontend-tests
raaymax ea810c3
tests: added missing tests
raaymax 09b21dc
tests: retriable tests
raaymax e052d17
chore: changes according to review
raaymax 4c2d267
style: code cleanup
raaymax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: ci-e2e | ||
on: | ||
push: | ||
branches: [ dev, master] | ||
pull_request: | ||
branches: [ dev, master] | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
browser: [ "chromium", "firefox", "webkit" ] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python 3.11.8 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.11.8" | ||
|
||
- name: Use Node.js 18 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
|
||
- name: update package manager & install python3 environment | ||
run: | | ||
sudo pip install poetry | ||
poetry install --with build | ||
|
||
- name: Install npm dependencies | ||
run: npm ci | ||
|
||
- name: Build UI | ||
run: npm run build | ||
|
||
- name: Install E2E browsers | ||
working-directory: e2e_tests | ||
run: npx playwright install ${{ matrix.browser }} --with-deps | ||
|
||
- name: Run E2E tests | ||
run: poetry run alfred ci --e2e=${{ matrix.browser }} |
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
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
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
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 @@ | ||
runtime/ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
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,148 @@ | ||
const express = require("express"); | ||
const fs = require("node:fs").promises; | ||
const { spawn } = require("node:child_process"); | ||
const httpProxy = require("http-proxy"); | ||
|
||
class Streamsync { | ||
constructor() { | ||
this.process = null; | ||
this.initialized = false; | ||
this.port = 7358; | ||
this.busy = false; | ||
} | ||
|
||
async start() { | ||
return new Promise((resolve, reject) => { | ||
if (this.process !== null) { | ||
this.process.kill(); | ||
} | ||
const ss = spawn( | ||
"streamsync", | ||
["edit", "./runtime", "--port", this.port] | ||
); | ||
this.process = ss; | ||
const startupTimeout = setTimeout(() => { | ||
// eslint-disable-next-line no-console | ||
console.error("Streamsync startup timeout"); | ||
ss.kill(); | ||
reject(); | ||
}, 5000); | ||
|
||
ss.stdout.on("data", (data) => { | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
`[${ss.pid}] stdout: ${Buffer.from(data, "utf-8").toString()}`, | ||
); | ||
if (data.includes("Builder is available at")) { | ||
this.initialized = true; | ||
clearTimeout(startupTimeout); | ||
resolve(ss); | ||
} | ||
}); | ||
|
||
ss.stderr.on("data", (data) => { | ||
// eslint-disable-next-line no-console | ||
console.error(`[${ss.pid}] stderr: ${data}`); | ||
}); | ||
|
||
ss.on("close", () => { | ||
// eslint-disable-next-line no-console | ||
console.log(`[${ss.pid}] child process closed`); | ||
}); | ||
ss.on("error", (err) => { | ||
// eslint-disable-next-line no-console | ||
console.log(`[${ss.pid}] child process error`, err); | ||
}); | ||
ss.on("exit", (code) => { | ||
// eslint-disable-next-line no-console | ||
this.process = null; | ||
console.log( | ||
`[${ss.pid}] child process exited with code ${code}`, | ||
); | ||
}); | ||
}); | ||
} | ||
|
||
async stop() { | ||
return new Promise((resolve) => { | ||
if (this.process) { | ||
this.process.once("exit", () => { | ||
resolve(); | ||
}); | ||
this.process.kill("SIGTERM"); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
} | ||
|
||
async restart() { | ||
this.busy = true; | ||
try { | ||
await this.stop(); | ||
this.port += 1; | ||
await this.start(); | ||
} catch (e) { | ||
throw e; | ||
} finally { | ||
this.busy = false; | ||
} | ||
} | ||
|
||
async loadPreset(preset) { | ||
this.busy = true; | ||
try { | ||
await this.stop(); | ||
this.port += 1; | ||
await fs.copyFile(`./presets/${preset}/ui.json`, "./runtime/ui.json"); | ||
await fs.copyFile(`./presets/${preset}/main.py`, "./runtime/main.py"); | ||
await this.start(); | ||
} catch (e) { | ||
throw e; | ||
} finally { | ||
this.busy = false; | ||
} | ||
} | ||
} | ||
|
||
const ss = new Streamsync(); | ||
(async () => { | ||
await fs.mkdir("runtime", { recursive: true }); | ||
})(); | ||
|
||
var proxy = httpProxy.createProxyServer(); | ||
|
||
proxy.on('error', function (e) { | ||
// eslint-disable-next-line no-console | ||
console.error(e); | ||
}); | ||
|
||
const app = express(); | ||
|
||
app.get("/preset/:preset", async (req, res) => { | ||
if(ss.busy) { | ||
res.status(429).send("Server is busy"); | ||
return; | ||
} | ||
console.log("Loading preset", req.params.preset); | ||
const preset = req.params.preset; | ||
await ss.loadPreset(preset); | ||
res.send("UI updated"); | ||
}); | ||
|
||
app.use((req, res) => { | ||
if(ss.initialized === false) { | ||
res.send("Server not initialized yet"); | ||
return; | ||
} | ||
proxy.web(req, res, {target: 'http://127.0.0.1:'+ ss.port}); | ||
}) | ||
|
||
const server = app.listen(7357, () => { | ||
// eslint-disable-next-line no-console | ||
console.log("Server is running on port 7357"); | ||
}); | ||
|
||
server.on('upgrade', (req, socket, head) => { | ||
proxy.ws(req, socket, head, {target: 'ws://127.0.0.1:'+ss.port, ws: true}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any ideas to make this less hacky in the future? Something like a health check, some signal I don't know about?
Probably useful for other purposes too.