|

Day 27 of 100: ES Modules — import, export, and Barrel Files

Day 27 of 100 — 100 Days of Playwright with TypeScript Challenge. Phase: JavaScript Fundamentals. JavaScript (Days 1-33) → TypeScript (Days 34-63) → Playwright (Days 64-96) → AI Framework Capstone (Days 97-100).

🎭 Want to master this with real projects? Join the Playwright Automation Mastery course at The Testing Academy.


Modules split frameworks into files. Pages, utils, fixtures — each its own module. import/export is the glue.

Contents

Named and Default Exports

// utils/url.js
export const BASE = 'http://localhost:3000';
export function buildUrl(path) { return BASE + path; }
export default class UrlBuilder { /* ... */ }

// tests/example.spec.js
import UrlBuilder, { BASE, buildUrl } from '../utils/url.js';
import * as urlUtils from '../utils/url.js';   // namespace import

🚀 Level Up Your Playwright

From locators to CI pipelines — build a production-grade Playwright + TypeScript framework step by step.

Barrel Files — Framework Pattern

// pages/index.js — re-export everything
export { LoginPage } from './LoginPage.js';
export { DashboardPage } from './DashboardPage.js';
export { CheckoutPage } from './CheckoutPage.js';

// Now tests import from one place:
// import { LoginPage, CheckoutPage } from '../pages';

Rules

  • Prefer named exports — searchable, rename-safe, autocomplete-friendly
  • One class per file in pages/ — LoginPage.ts holds LoginPage only
  • Barrel index files keep test imports short
  • CommonJS require() still appears in old configs — recognize it, write ESM

Tomorrow (Day 28): npm and package.json — managing your test project.

🎓 Master Playwright End to End

Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.