Skip to content

Commit

Permalink
(feature) test running job
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay288 committed Aug 26, 2022
1 parent 1e57279 commit 2c890f4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
list_connections,
update_connection,
} from "./api/connections";
import runAllTests from "services/testing/runAllTests";

dotenv.config();

Expand Down Expand Up @@ -117,6 +118,7 @@ const main = async () => {
app.listen(port, () => {
console.log(`⚡️[server]: Server is running at http://localhost:${port}`);
});
runAllTests();
} catch (err) {
console.error(`CatchBlockInsideMain: ${err}`);
}
Expand Down
6 changes: 6 additions & 0 deletions backend/src/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import schedule from "node-schedule";
import { AppDataSource } from "data-source";
import { JobsService } from "services/jobs";
import runAllTests from "services/testing/runAllTests";

const main = async () => {
const datasource = await AppDataSource.initialize();
Expand All @@ -15,6 +16,11 @@ const main = async () => {
JobsService.generateEndpointsFromTraces();
});

schedule.scheduleJob("30 * * * *", () => {
console.log("Running Tests...");
runAllTests();
});

process.on("SIGINT", () => {
schedule.gracefulShutdown().then(() => process.exit(0));
});
Expand Down
21 changes: 21 additions & 0 deletions backend/src/services/testing/runAllTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { AppDataSource } from "data-source";
import { ApiEndpointTest } from "models";
import { runTest } from "./runTests";

export const runAllTests = async (): Promise<void> => {
const testRepository = AppDataSource.getRepository(ApiEndpointTest);
const allTests = await testRepository.find();
const results = await Promise.all(allTests.map(runTest));
await Promise.all(
allTests.map((test, testIdx) => {
const runResult = results[testIdx];
test.requests = test.requests.map((e, i) => ({
...e,
result: runResult[i],
}));
return testRepository.save(test);
})
);
};

export default runAllTests;

0 comments on commit 2c890f4

Please sign in to comment.