Skip to content

Commit

Permalink
test(e2e): add helpers and browser specific naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ifiokjr committed Jun 20, 2019
1 parent ed0dd1d commit 4659cea
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 9 deletions.
3 changes: 3 additions & 0 deletions e2e/__image_snapshots__/firefox-twitter-editor-dom-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions e2e/__image_snapshots__/firefox-twitter-editor-ssr-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions e2e/__image_snapshots__/firefox-wysiwyg-editor-dom-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions e2e/__image_snapshots__/firefox-wysiwyg-editor-ssr-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions e2e/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { getBrowserName } from '@test-fixtures/test-urls';
import pSeries from 'p-series';

/**
* Clear the editor via triple click and delete
*/
Expand Down Expand Up @@ -25,3 +28,14 @@ export const textContent = async (selector: string) => page.$eval(selector, e =>
* Retrieve the outerHTML from the editor
*/
export const outerHtml = async (selector: string) => page.$eval(selector, e => e.outerHTML);

/**
* Repeat the keyPress N number of times.
*/
export const repeatKeyPress = (key: string, times: number) =>
pSeries(Array(times).fill(() => page.keyboard.press(key, { delay: 15 })));

/**
* Skips the test on Firefox.
*/
export const skipTestOnFirefox = getBrowserName() === 'firefox' ? test.skip : test;
14 changes: 8 additions & 6 deletions e2e/twitter.puppeteer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Deployment, URLDescriptor } from '@test-fixtures/test-urls';
import { innerHtml, outerHtml, sel, textContent } from './helpers';
import { Deployment, prefixBrowserName, URLDescriptor } from '@test-fixtures/test-urls';
import { innerHtml, outerHtml, sel, skipTestOnFirefox, textContent } from './helpers';

const editorSelector = '.remirror-editor';

describe('Twitter Editor Snapshots', () => {
const url = URLDescriptor.twitter[Deployment.Next][1];
const ssrIdentifier = 'twitter-editor-ssr';
const domIdentifier = 'twitter-editor-dom';
const ssrIdentifier = prefixBrowserName('twitter-editor-ssr');
const domIdentifier = prefixBrowserName('twitter-editor-dom');

beforeEach(async () => {
await jestPuppeteer.resetPage();
Expand Down Expand Up @@ -86,11 +86,12 @@ describe.each(URLDescriptor.twitter)('%s: Twitter Showcase', (_, path) => {
);
});

it('can handle more complex interactions', async () => {
// TODO The 'Home' key press doesn't work on Firefox
skipTestOnFirefox('can handle more complex interactions', async () => {
await page.type(editorSelector, 'this is the first url.com');
await page.keyboard.press('Enter');
await page.type(editorSelector, 'this.com is test.com');
await page.keyboard.press('Home');
await page.keyboard.press('Home'); // ? This does nothing on Firefox
await page.keyboard.type('split.com ');
await expect(innerHtml(editorSelector)).resolves.toIncludeMultiple([
'<a href="http://split.com" role="presentation">split.com</a>',
Expand All @@ -104,6 +105,7 @@ describe.each(URLDescriptor.twitter)('%s: Twitter Showcase', (_, path) => {
await page.keyboard.type('..no .co more url please');
await expect(innerHtml(editorSelector)).resolves.not.toInclude('url.com');
});

it('should handle the enter key', async () => {
await page.type(editorSelector, 'this is the first url.com');
await page.keyboard.press('ArrowLeft');
Expand Down
6 changes: 3 additions & 3 deletions e2e/wysiwyg.puppeteer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Deployment, URLDescriptor } from '@test-fixtures/test-urls';
import { Deployment, prefixBrowserName, URLDescriptor } from '@test-fixtures/test-urls';
import { outerHtml } from './helpers';

const editorSelector = '.remirror-editor';

describe('Wysiwyg Editor Snapshots', () => {
const url = URLDescriptor.wysiwyg[Deployment.Next][1];
const ssrIdentifier = 'wysiwyg-editor-ssr';
const domIdentifier = 'wysiwyg-editor-dom';
const ssrIdentifier = prefixBrowserName('wysiwyg-editor-ssr');
const domIdentifier = prefixBrowserName('wysiwyg-editor-dom');

beforeEach(async () => {
await jestPuppeteer.resetPage();
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
"lodash": "4.17.11",
"mz": "2.7.0",
"npm-run-all": "4.1.5",
"p-series": "^2.1.0",
"prettier": "1.18.2",
"prettier-package-json": "2.1.0",
"pretty-format": "^24.8.0",
Expand Down
18 changes: 18 additions & 0 deletions support/fixtures/test-urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,29 @@ if (STORYBOOK_ONLY) {
});
}

export type BrowserName = 'firefox' | 'chromium';

/**
* Retrieve the browser name from the environment
*/
export const getBrowserName = (): BrowserName => process.env.PUPPETEER_BROWSER || 'chromium';

/**
* Prefix the browser name to the passed in string
*/
export const prefixBrowserName = (value: string) => `${getBrowserName()}-${value}`;

/**
* Declare the globals used throughout tests
*/
declare global {
const __DEV__: boolean;
const __TEST__: boolean;
const __E2E__: boolean;

namespace NodeJS {
interface ProcessEnv {
PUPPETEER_BROWSER?: BrowserName;
}
}
}
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2397,6 +2397,11 @@
resolved "https://registry.yarnpkg.com/@sheerun/mutationobserver-shim/-/mutationobserver-shim-0.3.2.tgz#8013f2af54a2b7d735f71560ff360d3a8176a87b"
integrity sha512-vTCdPp/T/Q3oSqwHmZ5Kpa9oI7iLtGl3RQaA/NyLHikvcrPxACkkKVr/XzkSPJWXHRhKGzVvb0urJsbMlRxi1Q==

"@sindresorhus/is@^0.15.0":
version "0.15.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.15.0.tgz#96915baa05e6a6a1d137badf4984d3fc05820bb6"
integrity sha512-lu8BpxjAtRCAo5ifytTpCPCj99LF7o/2Myn+NXyNCBqvPYn7Pjd76AMmUB5l7XF1U6t0hcWrlEM5ESufW7wAeA==

"@sindresorhus/slugify@^0.9.1":
version "0.9.1"
resolved "https://registry.yarnpkg.com/@sindresorhus/slugify/-/slugify-0.9.1.tgz#892ad24d70b442c0a14fe519cb4019d59bc5069f"
Expand Down Expand Up @@ -14853,6 +14858,14 @@ p-retry@^3.0.1:
dependencies:
retry "^0.12.0"

p-series@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/p-series/-/p-series-2.1.0.tgz#7035b3a81e2644d4ba407c1ebbc21776e353fa29"
integrity sha512-vEAnkG1ikRT1kPBrKwpj7AFYQkd1hjt/oHeppxtpoPxy5gEt+OWiHZJN3tMqvFa+UJfVwO3lwHoMUpMYBLKnaQ==
dependencies:
"@sindresorhus/is" "^0.15.0"
p-reduce "^2.1.0"

p-try@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3"
Expand Down

0 comments on commit 4659cea

Please sign in to comment.