Playwright + TS · Lesson 7 of 36

0/36 done

Module 7: Modules & Project Structure

7. ES Modules (import/export) & npm Configuration

10 minlesson

Your task

Write an export statement exporting a constant named API_TIMEOUT set to 10000.

Write it in the editor, then press Check answer (Ctrl + Enter).

ES Modules: Named vs Default Export

typescript
// Named export (constants.ts):
export const DEFAULT_TIMEOUT = 30000;
export const BASE_URL = "https://targetqa.com";

// Importing named exports:
import { DEFAULT_TIMEOUT, BASE_URL } from "./constants";

// Default export (LoginPage.ts):
export default class LoginPage { ... }

// Importing default export:
import LoginPage from "./LoginPage";

Environment Variables

In automation, URLs and credentials vary across environments (dev, staging, prod):

typescript
const targetEnv = process.env.TEST_ENV || "staging";

Key Takeaways & Walkthrough Summary

A well-structured automation project is easy to maintain and scale. In this lesson, we will cover ES modules with import and export, package.json configurations, tsconfig settings, and how to organize your folders cleanly. Let's explore how real-world test repositories are structured!

Part of the Playwright + TS course (Playwright with TypeScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Why are named exports generally preferred over default exports in automation frameworks?

Named exports enforce consistent naming across all test files and make refactoring and auto-imports reliable in IDEs.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

TypeScript
Skip