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 together
  • test() or it(): Defines individual test cases
  • expect(): Makes assertions about what your code should do

For example, a basic Jest test looks like this:

TypeScript
describe('math functions', () => {
  test('adds two numbers', () => {
    expect(add(2, 3)).toBe(5);
  });
});

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:

text
Create a new file called math_utils.test.ts with unit tests for math_utils.ts

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:

TypeScript
export function square(x: number): number {
    return x * x;
}

Now you run Codex and type:

text
Write a test file called math_utils.test.ts to test the square function.

Codex might suggest creating a new file with this content:

TypeScript
import { square } from './math_utils';

describe('square', () => {
    test('squares positive numbers', () => {
        expect(square(2)).toBe(4);
    });

    test('squares negative numbers', () => {
        expect(square(-3)).toBe(9);
    });

    test('squares zero', () => {
        expect(square(0)).toBe(0);
    });
});

You can then review and approve the file creation and content.

Use Cases

This technique is useful for:

  • Generating boilerplate code.
  • Writing tests or config files.
  • Creating documentation stubs.
  • Starting new scripts or tools.

You'll save time by letting Codex scaffold the structure while you focus on the logic.

Summary

In this unit, you learned how to use Codex to create new files and populate them with relevant code using natural language. You also learned the basics of Jest testing framework structure, which will help you understand the test files Codex generates. This helps automate setup tasks and streamlines the start of new files or components in your projects.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal