Changes for jest 27

This commit is contained in:
Nathan Bierema 2021-08-27 11:46:06 -04:00
parent 7c40e60933
commit da53e2de14
10 changed files with 60 additions and 48 deletions

View File

@ -1,4 +1,5 @@
module.exports = { module.exports = {
setupFilesAfterEnv: ['<rootDir>/test/setup.js'], setupFilesAfterEnv: ['<rootDir>/test/setup.js'],
testPathIgnorePatterns: ['<rootDir>/examples'], testPathIgnorePatterns: ['<rootDir>/examples'],
testEnvironment: 'jsdom',
}; };

View File

@ -10,10 +10,12 @@ const actionsPattern =
/^@@INIT(.|\n)+@@reduxReactRouter\/routerDidChange(.|\n)+@@reduxReactRouter\/initRoutes(.|\n)+$/; /^@@INIT(.|\n)+@@reduxReactRouter\/routerDidChange(.|\n)+@@reduxReactRouter\/initRoutes(.|\n)+$/;
describe('Chrome extension', function () { describe('Chrome extension', function () {
let driver;
beforeAll(async () => { beforeAll(async () => {
chromedriver.start(); chromedriver.start();
await delay(2000); await delay(2000);
this.driver = new webdriver.Builder() driver = new webdriver.Builder()
.usingServer(`http://localhost:${port}`) .usingServer(`http://localhost:${port}`)
.withCapabilities({ .withCapabilities({
chromeOptions: { chromeOptions: {
@ -23,31 +25,32 @@ describe('Chrome extension', function () {
.forBrowser('chrome') .forBrowser('chrome')
.build(); .build();
}); });
afterAll(async () => { afterAll(async () => {
await this.driver.quit(); await driver.quit();
chromedriver.stop(); chromedriver.stop();
}); });
it("should open extension's window", async () => { it("should open extension's window", async () => {
await this.driver.get(`chrome-extension://${extensionId}/window.html#left`); await driver.get(`chrome-extension://${extensionId}/window.html#left`);
const url = await this.driver.getCurrentUrl(); const url = await driver.getCurrentUrl();
expect(url).toBe(`chrome-extension://${extensionId}/window.html#left`); expect(url).toBe(`chrome-extension://${extensionId}/window.html#left`);
}); });
it('should match document title', async () => { it('should match document title', async () => {
const title = await this.driver.getTitle(); const title = await driver.getTitle();
expect(title).toBe('Redux DevTools'); expect(title).toBe('Redux DevTools');
}); });
it("should contain inspector monitor's component", async () => { it("should contain inspector monitor's component", async () => {
const val = await this.driver const val = await driver
.findElement(webdriver.By.xpath('//div[contains(@class, "inspector-")]')) .findElement(webdriver.By.xpath('//div[contains(@class, "inspector-")]'))
.getText(); .getText();
expect(val).toBeDefined(); expect(val).toBeDefined();
}); });
it('should contain an empty actions list', async () => { it('should contain an empty actions list', async () => {
const val = await this.driver const val = await driver
.findElement( .findElement(
webdriver.By.xpath('//div[contains(@class, "actionListRows-")]') webdriver.By.xpath('//div[contains(@class, "actionListRows-")]')
) )
@ -56,24 +59,24 @@ describe('Chrome extension', function () {
}); });
Object.keys(switchMonitorTests).forEach((description) => Object.keys(switchMonitorTests).forEach((description) =>
it(description, switchMonitorTests[description].bind(this)) it(description, () => switchMonitorTests[description](driver))
); );
it('should get actions list', async () => { it('should get actions list', async () => {
const url = 'http://zalmoxisus.github.io/examples/router/'; const url = 'http://zalmoxisus.github.io/examples/router/';
await this.driver.executeScript(`window.open('${url}')`); await driver.executeScript(`window.open('${url}')`);
await delay(2000); await delay(2000);
const tabs = await this.driver.getAllWindowHandles(); const tabs = await driver.getAllWindowHandles();
await this.driver.switchTo().window(tabs[1]); await driver.switchTo().window(tabs[1]);
expect(await this.driver.getCurrentUrl()).toMatch(url); expect(await driver.getCurrentUrl()).toMatch(url);
await this.driver.manage().timeouts().pageLoadTimeout(5000); await driver.manage().timeouts().pageLoadTimeout(5000);
await this.driver.switchTo().window(tabs[0]); await driver.switchTo().window(tabs[0]);
const result = await this.driver.wait( const result = await driver.wait(
this.driver driver
.findElement( .findElement(
webdriver.By.xpath('//div[contains(@class, "actionListRows-")]') webdriver.By.xpath('//div[contains(@class, "actionListRows-")]')
) )

View File

@ -9,10 +9,12 @@ const devPanelPath =
'chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljd/window.html'; 'chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljd/window.html';
describe('DevTools panel for Electron', function () { describe('DevTools panel for Electron', function () {
let driver;
beforeAll(async () => { beforeAll(async () => {
chromedriver.start(); chromedriver.start();
await delay(1000); await delay(1000);
this.driver = new webdriver.Builder() driver = new webdriver.Builder()
.usingServer(`http://localhost:${port}`) .usingServer(`http://localhost:${port}`)
.withCapabilities({ .withCapabilities({
chromeOptions: { chromeOptions: {
@ -22,33 +24,33 @@ describe('DevTools panel for Electron', function () {
}) })
.forBrowser('electron') .forBrowser('electron')
.build(); .build();
await this.driver.manage().timeouts().setScriptTimeout(10000); await driver.manage().timeouts().setScriptTimeout(10000);
}); });
afterAll(async () => { afterAll(async () => {
await this.driver.quit(); await driver.quit();
chromedriver.stop(); chromedriver.stop();
}); });
it('should open Redux DevTools tab', async () => { it('should open Redux DevTools tab', async () => {
if (!(await this.driver.getCurrentUrl()).startsWith('devtools')) { if (!(await driver.getCurrentUrl()).startsWith('devtools')) {
const originalWindow = await this.driver.getWindowHandle(); const originalWindow = await driver.getWindowHandle();
const windows = await this.driver.getAllWindowHandles(); const windows = await driver.getAllWindowHandles();
for (const window of windows) { for (const window of windows) {
if (window === originalWindow) continue; if (window === originalWindow) continue;
await this.driver.switchTo().window(window); await driver.switchTo().window(window);
if ((await this.driver.getCurrentUrl()).startsWith('devtools')) { if ((await driver.getCurrentUrl()).startsWith('devtools')) {
break; break;
} }
} }
} }
expect(await this.driver.getCurrentUrl()).toMatch( expect(await driver.getCurrentUrl()).toMatch(
/devtools:\/\/devtools\/bundled\/devtools_app.html/ /devtools:\/\/devtools\/bundled\/devtools_app.html/
); );
await this.driver.manage().timeouts().pageLoadTimeout(5000); await driver.manage().timeouts().pageLoadTimeout(5000);
const id = await this.driver.executeAsyncScript(function (callback) { const id = await driver.executeAsyncScript(function (callback) {
let attempts = 5; let attempts = 5;
function showReduxPanel() { function showReduxPanel() {
if (attempts === 0) { if (attempts === 0) {
@ -71,17 +73,17 @@ describe('DevTools panel for Electron', function () {
}); });
expect(id).toBe('chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljdRedux'); expect(id).toBe('chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljdRedux');
const className = await this.driver const className = await driver
.findElement(webdriver.By.className(id)) .findElement(webdriver.By.className(id))
.getAttribute('class'); .getAttribute('class');
expect(className).not.toMatch(/hidden/); // not hidden expect(className).not.toMatch(/hidden/); // not hidden
}); });
it('should have Redux DevTools UI on current tab', async () => { it('should have Redux DevTools UI on current tab', async () => {
await this.driver await driver
.switchTo() .switchTo()
.frame( .frame(
this.driver.findElement( driver.findElement(
webdriver.By.xpath(`//iframe[@src='${devPanelPath}']`) webdriver.By.xpath(`//iframe[@src='${devPanelPath}']`)
) )
); );
@ -89,7 +91,7 @@ describe('DevTools panel for Electron', function () {
}); });
it('should contain INIT action', async () => { it('should contain INIT action', async () => {
const element = await this.driver.wait( const element = await driver.wait(
webdriver.until.elementLocated( webdriver.until.elementLocated(
webdriver.By.xpath('//div[contains(@class, "actionListRows-")]') webdriver.By.xpath('//div[contains(@class, "actionListRows-")]')
), ),
@ -101,23 +103,23 @@ describe('DevTools panel for Electron', function () {
}); });
it("should contain Inspector monitor's component", async () => { it("should contain Inspector monitor's component", async () => {
const val = await this.driver const val = await driver
.findElement(webdriver.By.xpath('//div[contains(@class, "inspector-")]')) .findElement(webdriver.By.xpath('//div[contains(@class, "inspector-")]'))
.getText(); .getText();
expect(val).toBeDefined(); expect(val).toBeDefined();
}); });
Object.keys(switchMonitorTests).forEach((description) => Object.keys(switchMonitorTests).forEach((description) =>
it(description, switchMonitorTests[description].bind(this)) it(description, () => switchMonitorTests[description](driver))
); );
/* it('should be no logs in console of main window', async () => { /* it('should be no logs in console of main window', async () => {
const handles = await this.driver.getAllWindowHandles(); const handles = await driver.getAllWindowHandles();
await this.driver.switchTo().window(handles[1]); // Change to main window await driver.switchTo().window(handles[1]); // Change to main window
expect(await this.driver.getTitle()).toBe('Electron Test'); expect(await driver.getTitle()).toBe('Electron Test');
const logs = await this.driver.manage().logs().get(webdriver.logging.Type.BROWSER); const logs = await driver.manage().logs().get(webdriver.logging.Type.BROWSER);
expect(logs).toEqual([]); expect(logs).toEqual([]);
}); });
*/ */

View File

@ -4,16 +4,16 @@ export const delay = (time) =>
new Promise((resolve) => setTimeout(resolve, time)); new Promise((resolve) => setTimeout(resolve, time));
export const switchMonitorTests = { export const switchMonitorTests = {
'should switch to Log Monitor': async function () { 'should switch to Log Monitor': async function (driver) {
await this.driver await driver
.findElement(webdriver.By.xpath('//button[text()="Inspector"]')) .findElement(webdriver.By.xpath('//button[text()="Inspector"]'))
.click(); .click();
await delay(500); // Wait till menu is fully opened await delay(500); // Wait till menu is fully opened
await this.driver await driver
.findElement(webdriver.By.xpath('//button[text()="Log monitor"]')) .findElement(webdriver.By.xpath('//button[text()="Log monitor"]'))
.click(); .click();
await delay(500); await delay(500);
await this.driver.findElement( await driver.findElement(
webdriver.By.xpath( webdriver.By.xpath(
'//div[div[button[text()="Reset"]] and .//div[button[text()="Revert"]]]' '//div[div[button[text()="Reset"]] and .//div[button[text()="Revert"]]]'
) )
@ -21,27 +21,27 @@ export const switchMonitorTests = {
await delay(500); await delay(500);
}, },
'should switch to Chart Monitor': async function () { 'should switch to Chart Monitor': async function (driver) {
await this.driver await driver
.findElement(webdriver.By.xpath('//button[text()="Log monitor"]')) .findElement(webdriver.By.xpath('//button[text()="Log monitor"]'))
.click(); .click();
await delay(500); // Wait till menu is fully opened await delay(500); // Wait till menu is fully opened
await this.driver await driver
.findElement(webdriver.By.xpath('//button[text()="Chart"]')) .findElement(webdriver.By.xpath('//button[text()="Chart"]'))
.click(); .click();
await delay(500); await delay(500);
await this.driver.findElement( await driver.findElement(
webdriver.By.xpath('//*[@class="nodeText" and text()="state"]') webdriver.By.xpath('//*[@class="nodeText" and text()="state"]')
); );
await delay(500); // Wait till menu is closed await delay(500); // Wait till menu is closed
}, },
'should switch back to Inspector Monitor': async function () { 'should switch back to Inspector Monitor': async function (driver) {
await this.driver await driver
.findElement(webdriver.By.xpath('//button[text()="Chart"]')) .findElement(webdriver.By.xpath('//button[text()="Chart"]'))
.click(); .click();
await delay(1000); // Wait till menu is fully opened await delay(1000); // Wait till menu is fully opened
await this.driver await driver
.findElement(webdriver.By.xpath('//button[text()="Inspector"]')) .findElement(webdriver.By.xpath('//button[text()="Inspector"]'))
.click(); .click();
await delay(1500); // Wait till menu is closed await delay(1500); // Wait till menu is closed

View File

@ -1,4 +1,5 @@
module.exports = { module.exports = {
preset: 'ts-jest', preset: 'ts-jest',
setupFilesAfterEnv: ['<rootDir>/tests/setup.ts'], setupFilesAfterEnv: ['<rootDir>/tests/setup.ts'],
testEnvironment: 'jsdom',
}; };

View File

@ -1,3 +1,4 @@
module.exports = { module.exports = {
preset: 'ts-jest', preset: 'ts-jest',
testEnvironment: 'jsdom',
}; };

View File

@ -1,3 +1,4 @@
module.exports = { module.exports = {
preset: 'ts-jest', preset: 'ts-jest',
testEnvironment: 'jsdom',
}; };

View File

@ -1,4 +1,5 @@
module.exports = { module.exports = {
preset: 'ts-jest', preset: 'ts-jest',
setupFilesAfterEnv: ['<rootDir>/test/setup.ts'], setupFilesAfterEnv: ['<rootDir>/test/setup.ts'],
testEnvironment: 'jsdom',
}; };

View File

@ -1,4 +1,5 @@
module.exports = { module.exports = {
preset: 'ts-jest', preset: 'ts-jest',
setupFilesAfterEnv: ['<rootDir>/test/setup.ts'], setupFilesAfterEnv: ['<rootDir>/test/setup.ts'],
testEnvironment: 'jsdom',
}; };

View File

@ -1,3 +1,4 @@
module.exports = { module.exports = {
preset: 'ts-jest', preset: 'ts-jest',
testEnvironment: 'jsdom',
}; };