Question: In this assignment you will create a character creation system for a fantasy video game. You will use TDD principles with Jest and Node.js s

In this assignment you will create a character creation system for a fantasy video game. You will use TDD principles with Jest and Node.jss built-in fs module. You can choose to use either the callback methods or promise methods (async/await). Requirements:
1. Project Structure: Your project should have the following structure: fantasy-character-creation src character-creation.js test character-creation.spec.js package.json
2. TDD: You must follow TDD principles. Write your tests first, then write the code to make the tests pass.
3. Unit Tests: You must write at least three-unit tests:
a. Test that data can be written to a file.
b.b. Test that data can be read from a file
c.c. Test that it handles errors when reading from the file
4. File Operations: You must use __diranme, readFile, and writeFile. And, you must const variables for each file name.
5. Character Creation: Your program should allow the creation of a character with the following properties:
a. Class (Warrior, Mage, Rogue)
b. Gender (Male, Female, Other)
c. An additional property for something neat and fun about your character.
6. File Data: Your program should write character data to a file and read character data from the file.
7. Package.json: Add a test script to the package.json file to run your tests with Jest Instructions:
1. Set up your project structure as describe in the Requirements section.
2. Write your first test in character-creation.spec.js. This test should check that data can be written to a file.
3. Run your test script to confirm that the test fails.
4. Write code in the character-creation.js to make the test pass.
5. Run your test script again to confirm that the test now passes.
6. Repeat steps 2-5 for the remaining two tests.
7. Make sure to handle errors property in your code and tests.
Hints:
Use the fs modules readFIle and writeFile functions to read from and write to files.
Use __dirname to get the directory name of the current module.
Use const variables for each file name. 182
Remember to follow TDD principles: write your test first, then write code to make the test pass.
"use strict";
/**
* This file allows you to choose between using callbacks or promises (async/await) for handling asynchronous operations.
\square
* If you want to use callbacks:
*1. Uncomment the 'fs' require statement under the "For callbacks" comment.
*
* If you want to use promises (async/await):
*1. Uncomment the 'fs' require statement under the "For promises" comment.
*/
// For callbacks:
// const fs = require('fs');
// For promises:
// const fs = require('fs').promises;
describe("Character Creation Module", ()=>{
let createCharacter;
let getCharacters;
beforeEach(()=>{
jest.resetModules();
// Set up your mocks here
({ createCharacter, getCharacters }= require('../src/character-creation'));
});
// TODO: Write your tests here. You should have at least three tests:
//1. Test that createCharacter writes a new character to the file
//2. Test that getcharacters reads characters from the file
//3. Test that createcharacter handles errors when writing to the file
});
```
"use strict";
/*
* This file allows you to choose between using callbacks or promises (async/await) for handling asynchronous operations.
*
* If you want to use callbacks:
*1. Uncomment the 'fs' require statement under the "For callbacks" comment.
*2. Uncomment the 'createcharacter' and 'getcharacters' functions under the "For callbacks" comment.
*3. Uncomment the 'module.exports' line under the "For callbacks" comment.
*
* If you want to use promises (async/await):
*1. Uncomment the 'fs' require statement under the "For promises" comment.
*2. Uncomment the 'createcharacter' and 'getcharacters' functions under the "For promises" comment.
*3. Uncomment the 'module.exports' line under the "For promises" comment.
*/
// For callbacks:
/*
const fs = require('fs');
function createCharacter(character, callback){
// TODO Implement this function
}
function getcharacters(callback){
// TODO- Implement this function
}
*/
// For promises:
/*
const fs = require('fs').promises;
async function createcharacter(character){
// TODOH Implement this function
}
``````
JS character-creation.js
src > JS character-creation.js
30}
37
38 async function getCharacters(){
39// TODO Implement this function
40}
41*/
42
43// Uncomment the appropriate exports depending on whether you're using callbacks or promises:
44
45// module.exports ={ createCharacter, getCharacters }; // For callbacks
46// module.exports ={ createCharacter, getCharacters }; // For promises
``````
{} package.json
{} package.json >...
{
"name": "fantasy-character-creation",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "test"
},
\triangleright Debug
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/jest": "^29.5.11",
"jest
In this assignment you will create a character

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!