Skip to content

Commit

Permalink
Merge pull request #7 from education/add-error-option-to-status
Browse files Browse the repository at this point in the history
add error as an option in status + tests
  • Loading branch information
jalafel authored Nov 30, 2023
2 parents ed4ad1b + 61ceebc commit 2a1ebec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
23 changes: 17 additions & 6 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ test('test fails on non-existent executable', () => {
INPUT_COMMAND: 'nonexistentcommand',
})

expect(result.status).toBe('fail')
expect(result.status).toBe('error')
expect(result.tests[0].name).toBe('Test 4')
expect(result.tests[0].status).toBe('fail')
expect(result.tests[0].status).toBe('error')
expect(result.tests[0].message).toContain('Unable to locate executable file: nonexistentcommand')
})

Expand All @@ -127,9 +127,9 @@ test('test fails on command timeout', () => {
INPUT_TIMEOUT: '0.01', // ~ 1 second
})

expect(result.status).toBe('fail')
expect(result.status).toBe('error')
expect(result.tests[0].name).toBe('Timeout Test')
expect(result.tests[0].status).toBe('fail')
expect(result.tests[0].status).toBe('error')
expect(result.tests[0].message).toContain('Command timed out')
})

Expand All @@ -153,8 +153,19 @@ test('test fails on setup command timeout', () => {
INPUT_TIMEOUT: '0.01', // ~ 1 second
})

expect(result.status).toBe('fail')
expect(result.status).toBe('error')
expect(result.tests[0].name).toBe('Setup Timeout Test')
expect(result.tests[0].status).toBe('fail')
expect(result.tests[0].status).toBe('error')
expect(result.tests[0].message).toContain('Command timed out')
})

test('awards no points if test errors', () => {
const result = runTestWithEnv({
'INPUT_TEST-NAME': 'Test 4',
INPUT_COMMAND: 'nonexistentcommand',
'INPUT_MAX-SCORE': '100',
})

expect(result.max_score).toBe(100)
expect(result.tests[0].score).toBe(0)
})
2 changes: 1 addition & 1 deletion dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ function generateResult(status, testName, command, message, duration, maxScore)
}
}

function getErrorMessage(error, command) {
function getErrorMessageAndStatus(error, command) {
if (error.message.includes('ETIMEDOUT')) {
return 'Command timed out'
return { status: 'error', errorMessage: 'Command timed out' }
}
if (error.message.includes('command not found')) {
return `Unable to locate executable file: ${command}`
return { status: 'error', errorMessage: `Unable to locate executable file: ${command}` }
}
if (error.message.includes('Command failed')) {
return 'failed with exit code 1'
return { status: 'fail', errorMessage: 'failed with exit code 1' }
}
return error.message
return { status: 'error', errorMessage: error.message }
}

function run() {
Expand All @@ -70,8 +70,8 @@ function run() {
result = generateResult('pass', testName, command, output, endTime - startTime, maxScore)
} catch (error) {
endTime = new Date()
const errorMessage = getErrorMessage(error, command)
result = generateResult('fail', testName, command, errorMessage, endTime - startTime, maxScore)
const {status, errorMessage} = getErrorMessageAndStatus(error, command)
result = generateResult(status, testName, command, errorMessage, endTime - startTime, maxScore)
}

core.setOutput('result', btoa(JSON.stringify(result)))
Expand Down

0 comments on commit 2a1ebec

Please sign in to comment.