Skip to content

Commit 4d9a69a

Browse files
authored
Merge pull request #48 from https-sam/dev
fixed unit test case - async done() for readfile
2 parents 25c5792 + 66b009e commit 4d9a69a

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

__tests__/code-excution/python.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { mainClassName } from "../../src/config";
2+
import { CodeContext } from "../../src/types/worker";
23
import JobWorker from "../../src/worker";
4+
import fs from 'fs'
35

46
describe("Python transform into executable", () => {
57
const functionName = "solution"
@@ -11,22 +13,22 @@ describe("Python transform into executable", () => {
1113
})
1214

1315

14-
// TODO needs some work, cannot seem to ready file here, and is being recognized as success
15-
16-
// describe("Python code excution test", () => {
17-
// it('should calculate a frequency in string', () => {
18-
// expect.assertions(1);
19-
20-
// fs.readFile(`${__dirname}/../test-code/python/counter.py`, 'utf8', async (error, code) => {
21-
// const codeContext: CodeContext = {
22-
// code: code,
23-
// functionName: "calculate"
24-
// }
25-
// const worker = new JobWorker("python3", codeContext);
26-
// const response = await worker.startContainer()
27-
// console.log(response)
28-
// expect(response.codeOutput).toBe("Counter({'a': 2, 's': 2, 'w': 2, 'e': 2, 'l': 1, 'd': 1, 'k': 1})")
29-
// await worker.cleanupJob();
30-
// });
31-
// })
32-
// })
16+
describe("Python code excution test", () => {
17+
let code: string
18+
beforeAll((done) => {
19+
fs.readFile(`${__dirname}/../test-code/python/counter.py`, 'utf8', (err, data) => {
20+
code = data
21+
done()
22+
})
23+
})
24+
it('should calculate a frequency in string', async () => {
25+
const codeContext: CodeContext = {
26+
code: code,
27+
functionName: "calculate"
28+
}
29+
const worker = new JobWorker("python3", codeContext);
30+
const response = await worker.startContainer()
31+
expect(response.codeOutput).toBe("Counter({'a': 2, 's': 2, 'w': 2, 'e': 2, 'l': 1, 'd': 1, 'k': 1})")
32+
await worker.cleanupJob();
33+
})
34+
})

0 commit comments

Comments
 (0)