-
Notifications
You must be signed in to change notification settings - Fork 750
feat: added executor tests #1816
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
Draft
RohitKushvaha01
wants to merge
6
commits into
Acode-Foundation:main
Choose a base branch
from
RohitKushvaha01:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3403337
feat: added executor tests
RohitKushvaha01 2edc3db
Update src/test/exec.tests.js
RohitKushvaha01 3502ba5
feat: added executor tests
RohitKushvaha01 3bedaa2
feat: added delay
RohitKushvaha01 d332a98
feat: added missing import
RohitKushvaha01 9dd7c25
feat: removed missing import
RohitKushvaha01 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,176 @@ | ||
| import { TestRunner } from "./tester"; | ||
|
|
||
| export async function runExecutorTests(writeOutput) { | ||
| const runner = new TestRunner("Executor API Tests"); | ||
|
|
||
| runner.test("Executor available", async (test) => { | ||
| test.assert(typeof Executor !== "undefined", "Executor should be available globally"); | ||
| }); | ||
|
|
||
| runner.test("Background Executor available", async (test) => { | ||
| test.assert(typeof Executor.BackgroundExecutor !== "undefined", "Background Executor should be available globally"); | ||
| }); | ||
|
|
||
|
|
||
| runner.test("execute()", async (test) => { | ||
|
|
||
| test.assert( | ||
| await Executor.execute("echo test123").includes("test123"), | ||
| "Command output should match" | ||
| ); | ||
|
|
||
| }); | ||
|
|
||
|
|
||
|
|
||
| runner.test("execute() (BackgroundExecutor)", async (test) => { | ||
|
|
||
| test.assert( | ||
| await Executor.BackgroundExecutor.execute("echo test123").includes("test123"), | ||
| "Command output should match" | ||
| ); | ||
|
|
||
| }); | ||
|
|
||
| runner.test("start()", async (test) => { | ||
| let stdout = ""; | ||
|
|
||
| const uuid = await Executor.start("sh", (type, data) => { | ||
| if (type === "stdout") stdout += data; | ||
| }); | ||
|
|
||
| await Executor.write(uuid, "echo hello\n"); | ||
| await new Promise(r => setTimeout(r, 200)); | ||
| await Executor.stop(uuid); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
| test.assert(stdout.includes("hello"), "Shell should echo output"); | ||
| }); | ||
|
|
||
|
|
||
| runner.test("start() (BackgroundExecutor)", async (test) => { | ||
| let stdout = ""; | ||
|
|
||
| const uuid = await Executor.BackgroundExecutor.start("sh", (type, data) => { | ||
| if (type === "stdout") stdout += data; | ||
| }); | ||
|
|
||
| await Executor.BackgroundExecutor.write(uuid, "echo hello\n"); | ||
| await new Promise(r => setTimeout(r, 200)); | ||
| await Executor.BackgroundExecutor.stop(uuid); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
| test.assert(stdout.includes("hello"), "Shell should echo output"); | ||
| }); | ||
|
|
||
|
|
||
| runner.test("start/stop()", async (test) => { | ||
| let stdout = ""; | ||
|
|
||
| const uuid = await Executor.start("sh", (type, data) => { | ||
|
|
||
| }); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
|
|
||
| const isRunning = await Executor.isRunning(uuid); | ||
|
|
||
| test.assert(isRunning === true, "Executor must be running"); | ||
|
|
||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
| await Executor.stop(uuid); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
| test.assert(await Executor.isRunning(uuid) === false, "Executor must be stopped"); | ||
|
|
||
| }); | ||
|
|
||
| runner.test("start/stop() (BackgroundExecutor)", async (test) => { | ||
| let stdout = ""; | ||
|
|
||
| const uuid = await Executor.BackgroundExecutor.start("sh", (type, data) => { | ||
|
|
||
| }); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
|
|
||
| const isRunning = await Executor.BackgroundExecutor.isRunning(uuid); | ||
|
|
||
| test.assert(isRunning === true, "Executor must be running"); | ||
|
|
||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
| await Executor.BackgroundExecutor.stop(uuid); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
| test.assert(isRunning !== await Executor.BackgroundExecutor.isRunning(uuid), "Executor must be stopped"); | ||
| test.assert(await Executor.BackgroundExecutor.isRunning(uuid) === false, "Executor must be stopped"); | ||
|
|
||
| }); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| runner.test("start/stop()", async (test) => { | ||
| let stdout = ""; | ||
|
|
||
| const uuid = await Executor.start("sh", (type, data) => { | ||
|
|
||
| }); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
|
|
||
| const isRunning = await Executor.isRunning(uuid); | ||
|
|
||
| test.assert(isRunning === true, "Executor must be running"); | ||
|
|
||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
| await Executor.stop(uuid); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
| test.assert(await Executor.isRunning(uuid) === false, "Executor must be stopped"); | ||
|
|
||
| }); | ||
|
|
||
| runner.test("FDROID env variable", async (test) => { | ||
| const result = await Executor.execute("echo $FDROID"); | ||
|
|
||
| const isSet = result.trim().length > 0; | ||
|
|
||
| test.assert( | ||
| isSet, | ||
| "FDROID env variable should be set" | ||
| ); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| return await runner.run(writeOutput); | ||
| } | ||
This file contains hidden or 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
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.
Environment-dependent test: This test assumes the FDROID environment variable is always set and has a non-empty value. However, this may not be true in all test environments (e.g., local development, CI/CD pipelines, non-F-Droid builds).
Consider using
test.skip()if the environment variable isn't set, or adjust the assertion to handle cases where the variable legitimately might not exist:test.assert(typeof result === 'string', "FDROID env variable should be accessible")Prompt To Fix With AI