Skip to content

Commit 5f364bb

Browse files
committed
remove try catch and expect test to throw error
1 parent 167d0e2 commit 5f364bb

File tree

3 files changed

+18
-41
lines changed

3 files changed

+18
-41
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
},
2121
"dependencies": {
2222
"amqplib": "^0.5.2",
23+
"chai-as-promised": "^7.1.1",
2324
"newrelic": "^6.5.0",
2425
"raven": "^2.6.4",
2526
"shelljs": "^0.8.1"

src/tasks/index.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,16 @@ export async function execute (job: Job) {
2828
scenario = new ProjectScenario()
2929
}
3030

31-
let result
32-
try {
33-
// Setup RUNBOX
34-
await scenario.setup(currentJobDir, job)
31+
// Setup RUNBOX
32+
await scenario.setup(currentJobDir, job)
3533

36-
// Run worker
37-
await scenario.run(currentJobDir, job)
34+
// Run worker
35+
await scenario.run(currentJobDir, job)
3836

39-
// Get result
40-
result = await scenario.result(currentJobDir, job)
41-
}
42-
catch(err) {
43-
result = {
44-
id: job.id,
45-
stderr: err
46-
}
47-
}
37+
// Get result
38+
const result = await scenario.result(currentJobDir, job)
4839

4940
rm('-rf', currentJobDir)
5041

51-
return result;
42+
return result
5243
}

test/project/project.nodejs.spec.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { execute } from '../../src/tasks/'
2-
import { expect } from 'chai'
32
import { ProjectJob } from '../../src/tasks/jobs/project'
43

4+
const chai = require('chai');
5+
const chaiAsPromised = require('chai-as-promised');
6+
const {expect} = chai
7+
chai.use(chaiAsPromised)
58

69
describe('project-nodejs', () => {
710
it('should run nodejs project correctly', async () => {
@@ -50,23 +53,22 @@ describe('project-nodejs', () => {
5053
expect(projectResult.score).to.equal(0)
5154
})
5255

53-
it('should not break when url is invalid', async () => {
54-
const projectResult = await execute(new ProjectJob({
56+
it('should throw error when url is invalid', async () => {
57+
const job = new ProjectJob({
5558
id: 25,
5659
source: 'https://www.invalidurl.com',
5760
problem: 'https://www.invalidurl.com',
5861
submissionDirs: 'src/*',
5962
lang: 'nodejs',
6063
timelimit: 20,
6164
scenario: 'project'
62-
}))
63-
expect(projectResult).to.have.keys(
64-
'id',
65-
'stderr',
66-
)
65+
})
66+
67+
await expect(execute(job)).to.be.rejected;
6768
})
6869

6970
it('should return code = 1 when there is a build error', async () => {
71+
// file downloaded from google.com will not be a nodejs project, hence build error
7072
const projectResult = await execute(new ProjectJob({
7173
id: 25,
7274
source: 'https://www.google.com',
@@ -87,21 +89,4 @@ describe('project-nodejs', () => {
8789
expect(projectResult.code).to.equal(1)
8890
expect(projectResult.score).to.equal(0)
8991
})
90-
91-
it('should not break if lang is incorrect', async () => {
92-
const projectResult = await execute(new ProjectJob({
93-
id: 25,
94-
source: 'https://minio.cb.lk/public/problem.zip',
95-
problem: 'https://minio.cb.lk/public/solution.zip',
96-
submissionDirs: 'src/*',
97-
lang: 'abcd',
98-
timelimit: 20,
99-
scenario: 'project'
100-
}))
101-
102-
expect(projectResult).to.have.keys(
103-
'id',
104-
'stderr',
105-
)
106-
})
10792
})

0 commit comments

Comments
 (0)