freeCodeCamp / freeCodeCamp/back-end-development-and-apis
Expected code in instructions
- Dominant language
- JavaScript
- Stars
- 32
- Forks
- 217
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
In the Build a Bank API workshop (and others as well), the expected code is always part of the instructions. One could simply go ahead by copying and pasting the provided code blocks.
Where the code is placed is also often irrelevant because regex tests do no verify that the code works. Also, functionalities are partially tested.
For example, lesson 5 instructions:
>Create a new file called `db.js`. This module will handle reading and writing `accounts.json` so the rest of your server doesn't have to worry about file I/O.
>
>Import `readFile` and `writeFile` from Node's built-in `fs/promises` module, then export two async functions - `getAccounts` reads and parses `accounts.json`, and `saveAccounts` writes updated data back to it:
>
>```js
>import { readFile, writeFile } from "fs/promises";
>import { join, dirname } from "path";
>import { fileURLToPath } from "url";
>
>const __dirname = dirname(fileURLToPath(import.meta.url));
>const DB_PATH = join(__dirname, "accounts.json");
>
>export async function getAccounts() {
> const data = await readFile(DB_PATH, "utf8");
> return JSON.parse(data);
>}
>
>export async function saveAccounts(accounts) {
> await writeFile(DB_PATH, JSON.stringify(accounts, null, 2));
>}
>```
---
You can either copy and paste this code and pass, or simply do this:
```js
// import { readFile, writeFile } from "fs/promises";
// export function getAccounts() {}
// export function saveAccounts() {}
```
I know writing robust tests can be tricky but I believe we should improve this aspect in some way. Any thoughts?
Contributor guide
Research direction
Review the Build a Bank API lesson 5 instructions, including db.js and accounts.json, alongside the existing regex tests. Determine how the tests can verify behavior and meaningful code placement rather than accepting empty exports or copied snippets; done means incomplete implementations no longer pass while valid solutions do.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- content, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100