|
| 1 | +# V School Code Talk Challenges |
| 2 | + |
| 3 | +### About |
| 4 | +- A playground Node.js environment for testing and debugging pure, single functions. |
| 5 | +- Useful for running local debugger and creating custom test cases for code puzzles from Edabit, Code Wars, etc. |
| 6 | + |
| 7 | +### Getting Started |
| 8 | +- `npm install` |
| 9 | +- `npm run test` |
| 10 | +- 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 the `jest.config.js` file |
| 11 | + |
| 12 | +### Creating Custom Challenges |
| 13 | +- Within `/challenges` directory, create a file which contains a default export of the function you wish to test. For example: |
| 14 | +```js |
| 15 | +// challenges/add_func.js |
| 16 | +module.exports = (x, y) => { return x + y }; |
| 17 | +``` |
| 18 | + |
| 19 | +- 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: |
| 20 | + |
| 21 | +```js |
| 22 | +// test-cases.js |
| 23 | +module.exports = { |
| 24 | + add_func: [ |
| 25 | + [ |
| 26 | + // arguments to be passed the 'add_func' function: |
| 27 | + [1, 2], |
| 28 | + // expected output of the 'add_func' function: |
| 29 | + 3 |
| 30 | + ], |
| 31 | + [[0, 0], 0], |
| 32 | + [[-1, -2], -3], |
| 33 | + ], |
| 34 | + // etc... |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +### Testing Single Challenges |
| 39 | +- To run tests for all cases defined for a given challenge, set the property `globals.testSingleChallenge` within `jest.config.js` to the name of the file you wish to test as defined in `/challenges` (omit the `.js` extension). For example: |
| 40 | +```js |
| 41 | +// jest.config.js |
| 42 | +module.exports = { |
| 43 | + globals: { |
| 44 | + testSingleChallenge: "example" |
| 45 | + }, |
| 46 | + //... |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +### Testing Single Test Cases |
| 51 | +- To run a test on a single test case for a given challenge, set the property `globals.testSingleTestCase` within `jest.config.js` to the index of the test case you wish to try. The property `globals.testSingleChallenge` must also be defined. For example: |
| 52 | +```js |
| 53 | +// jest.config.js |
| 54 | +module.exports = { |
| 55 | + globals: { |
| 56 | + testSingleChallenge: "example", |
| 57 | + testSingleTestCase: 0 |
| 58 | + }, |
| 59 | + // ... |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +### [Changelog](./changelog.md) |
| 64 | + |
| 65 | +### Author |
| 66 | +- Reach out to [Ben Turner](bbgrabbag@gmail.com) for any questions, bugs, or contribution requests. |
0 commit comments