Skip to content
Permalink
Browse files

Chore: Fix test case to simulate parsing HTML

Needed to ensure an `originalDocument` is set to avoid treating
test files as fragments.
  • Loading branch information...
antross authored and molant committed Oct 21, 2019
1 parent 4ec8e55 commit 1d9e43dd453f7971cb801cfd4f73100621dcb375
Showing with 31 additions and 3 deletions.
  1. +31 −3 packages/extension-browser/tests/end-to-end.ts
@@ -99,7 +99,8 @@ const findWebhintDevtoolsPanel = async (browser: Browser): Promise<Frame> => {
};

test('It runs end-to-end in a page', async (t) => {
const server = await Server.create({ configuration: await readFixture('missing-lang.html') });
const content = await readFixture('missing-lang.html');
const server = await Server.create({ configuration: content });

const url = `http://localhost:${server.port}/`;

@@ -112,7 +113,7 @@ test('It runs end-to-end in a page', async (t) => {
console.log('Page Error: ', e);
});

const resultsPromise = page.evaluate(() => {
const resultsPromise = page.evaluate((content: string, url: string) => {
return new Promise<Results>((resolve) => {
const listeners: (((events: Events) => void))[] = [];

@@ -152,14 +153,41 @@ test('It runs end-to-end in a page', async (t) => {
if (event.requestConfig) {
onMessage({ config: {} });
}
if (event.ready) {
setTimeout(() => {
onMessage({
fetchEnd: {
element: null, // Set by `content-script/connector`.
request: {
headers: {},
url
},
resource: url,
response: {
body: {
content,
rawContent: null as any,
rawResponse: null as any
},
charset: '', // Set by `content-script/connector`.
headers: { 'content-type': 'text/html; charset=utf-8' },
hops: [],
mediaType: '', // Set by `content-script/connector`.
statusCode: 200,
url
}
}
});
}, 0);
}
if (event.results) {
resolve(event.results);
}
}
}
} as any;
});
});
}, content, url);

await page.addScriptTag({ path: `${__dirname}/../bundle/content-script/webhint.js` });

0 comments on commit 1d9e43d

Please sign in to comment.
You can’t perform that action at this time.