From f1971edf6d5875b23589d1224fd547afc98c3ae1 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Fri, 8 Nov 2019 06:23:22 +0100 Subject: [PATCH] build: fix e2e (#246) * fix: e2e testing * fix: e2e testing * fix: e2e testing * fix: e2e testing * fix: e2e testing * fix: e2e testing --- package.json | 2 +- src/components/Help/Help.tsx | 7 +++-- src/components/Package/Package.tsx | 2 +- test/e2e/config/config-protected-e2e.yaml | 2 +- test/e2e/config/config-scoped-e2e.yaml | 2 +- test/e2e/e2e.spec.js | 38 +++++++++++++++-------- test/e2e/setup.js | 7 ++++- yarn.lock | 30 +++++++++++------- 8 files changed, 59 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 7279ca1..bf5cfaf 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "ora": "4.0.2", "prettier": "1.18.2", "prop-types": "15.7.2", - "puppeteer": "1.8.0", + "puppeteer": "2.0.0", "react": "16.11.0", "react-autosuggest": "9.4.3", "react-dom": "16.11.0", diff --git a/src/components/Help/Help.tsx b/src/components/Help/Help.tsx index 226c15e..0923dfa 100644 --- a/src/components/Help/Help.tsx +++ b/src/components/Help/Help.tsx @@ -10,6 +10,9 @@ import Text from '../../muiComponents/Text'; import { CardStyled as Card, HelpTitle } from './styles'; +export const HELP_TITLE = 'No Package Published Yet.'; +export const COMPONENT_HELP_ID = 'help-card__title'; + function renderHeadingClipboardSegments(title: string, text: string): React.ReactNode { return ( @@ -25,8 +28,8 @@ const Help: React.FC = () => { return ( - - {'No Package Published Yet.'} + + {HELP_TITLE} {'To publish your first package just:'} diff --git a/src/components/Package/Package.tsx b/src/components/Package/Package.tsx index 43cb21d..b0b4fd3 100644 --- a/src/components/Package/Package.tsx +++ b/src/components/Package/Package.tsx @@ -156,7 +156,7 @@ const Package: React.FC = ({ {/* eslint-disable-next-line react/jsx-max-depth */} - {packageName} + {packageName} diff --git a/test/e2e/config/config-protected-e2e.yaml b/test/e2e/config/config-protected-e2e.yaml index 6d6a4c7..3bdb5b3 100644 --- a/test/e2e/config/config-protected-e2e.yaml +++ b/test/e2e/config/config-protected-e2e.yaml @@ -14,7 +14,7 @@ auth: password: test logs: - - { type: stdout, format: pretty, level: warn } + - { type: stdout, format: pretty, level: info } packages: 'protected-*': diff --git a/test/e2e/config/config-scoped-e2e.yaml b/test/e2e/config/config-scoped-e2e.yaml index fd0f891..702d4c3 100644 --- a/test/e2e/config/config-scoped-e2e.yaml +++ b/test/e2e/config/config-scoped-e2e.yaml @@ -14,7 +14,7 @@ auth: password: test logs: - - { type: stdout, format: pretty, level: warn } + - { type: stdout, format: pretty, level: info } packages: '@*/*': diff --git a/test/e2e/e2e.spec.js b/test/e2e/e2e.spec.js index 739ee36..964aeff 100644 --- a/test/e2e/e2e.spec.js +++ b/test/e2e/e2e.spec.js @@ -1,3 +1,5 @@ +import { HELP_TITLE } from '../../src/components/Help/Help'; + const scopedPackageMetadata = require('./partials/pkg-scoped'); const protectedPackageMetadata = require('./partials/pkg-protected'); @@ -12,16 +14,16 @@ describe('/ (Verdaccio Page)', () => { await button.click(options); }; - const evaluateSignIn = async function() { - const text = await page.evaluate( - () => document.querySelector('button[data-testid="header--button-login"]').textContent - ); + const evaluateSignIn = async function(matchText = 'Login') { + const text = await page.evaluate(() => { + return document.querySelector('button[data-testid="header--button-login"]').textContent; + }); - expect(text).toMatch('Login'); + expect(text).toMatch(matchText); }; const getPackages = async function() { - return await page.$$('.package-list-items .package-link a'); + return await page.$$('.package-title'); }; const logIn = async function() { @@ -54,31 +56,34 @@ describe('/ (Verdaccio Page)', () => { await page.close(); }); - test('should load without error', async () => { - const text = await page.evaluate(() => document.body.textContent); + test('should display title', async () => { + const text = await page.title(); + await page.waitFor(1000); - // FIXME: perhaps it is not the best approach - expect(text).toContain('Powered by'); + expect(text).toContain('verdaccio-server-e2e'); }); test('should match title with no packages published', async () => { const text = await page.evaluate(() => document.querySelector('#help-card__title').textContent); - expect(text).toMatch('No Package Published Yet'); + expect(text).toMatch(HELP_TITLE); }); + // test('should match title with first step', async () => { const text = await page.evaluate(() => document.querySelector('#help-card').textContent); expect(text).toContain('npm adduser --registry http://0.0.0.0:55558'); }); + // test('should match title with second step', async () => { const text = await page.evaluate(() => document.querySelector('#help-card').textContent); expect(text).toContain('npm publish --registry http://0.0.0.0:55558'); }); - + // test('should match button Login to sign in', async () => { await evaluateSignIn(); }); + // test('should click on sign in button', async () => { const signInButton = await page.$('button[data-testid="header--button-login"]'); @@ -88,6 +93,7 @@ describe('/ (Verdaccio Page)', () => { expect(signInDialog).not.toBeNull(); }); + // test('should log in an user', async () => { // we open the dialog @@ -96,6 +102,7 @@ describe('/ (Verdaccio Page)', () => { const buttonLogout = await page.$('#header--button-logout'); expect(buttonLogout).toBeDefined(); }); + // test('should logout an user', async () => { // we assume the user is logged already @@ -105,6 +112,7 @@ describe('/ (Verdaccio Page)', () => { await page.waitFor(1000); await evaluateSignIn(); }); + // test('should check registry info dialog', async () => { const registryInfoButton = await page.$('#header--button-registryInfo'); @@ -117,6 +125,7 @@ describe('/ (Verdaccio Page)', () => { const closeButton = await page.$('#registryInfo--dialog-close'); closeButton.click(); }); + // test('should publish a package', async () => { await global.__SERVER__.putPackage(scopedPackageMetadata.name, scopedPackageMetadata); @@ -126,13 +135,16 @@ describe('/ (Verdaccio Page)', () => { const packagesList = await getPackages(); expect(packagesList).toHaveLength(1); }); + // test('should navigate to the package detail', async () => { const packagesList = await getPackages(); + // console.log("-->packagesList:", packagesList); const firstPackage = packagesList[0]; await firstPackage.click({ clickCount: 1, delay: 200 }); await page.waitFor(1000); const readmeText = await page.evaluate(() => document.querySelector('.markdown-body').textContent); + expect(readmeText).toMatch('test'); }); @@ -140,7 +152,7 @@ describe('/ (Verdaccio Page)', () => { const versionList = await page.$$('.sidebar-info .detail-info'); expect(versionList).toHaveLength(1); }); - + // test('should display dependencies tab', async () => { const dependenciesTab = await page.$$('#dependencies-tab'); expect(dependenciesTab).toHaveLength(1); diff --git a/test/e2e/setup.js b/test/e2e/setup.js index 4554458..b411ef2 100644 --- a/test/e2e/setup.js +++ b/test/e2e/setup.js @@ -10,7 +10,12 @@ const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup'); module.exports = async function() { console.log(green('Setup Puppeteer')); - const browser = await puppeteer.launch({ headless: true, /* slowMo: 300 */ args: ['--no-sandbox'] }); + const browser = await puppeteer.launch({ + headless: true, + // slowMo: 600, + // devtools: true, + args: ['--no-sandbox'], + }); global.__BROWSER__ = browser; mkdirp.sync(DIR); fs.writeFileSync(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint()); diff --git a/yarn.lock b/yarn.lock index 5a00d5e..af85f23 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6852,6 +6852,14 @@ https-proxy-agent@^2.2.1: agent-base "^4.3.0" debug "^3.1.0" +https-proxy-agent@^3.0.0: + version "3.0.1" + resolved "https://registry.verdaccio.org/https-proxy-agent/-/https-proxy-agent-3.0.1.tgz#b8c286433e87602311b01c8ea34413d856a4af81" + integrity sha512-+ML2Rbh6DAuee7d07tYGEKOEi2voWPUGan+ExdPbPW6Z3svq+JCqr0v8WmKPOkz1vOVykPCBSuobe7G8GJUtVg== + dependencies: + agent-base "^4.3.0" + debug "^3.1.0" + humanize@0.0.9: version "0.0.9" resolved "https://registry.verdaccio.org/humanize/-/humanize-0.0.9.tgz#1994ffaecdfe9c441ed2bdac7452b7bb4c9e41a4" @@ -10951,7 +10959,7 @@ process@^0.11.10: resolved "https://registry.verdaccio.org/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182" integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI= -progress@^2.0.0: +progress@^2.0.0, progress@^2.0.1: version "2.0.3" resolved "https://registry.verdaccio.org/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== @@ -11090,19 +11098,19 @@ punycode@^2.1.0, punycode@^2.1.1: resolved "https://registry.verdaccio.org/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== -puppeteer@1.8.0: - version "1.8.0" - resolved "https://registry.verdaccio.org/puppeteer/-/puppeteer-1.8.0.tgz#9e8bbd2f5448cc19cac220efc0512837104877ad" - integrity sha512-wJ7Fxs03l4dy/ZXQACUKBBobIuJaS4NHq44q7/QinpAXFMwJMJFEIPjzoksVzUhZxQe+RXnjXH69mg13yMh0BA== +puppeteer@2.0.0: + version "2.0.0" + resolved "https://registry.verdaccio.org/puppeteer/-/puppeteer-2.0.0.tgz#0612992e29ec418e0a62c8bebe61af1a64d7ec01" + integrity sha512-t3MmTWzQxPRP71teU6l0jX47PHXlc4Z52sQv4LJQSZLq1ttkKS2yGM3gaI57uQwZkNaoGd0+HPPMELZkcyhlqA== dependencies: - debug "^3.1.0" + debug "^4.1.0" extract-zip "^1.6.6" - https-proxy-agent "^2.2.1" + https-proxy-agent "^3.0.0" mime "^2.0.3" - progress "^2.0.0" + progress "^2.0.1" proxy-from-env "^1.0.0" rimraf "^2.6.1" - ws "^5.1.1" + ws "^6.1.0" q@^1.1.2, q@^1.5.1: version "1.5.1" @@ -14209,14 +14217,14 @@ write@1.0.3: dependencies: mkdirp "^0.5.1" -ws@^5.1.1, ws@^5.2.0: +ws@^5.2.0: version "5.2.2" resolved "https://registry.verdaccio.org/ws/-/ws-5.2.2.tgz#dffef14866b8e8dc9133582514d1befaf96e980f" integrity sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA== dependencies: async-limiter "~1.0.0" -ws@^6.0.0, ws@^6.2.1: +ws@^6.0.0, ws@^6.1.0, ws@^6.2.1: version "6.2.1" resolved "https://registry.verdaccio.org/ws/-/ws-6.2.1.tgz#442fdf0a47ed64f59b6a5d8ff130f4748ed524fb" integrity sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==