Skip to content

Commit

Permalink
feat: test runner stop and delay
Browse files Browse the repository at this point in the history
  • Loading branch information
anwarulislam committed Dec 14, 2023
1 parent 2bbdf25 commit 1c03367
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
Expand Up @@ -50,6 +50,7 @@
<HttpTestRunnerResult
:config="testRunnerConfig"
:collection="collection"
:stop-running="stopRunningTest"
/>
</div>

Expand Down
Expand Up @@ -51,7 +51,7 @@
<script setup lang="ts">
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
import { SmartTreeAdapter } from "@hoppscotch/ui/dist/helpers/treeAdapter"
import { ref, onMounted, computed, watch } from "vue"
import { ref, computed, watch } from "vue"
import { useI18n } from "~/composables/i18n"
import { TestRunnerCollectionsAdapter } from "~/helpers/runner/adapter"
import { TestRunnerService } from "~/services/test-runner/test-runner.service"
Expand All @@ -64,13 +64,22 @@ const testRunnerService = useService(TestRunnerService)
const props = defineProps<{
collection: HoppCollection<HoppRESTRequest>
config: TestRunnerConfig
stopRunning: boolean
}>()
const selectedTestTab = ref("all_tests")
const showCheckbox = ref(false)
const runnerState = testRunnerService.runTests(props.collection, props.config)
const stopRunningTest = computed(() => {
console.log("stopRunningTest", props.stopRunning)
return props.stopRunning
})
const runnerState = testRunnerService.runTests(props.collection, {
...props.config,
stopRef: stopRunningTest,
})
watch(
() => runnerState.value,
Expand All @@ -86,23 +95,6 @@ const result = computed(() => {
return [runnerState.value.result]
})
// const runTest = async () => {
// const state = testRunnerService.runTests(props.collection, props.config)
// watch(
// () => state,
// () => {
// runnerState.value = state.value
// },
// {
// deep: true,
// }
// )
// }
// onMounted(() => {
// runTest()
// })
const collectionAdapter: SmartTreeAdapter<any> =
new TestRunnerCollectionsAdapter(result)
</script>
Expand Up @@ -15,7 +15,7 @@ export type TestRunState = {
}

export type TestRunnerOptions = {
stop?: Ref<boolean>
stopRef: Ref<boolean>
} & TestRunnerConfig

export type TestRunnerRequest = HoppRESTRequest & {
Expand All @@ -32,6 +32,14 @@ export type TestRunnerRequest = HoppRESTRequest & {
testResults?: HoppTestResult | null
}

/**
* Delays the execution of the script
* @param timeMS The time to wait in milliseconds
*/
function delay(timeMS: number) {
return new Promise((resolve) => setTimeout(resolve, timeMS))
}

/**
* This service is responsible to run requests and tests of collections
*/
Expand Down Expand Up @@ -66,11 +74,20 @@ export class TestRunnerService extends Service {
options: TestRunnerOptions
) {
for (const folder of collection.folders) {
if (options.stopRef?.value) {
state.value.status = "stopped"
break
}
await this.runTestCollection(state, folder, options)
}

for (const request of collection.requests) {
if (options.stopRef?.value) {
state.value.status = "stopped"
break
}
await this.runTestRequest(state, request, options)
await delay(options.delay ?? 0)
}
}

Expand Down

0 comments on commit 1c03367

Please sign in to comment.