- A playground Node.js environment for testing and debugging pure functions.
- Useful for running local debugger and creating custom test cases for code puzzles from Edabit, Code Wars, etc.
npm install
npm run test
(See Testing Single Challenges for further configuration)- In VS Code, you can run the debugger using the Jest configuration called
Unit Test
listed in.vscode/launch.json
file. Hotkey is F5. This will automatically read thejest.config.js
file - If you get stuck, solutions can be found by running
git checkout solutions
- To run tests for all cases defined for a given challenge, set the property
globals.testSingleChallenge
withinjest.config.js
to the name of the file you wish to test as defined in/challenges
(omit the.js
extension). For example:
// jest.config.js
module.exports = {
globals: {
testSingleChallenge: "add_func"
},
//...
}
- If no value for
globals.testSingleChallenge
is provided, all tests will run for all challenges by default.
- To run a test on a single test case for a given challenge, set the property
globals.testSingleTestCase
withinjest.config.js
to the index of the test case you wish to try. The propertyglobals.testSingleChallenge
must also be defined. For example:
// jest.config.js
module.exports = {
globals: {
testSingleChallenge: "add_func",
testSingleTestCase: 0
},
// ...
}
- Within
/challenges
directory, create a file which contains a default export of the function you wish to test. For example:
// challenges/add_func.js
module.exports = (x, y) => { return x + y };
- In
test-cases.js
add a property (using same name as the file created above) to the default export object which defines an array containing the set of inputs and expected values. Each test case should look something like this:
// test-cases.js
module.exports = {
add_func: [
[
// arguments to be passed the 'add_func' function:
[1, 2],
// expected output of the 'add_func' function:
3
],
[[0, 0], 0],
[[-1, -2], -3],
],
// etc...
}
- The default workflow in
main.test.js
may not work for some scenarios, so custom tests can be added tocustom.test.js
. - By default custom tests are switched off. To enable them, set the property
globals.skipCustomTests
withinjest.config.js
tofalse
. - To run only custom tests, set the property
globals.runCustomTestsOnly
withinjest.config.js
totrue
. This will override the other settings.
- Reach out to Ben Turner for any questions, bugs, or contribution requests.