auth.setup.ts 1013 B

1234567891011121314151617181920212223
  1. import { test as setup, expect } from '@playwright/test';
  2. import { loadFixture, probeReadiness, readinessMessage, STORAGE_STATE_PATH } from './helpers';
  3. import { ensureLoggedIn } from './flow';
  4. declare const require: (id: string) => any;
  5. setup('authenticate once for the negative suite', async ({ page }) => {
  6. const readiness = await probeReadiness();
  7. expect(readiness.ok, readinessMessage(readiness)).toBe(true);
  8. let fixture;
  9. try {
  10. fixture = loadFixture();
  11. } catch (err) {
  12. setup.skip(true, `run provision first: cargo run -p provision -- bootstrap --password-file <path> (${(err as Error).message})`);
  13. throw new Error('unreachable');
  14. }
  15. const { authenticator } = require('otplib');
  16. await ensureLoggedIn(page, fixture, (secret: string) => authenticator.generate(secret));
  17. const fs = require('node:fs');
  18. const path = require('node:path');
  19. fs.mkdirSync(path.dirname(STORAGE_STATE_PATH), { recursive: true });
  20. await page.context().storageState({ path: STORAGE_STATE_PATH });
  21. });