codehskarel-tester
v1.0.2
Published
Test karel submissions from codehs using [jskarel](https://github.com/freeuni-digital-technologies/jskarel)
Downloads
3
Readme
Codehskarel-tester
Test karel submissions from codehs using jskarel
coverage:
Usage
Test File syntax
Module should export these objects:
- config with karel starting position
- list of assertions. Function of karel, returning a chai test case
Example
This file checks that karel moved one position north and one position west, and picked up the beeper there
const { expect } = require('chai')
const startingX = 2; // can generate a random number instead
module.exports.config = {
karel: {
position: [startingX, 2]
},
world: {
beepers: [[startingX + 1, 3]]
}
}
module.exports.assertions = [
karel => expect(karel.position).eql({x: startingX + 1, y: 3}, 'karel should finish on 3x3'),
karel => expect(karel.world.beepers).length(0, 'all beepers should be picked up')
]
As a cli program
Output is a json representation of results (test name with )
test-codehs-submission --help
Usage: test-codehs-submission [options]
Options:
-t, --test-file <testFile> test file
-f, --file <file> submission file
As a library
import {testSubmission} from "codehskarel-tester";
// will fail the test if submission does not finish running within 2 seconds
testSubmission('./testFile.js', './submission.txt', 2000)
.then((results: Result[]) => console.log(results))
returned object type:
interface Result {
passed?: boolean
error?: boolean
details?: string // error details
message: string // test description
}