Skip to content

Commit

Permalink
chore: fix test for headless=new
Browse files Browse the repository at this point in the history
  • Loading branch information
blakebyrnes committed Jun 13, 2024
1 parent 4f1f836 commit 87d5267
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
include:
- node-version: 18.x
os: ubuntu-latest
browser: chrome-97-0
browser: chrome-114-0

runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
include:
- node-version: 18.x
os: ubuntu-latest
browser: chrome-97-0
browser: chrome-114-0

runs-on: ${{ matrix.os }}

Expand Down
2 changes: 2 additions & 0 deletions core/lib/FrameEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ b) Use the UserProfile feature to set cookies for 1 or more domains before they'
domain: cookie.domain,
},
]);
await new Promise(setImmediate);
return true;
}
}
Expand All @@ -411,6 +412,7 @@ b) Use the UserProfile feature to set cookies for 1 or more domains before they'
url: this.frame.url,
},
]);
await new Promise(setImmediate);
return true;
}

Expand Down
4 changes: 3 additions & 1 deletion core/lib/Tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ export default class Tab
mitmSession.interceptorHandlers.unshift({
urls: [origin],
handlerFn(url, type, request, response) {
response.end(`<html lang="en"><body>Empty</body></html>`);
response.end(
`<html lang="en"><head><link rel="icon" href="data:,"></head><body>Empty</body></html>`,
);
return true;
},
});
Expand Down
2 changes: 1 addition & 1 deletion core/lib/UserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ for (const [key,value] of ${JSON.stringify(localStorage)}) {
responseCode: 200,
requestId,
body: Buffer.from(
`<html><body class="${readyClass}">
`<html><head><link rel="icon" href="data:,"></head><body class="${readyClass}">
<h5>Loading UserProfile for ${url.origin}</h5>
<script>
${script}
Expand Down
4 changes: 3 additions & 1 deletion core/test/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ describe('Core events tests', () => {
await tab.waitForLoad(LocationStatus.PaintingStable);

// TODO: this should really be 2; it's emitting base document as an resource
expect(onEventFn.mock.calls).toHaveLength(4);
expect(
onEventFn.mock.calls.map(x => x[0].data[0].url).filter(x => !x.includes('favicon.ico')),
).toHaveLength(4);
}, 10e3);

it('removes event listeners', async () => {
Expand Down
8 changes: 6 additions & 2 deletions core/test/resources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ test('records a single resource for failed mitm requests', async () => {
waitForEmptyKeyCheck.resolve();
await didEmit.promise;
await new Promise(setImmediate);
expect(session.resources.getForTab(meta.tabId)).toHaveLength(1);
expect([...session.resources.browserRequestIdToResources.keys()]).toHaveLength(1);

const resource = session.resources
.getForTab(meta.tabId)
.find(x => x.url === `http://localhost:2344/not-there`);
expect(resource).toBeTruthy();
expect([...session.resources.browserRequestIdToResources.keys()].length).toBeGreaterThanOrEqual(1);
await session.close();
});

Expand Down
10 changes: 5 additions & 5 deletions core/test/user-profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ document.querySelector('#local').innerHTML = localStorage.getItem('test');
const session = tab.session;
Helpers.needsClosing.push(session);
session.mitmRequestSession.interceptorHandlers.push({
urls: ['http://dataliberationfoundation.org/*'],
urls: ['https://dataliberationfoundation.org/*'],
types: [],
handlerFn(url: URL, type: IResourceType, request, response) {
response.end(`<html><body><p>frame body</p>
Expand All @@ -452,10 +452,10 @@ localStorage.setItem('cross', '1');
},
});

await tab.goto(`http://dataliberationfoundation.org/`);
await tab.goto(`https://dataliberationfoundation.org/`);
await tab.waitForLoad('AllContentLoaded');
profile = await tab.session.exportUserProfile();
expect(profile.storage['http://dataliberationfoundation.org']?.localStorage).toHaveLength(1);
expect(profile.storage['https://dataliberationfoundation.org']?.localStorage).toHaveLength(1);
await session.close();
}
{
Expand All @@ -467,7 +467,7 @@ localStorage.setItem('cross', '1');
Helpers.needsClosing.push(session);

session.mitmRequestSession.interceptorHandlers.push({
urls: ['http://dataliberationfoundation.org/*'],
urls: ['https://dataliberationfoundation.org/*'],
types: [],
handlerFn(url: URL, type: IResourceType, request, response) {
response.end(`<html>
Expand All @@ -481,7 +481,7 @@ localStorage.setItem('cross', '1');
return true;
},
});
await tab.goto(`http://dataliberationfoundation.org/`);
await tab.goto(`https://dataliberationfoundation.org/`);
await tab.waitForLoad('DomContentLoaded');
const localContent = await tab.execJsPath([
'document',
Expand Down
2 changes: 2 additions & 0 deletions end-to-end/test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ describe('basic Full Client tests', () => {
'CookieSub=sub; domain=.ulixee.org',
]);
response.end(`<html lang='en'>
<head><link rel="icon" href="data:,"></head>
<body>
<h1>Page Title</h1>
</body>
Expand All @@ -147,6 +148,7 @@ describe('basic Full Client tests', () => {
});

await hero.goto(`https://ulixee.org`);
await hero.activeTab.waitForLoad('DomContentLoaded');
const cookieStorage = hero.activeTab.cookieStorage;
{
expect(await cookieStorage.length).toBe(2);
Expand Down

0 comments on commit 87d5267

Please sign in to comment.