Skip to content

Commit

Permalink
test: update syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Jun 24, 2019
1 parent a5b98b5 commit 534dede
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 276 deletions.
29 changes: 19 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

184 changes: 86 additions & 98 deletions test/e2e/Client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,56 +37,50 @@ describe('reload', () => {
});

describe('on browser client', () => {
it('should hot reload without page refresh', (done) => {
runBrowser().then(({ page, browser }) => {
let refreshed = false;
page.waitForNavigation({ waitUntil: 'load' }).then(() => {
page
.evaluate(() => {
const body = document.body;
const bgColor = getComputedStyle(body)['background-color'];
return bgColor;
})
.then((color) => {
page.setRequestInterception(true).then(() => {
page.on('request', (req) => {
if (
req.isNavigationRequest() &&
req.frame() === page.mainFrame() &&
req.url() === `http://localhost:${port}/main`
) {
refreshed = true;
}
req.continue();
});
fs.writeFileSync(
cssFilePath,
'body { background-color: rgb(255, 0, 0); }'
);
page.waitFor(10000).then(() => {
page
.evaluate(() => {
const body = document.body;
const bgColor = getComputedStyle(body)[
'background-color'
];
return bgColor;
})
.then((color2) => {
browser.close().then(() => {
expect(color).toEqual('rgb(0, 0, 255)');
expect(color2).toEqual('rgb(255, 0, 0)');
expect(refreshed).toBeFalsy();
done();
});
});
});
});
});
});

page.goto(`http://localhost:${port}/main`);
it('should hot reload without page refresh', async () => {
let refreshed = false;
const { page, browser } = await runBrowser();

page.goto(`http://localhost:${port}/main`);

await page.waitForNavigation({ waitUntil: 'load' });

const color = await page.evaluate(() => {
const body = document.body;
const bgColor = getComputedStyle(body)['background-color'];
return bgColor;
});

await page.setRequestInterception(true);

page.on('request', (req) => {
if (
req.isNavigationRequest() &&
req.frame() === page.mainFrame() &&
req.url() === `http://localhost:${port}/main`
) {
refreshed = true;
}
req.continue();
});
fs.writeFileSync(
cssFilePath,
'body { background-color: rgb(255, 0, 0); }'
);

await page.waitFor(10000);

const color2 = await page.evaluate(() => {
const body = document.body;
const bgColor = getComputedStyle(body)['background-color'];
return bgColor;
});

await browser.close();

expect(color).toEqual('rgb(0, 0, 255)');
expect(color2).toEqual('rgb(255, 0, 0)');
expect(refreshed).toBeFalsy();
});
});
});
Expand Down Expand Up @@ -115,56 +109,50 @@ describe('reload', () => {
});

describe('on browser client', () => {
it('should reload with page refresh', (done) => {
runBrowser().then(({ page, browser }) => {
let refreshed = false;
page.waitForNavigation({ waitUntil: 'load' }).then(() => {
page
.evaluate(() => {
const body = document.body;
const bgColor = getComputedStyle(body)['background-color'];
return bgColor;
})
.then((color) => {
page.setRequestInterception(true).then(() => {
page.on('request', (req) => {
if (
req.isNavigationRequest() &&
req.frame() === page.mainFrame() &&
req.url() === `http://localhost:${port}/main`
) {
refreshed = true;
}
req.continue();
});
fs.writeFileSync(
cssFilePath,
'body { background-color: rgb(255, 0, 0); }'
);
page.waitFor(10000).then(() => {
page
.evaluate(() => {
const body = document.body;
const bgColor = getComputedStyle(body)[
'background-color'
];
return bgColor;
})
.then((color2) => {
browser.close().then(() => {
expect(color).toEqual('rgb(0, 0, 255)');
expect(color2).toEqual('rgb(255, 0, 0)');
expect(refreshed).toBeTruthy();
done();
});
});
});
});
});
});

page.goto(`http://localhost:${port}/main`);
it('should reload with page refresh', async () => {
let refreshed = false;
const { page, browser } = await runBrowser();

page.goto(`http://localhost:${port}/main`);

await page.waitForNavigation({ waitUntil: 'load' });

const color = await page.evaluate(() => {
const body = document.body;
const bgColor = getComputedStyle(body)['background-color'];
return bgColor;
});

await page.setRequestInterception(true);

page.on('request', (req) => {
if (
req.isNavigationRequest() &&
req.frame() === page.mainFrame() &&
req.url() === `http://localhost:${port}/main`
) {
refreshed = true;
}
req.continue();
});
fs.writeFileSync(
cssFilePath,
'body { background-color: rgb(255, 0, 0); }'
);

await page.waitFor(10000);

const color2 = await page.evaluate(() => {
const body = document.body;
const bgColor = getComputedStyle(body)['background-color'];
return bgColor;
});

await browser.close();

expect(color).toEqual('rgb(0, 0, 255)');
expect(color2).toEqual('rgb(255, 0, 0)');
expect(refreshed).toBeTruthy();
});
});
});
Expand Down

0 comments on commit 534dede

Please sign in to comment.