79740245

Date: 2025-08-19 17:56:38
Score: 0.5
Natty:
Report link

Can be done, add module-alias:

npm install --save-dev module-alias

Register your aliases in package.json, using property _moduleAliases:

{
  "name": "playwright-alias",
  "version": "1.0.0",
  "description": "Show how to use aliases with Playwright ",
  "main": "index.js",
  "author": "Borewit",
  "type": "commonjs",
  "devDependencies": {
    "@playwright/test": "^1.54.2",
    "@types/node": "^24.3.0",
    "module-alias": "^2.2.3"
  },
  "_moduleAliases": {
    "@cy": "./cypress",
    "@": "./aliased"
  }
}

This file (based on the scenario in the question) we will alias aliased/utils/date-utils.js:

export function formatDate() {
    return 'aliased';
}

Testing the alias @ (tests/alias.spec.js):

import {expect, test} from "@playwright/test";
import { formatDate } from '@/utils/date-utils.js'; // Aliased import

test('alias', async ({ page }) => {
    expect(formatDate()).toBe('aliased');
});

Full source code: https://github.com/Borewit/playwright-alias

Reasons:
  • Contains signature (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): Can
Posted by: Borewit