

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Welcome
incomplete
2: TypeScript Setup
incomplete
3: Normalize URLs
incomplete
4: Extract Page Content
incomplete
5: Extract Links and Images
incomplete
6: Structure Page Data
incomplete
This lesson's interactive features are locked, please to keep using them
Test-driven development is a popular method of writing software. The idea is that you write tests for your code first, then you write the code that gets the tests to pass. We're going to approach this project using a bit of TDD.
We need a function that accepts a URL string as input and returns a "normalized" URL. To "normalize" means to "make the same". For example, all of these URLs are the "same page" according to most websites and HTTP standards:
https://www.boot.dev/blog/path/https://www.boot.dev/blog/pathhttp://www.boot.dev/blog/path/http://www.boot.dev/blog/pathWe want our normalizeURL() function to map all of those same inputs to a single normalized output: www.boot.dev/blog/path.
Keep in mind, the normalized URL isn't going to be used to make requests, it's just going to be used to compare URLs to see if they are the same page.
In test driven development (TDD), you typically follow this flow:
You are going to be using the Vitest testing library for TypeScript.
npm install -D vitest
...
"scripts": {
"start": "tsx ./src/index.ts",
"test": "vitest run"
},
...
I'd recommend you read up on Vitest's getting started guide here. By default, the vitest command will look for files that end in .test.ts, so write your first tests in a file called crawl.test.ts in the src directory.
Run and submit the CLI tests from the root of the module.