Creating New Project Files
Creating New Files with Codex
In this unit, you'll explore how Codex can help you create entirely new files and populate them with useful content — just by describing what you want. This includes writing new TypeScript files, generating code from scratch, and setting up files such as unit tests.
This hands-on unit focuses on expanding your workflow to include file generation and scaffolding, making Codex a powerful tool not just for editing — but also for building.
Understanding Jest for Testing
Before we dive into generating test files, let's briefly cover Jest — the testing framework you'll use in this unit. Jest is a popular JavaScript testing framework that makes it easy to write and run tests. When you write tests in Jest, you use three main functions:
describe(): Groups related tests togethertest()orit(): Defines individual test casesexpect(): Makes assertions about what your code should do
For example, a basic Jest test looks like this:
You don't need to memorize the syntax — Codex can generate properly structured Jest tests for you. Just describe what you want tested, and Codex will create the appropriate test structure.
Generating New Files with a Prompt
Once you've launched Codex inside your project directory, try a natural prompt like:
Codex will:
- Create the new file.
- Read the functions from
math_utils.ts. - Generate appropriate test cases using a testing framework like Jest.
- Show you a preview before applying the change.
You'll have the chance to review the proposed content and approve it — or edit the suggestion before it's applied.
Example Prompt
Imagine your file math_utils.ts contains this function:
Now you run Codex and type:
Codex might suggest creating a new file with this content:
You can then review and approve the file creation and content.
