Skip to content

Commit

Permalink
chore: add E2E tests (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Fernandes authored Jan 25, 2024
1 parent e1ca942 commit ddad28d
Show file tree
Hide file tree
Showing 16 changed files with 15,718 additions and 2,026 deletions.
2 changes: 1 addition & 1 deletion .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ runs:
- name: Install dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
shell: bash
run: npm ci --no-audit
run: npm ci --no-audit && npx puppeteer browsers install chrome
env:
NODE_AUTH_TOKEN: ${{ inputs.node-auth-token }}
GITHUB_TOKEN: ${{ inputs.github-token }}
23 changes: 23 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]

# Environment variables available to all jobs and steps in this workflow
env:
CHROME_VERSION: 121.0.6167.85

jobs:
audit:
name: Audit dependencies
Expand Down Expand Up @@ -39,6 +43,25 @@ jobs:
- name: Type checking
run: npm run check-types

#test:
# name: E2E Tests
# runs-on: rows-fe-default
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
#
# - uses: ./.github/actions/setup-node
#
# - uses: ./.github/actions/install-dependencies
# with:
# node-auth-token: ${{ secrets.NODE_AUTH_TOKEN }}
# github-token: ${{ secrets.GITHUB_TOKEN }}
#
# - name: Run E2E tests
# run: node node_modules/puppeteer/install.mjs && npm run test:e2e

build:
name: Build
runs-on: rows-fe-default
Expand Down
4 changes: 4 additions & 0 deletions config/jest-preset.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const ts_preset = require('ts-jest/jest-preset');
const puppeteer_preset = require('jest-puppeteer/jest-preset');

module.exports = Object.assign(ts_preset, puppeteer_preset);
49 changes: 49 additions & 0 deletions e2e/scrappers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { readdirSync, promises as fs } from 'fs';
import { resolve } from 'path';

const extensionId = 'phpjngkjjocinjepokdimcomfmgkogbe';
const extensionUrl = `chrome-extension://${extensionId}/index.html`;

function listDirectories(path: string) {
const directories = readdirSync(path, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dir) => dir.name);

return directories;
}

describe('RowsX - scrappers tests', () => {
const tests = listDirectories(__dirname);

it.each(tests)('Scrapping - %s', async (domain) => {
const appPage = await browser.newPage();
const data = await fs.readFile(resolve(__dirname, `./${domain}/index.html`));

await appPage.setRequestInterception(true);

appPage.on('request', async (request) => {
if (request.url().endsWith('/')) {
request.respond({ status: 200, contentType: 'text/html', body: data });
} else {
request.continue();
}
});

const extensionPage = await browser.newPage();
await appPage.bringToFront();
await appPage.goto(`https://${domain}`, { waitUntil: 'domcontentloaded' });
await extensionPage.goto(extensionUrl, { waitUntil: 'domcontentloaded' });
await appPage.waitForTimeout(1000);
await extensionPage.bringToFront();
const button = await extensionPage.waitForSelector('.copy-btn');
await button.click();
await appPage.bringToFront();

const context = await browser.defaultBrowserContext();
await context.overridePermissions(`https://${domain}`, ['clipboard-read']);
const clipboard = await appPage.evaluate(() => navigator.clipboard.readText());
await appPage.close();
const result = await fs.readFile(resolve(__dirname, `./${domain}/result.tsv`));
expect(clipboard).toBe(result.toString().trimEnd());
});
});
3,884 changes: 3,884 additions & 0 deletions e2e/wikipedia.com-daft-punk/index.html

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions e2e/wikipedia.com-daft-punk/result.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Name Location Visitors in 2023 and 2022
Louvre Paris , France 8,900,000 (2023) [2 ]
Musée d'Orsay Paris , France 5.2 million (including Musée de l'Orangerie ) (2023) [3 ]
National Museum of Natural History Washington, D.C. , United States 4,400,000 (2023) [4 ]
National Museum of Korea Seoul , South Korea 4.18 million (2023) [5 ]
Musée National d'Histoire Naturelle Paris , France 3.8 million ((2023) [7 ]
Prado Museum Madrid, Spain 3,209,285 (2023) [9 ]
Guggenheim Museum Bilbao Bilbao , Spain 1,324,000 (2023) [10 ]
Vatican Museums Vatican City 5,080,866 (2022)
Natural History Museum London , United Kingdom 4,654,608 [11 ] (2022)
British Museum London , United Kingdom 4,097,253 [1 ] [11 ] (2022)
Tate Modern London , United Kingdom 3,883,160 [11 ] (2022)
Guangdong Museum Guangzhou , China 3,359,700 [12 ] (2022)
Mevlana Museum Konya , Turkey 3,352,505 [13 ] (2022)
National Gallery of Art Washington, D.C. , United States 3,256,433 (2022) [1 ]
Metropolitan Museum of Art New York City , United States 3,208,832 [a ] [1 ] (2022)
State Hermitage Museum Saint Petersburg , Russia 2,812,913 [1 ] (2022)
National Gallery London , United Kingdom 2,727,119 [11 ] <2022)
State Russian Museum Saint Petersburg , Russia 2,651,688 [1 ] (figures below are from 2022)
National Museum of Marine Science and Technology Keelung , Taiwan 2,582,444 [14 ]
Victoria and Albert Museum London , United Kingdom 2,370,261 [11 ]
London Science Museum London , United Kingdom 2,334,930 [11 ]
Chinese Aviation Museum Beijing , China 2,300,000 [15 ]
National Museum of Natural Science Taichung , Taiwan 2,299,808 [14 ]
Galleria degli Uffizi Florence , Italy 2,222,692 [1 ]
Museum of Modern Art New York City , United States 2,190,440 [1 ]
Topography of Terror Berlin , Germany 2,100,000 [16 ]
M+ Hong Kong , China 2,034,331 [1 ]
Opium War Museum  [zh ] Dongguan , China 2,025,800 [17 ]
Cité des Sciences et de l'Industrie Paris , France 1,992,823 [18 ]
National Museum of Scotland Edinburgh , United Kingdom 1,973,751 [11 ]
State Tretyakov Gallery Moscow , Russia 1,910,000 [1 ]
National Taiwan Science Education Center Taipei , Taiwan 1,878,504 [14 ]
National Science and Technology Museum Kaohsiung , Taiwan 1,875,372 [14 ]
National Museum of Modern and Contemporary Art Seoul , South Korea 1,806,641 [1 ]
Smithsonian Museum of American History Washington, D.C. , United States 2,100,000 (2023) [19 ]
Rijksmuseum Amsterdam , Netherlands 1,766,084 [1 ]
California Science Center Los Angeles , United States 1,694,000 [20 ]
National Museum of China Beijing , China 1,630,911 [21 ]
Royal Museums Greenwich London , United Kingdom 1,628,580 [11 ]
Nanjing Museum Nanjing , China 1,610,000 [22 ]
Zhejiang Museum of Natural History Hangzhou , China 1,581,263 [23 ]
National Gallery of Victoria Melbourne , Australia 1,580,303 [1 ]
Jianchuan Museum Cluster Chengdu , China 1,538,143 [24 ]
Houston Museum of Natural Science Houston , United States 1,520,000 [20 ]
Tokyo Metropolitan Art Museum Tokyo , Japan 1,509,970 [1 ]
Changzhou Museum Changzhou , China 1,508,229 [25 ]
Humboldt Forum Berlin , Germany 1,500,000 [1 ]
National Museum of Anthropology Mexico City , Mexico 1,494,587 [26 ]
National Museum of History Mexico City , Mexico 1,486,379 [26 ]
National Air and Space Museum [b ] Washington, D.C. , United States 1,486,000 [27 ]
Kaohsiung Museum of Fine Arts Kaohsiung , Taiwan 1,461,406 [14 ]
Acropolis Museum Athens , Greece 1,451,727 [1 ]
China Science and Technology Museum Beijing , China 1,431,189 [28 ]
Galleria dell'Accademia Florence , Italy 1,428,369 [1 ]
Suzhou Museum Suzhou , China 1,417,412 [29 ]
Chengdu Museum Chengdu , China 1,404,735 [30 ]
Shanghai Science and Technology Museum Shanghai , China 1,403,179 [31 ]
The National Art Center, Tokyo Tokyo , Japan 1,400,096 [1 ]
Louis Vuitton Foundation Paris , France 1,398,525 [1 ]
Tokyo National Museum Tokyo , Japan 1,372,132 [1 ]
National Museum in Kraków Kraków , Poland 1,365,425 [1 ]
Centro Cultural Banco do Brasil São Paulo , Brazil 1,364,208 [1 ]
Van Gogh Museum Amsterdam , Netherlands 1,364,023 [1 ]
National Museum of Nature and Science Tokyo , Japan 1,350,000 [20 ]
Kunsthistorisches Museum Vienna , Austria 1,345,617 [1 ]
Tianjin Natural History Museum Tianjin , China 1,320,752 [32 ]
Palacio de Cristal del Retiro Madrid , Spain 1,318,823 [c ] [1 ]
Scottish National Gallery Edinburgh , United Kingdom 1,277,230 [1 ]
National Gallery Singapore Singapore 1,262,189 [1 ]
Museo Reina Sofía Madrid , Spain 1,253,183 [d ] [1 ]
Loading

0 comments on commit ddad28d

Please sign in to comment.