Skip to content

Commit

Permalink
Fix lighthouse tests
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Nov 19, 2024
1 parent 27ced8b commit 51cd9f0
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lighthouse/lighthouse-auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs';
import fs from 'fs/promises';
import { checkForInitialLoad, main } from './lighthouse-auth.mjs';

describe('Lighthouse Pre-Login Steps', () => {
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('Lighthouse Pre-Login Steps', () => {
beforeEach(() => {
jest.resetModules();
jest.mock('fs', () => ({ appendFile: jest.fn() }));
jest.spyOn(fs, 'appendFile').mockImplementation(() => {});
jest.spyOn(fs, 'appendFile').mockImplementation(async () => {});
});

describe('main', () => {
Expand Down Expand Up @@ -97,7 +97,11 @@ describe('Lighthouse Pre-Login Steps', () => {
'http://localhost:3000/accountLists',
'http://localhost:3000',
);
expect(initialPage.$).toHaveBeenCalledTimes(2);
expect(initialPage.$).toHaveBeenCalledTimes(1);
expect(initialPage.waitForSelector).toHaveBeenCalledWith(
'#sign-in-button',
expect.anything(),
);
});

it('should not break if the sign in button is not found', async () => {

Check warning on line 107 in lighthouse/lighthouse-auth.test.ts

View workflow job for this annotation

GitHub Actions / eslint

Test has no assertions
Expand Down Expand Up @@ -132,21 +136,19 @@ describe('Lighthouse Pre-Login Steps', () => {
it('should not break if the sign in button is not found the second time', async () => {
successfulTestMock();

initialPage.$.mockImplementationOnce((selector) => {
initialPage.$.mockImplementation((selector) => {
if (selector === '#sign-in-button') {
return Promise.resolve({
click: jest.fn(),
});
}
return Promise.resolve({});
}).mockImplementationOnce((selector) => {
if (selector === '#sign-in-button') {
return Promise.reject('could not find element');
}
return Promise.resolve({});
});

initialPage.waitForSelector.mockImplementation((selector) => {
if (selector === '#sign-in-button') {
return Promise.reject('could not find element');
}
if (selector === '#okta-signin-username') {
return Promise.reject('could not find element');
}
Expand Down

0 comments on commit 51cd9f0

Please sign in to comment.