fix: update e2e tests to use otplib v13 API and load .env

- Change tsconfig to use ESNext modules
- Add type: module to package.json
- Update auth.setup.ts to use generateSync instead of authenticator.generate
- Install and configure dotenv to load environment variables
- Add dotenv.config() to playwright.config.ts
This commit is contained in:
Graham McIntire 2026-03-06 15:53:10 -06:00
parent 659490c405
commit 99507eeaaf
No known key found for this signature in database
4 changed files with 8 additions and 5 deletions

View file

@ -1,6 +1,7 @@
{
"name": "towerops-e2e",
"version": "1.0.0",
"type": "module",
"description": "End-to-end tests for Towerops",
"scripts": {
"test": "playwright test",
@ -15,6 +16,7 @@
"devDependencies": {
"@playwright/test": "^1.48.0",
"@types/node": "^22.0.0",
"dotenv": "^17.3.1",
"otplib": "^13.0.0"
}
}

View file

@ -1,10 +1,11 @@
import { defineConfig, devices } from '@playwright/test';
import * as dotenv from 'dotenv';
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();
dotenv.config();
/**
* See https://playwright.dev/docs/test-configuration.

View file

@ -1,5 +1,5 @@
import { test as setup, expect } from '@playwright/test';
import { authenticator } from 'otplib';
import { generateSync } from 'otplib';
const authFile = 'tests/.auth/user.json';
@ -42,7 +42,7 @@ setup('authenticate', async ({ page }) => {
await page.waitForURL('**/users/log_in/totp');
// Generate TOTP code
const token = authenticator.generate(totpSecret);
const token = generateSync({ secret: totpSecret });
console.log(`Generated TOTP token: ${token}`);
// Fill in TOTP code

View file

@ -1,14 +1,14 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"module": "ESNext",
"lib": ["ES2020"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"moduleResolution": "bundler",
"types": ["node", "@playwright/test"]
},
"include": ["tests/**/*.ts"],