build: fix e2e (#246)

* fix: e2e testing

* fix: e2e testing

* fix: e2e testing

* fix: e2e testing

* fix: e2e testing

* fix: e2e testing
This commit is contained in:
Juan Picado @jotadeveloper 2019-11-08 06:23:22 +01:00 committed by GitHub
parent c9f6bf43ae
commit f1971edf6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 59 additions and 31 deletions

View File

@ -86,7 +86,7 @@
"ora": "4.0.2", "ora": "4.0.2",
"prettier": "1.18.2", "prettier": "1.18.2",
"prop-types": "15.7.2", "prop-types": "15.7.2",
"puppeteer": "1.8.0", "puppeteer": "2.0.0",
"react": "16.11.0", "react": "16.11.0",
"react-autosuggest": "9.4.3", "react-autosuggest": "9.4.3",
"react-dom": "16.11.0", "react-dom": "16.11.0",

View File

@ -10,6 +10,9 @@ import Text from '../../muiComponents/Text';
import { CardStyled as Card, HelpTitle } from './styles'; 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 { function renderHeadingClipboardSegments(title: string, text: string): React.ReactNode {
return ( return (
<Fragment> <Fragment>
@ -25,8 +28,8 @@ const Help: React.FC = () => {
return ( return (
<Card id="help-card"> <Card id="help-card">
<CardContent> <CardContent>
<Typography component="h2" gutterBottom={true} id="help-card__title" variant="h5"> <Typography component="h2" gutterBottom={true} id={COMPONENT_HELP_ID} variant="h5">
{'No Package Published Yet.'} {HELP_TITLE}
</Typography> </Typography>
<HelpTitle color="textSecondary" gutterBottom={true}> <HelpTitle color="textSecondary" gutterBottom={true}>
{'To publish your first package just:'} {'To publish your first package just:'}

View File

@ -156,7 +156,7 @@ const Package: React.FC<PackageInterface> = ({
<Grid item={true} xs={true}> <Grid item={true} xs={true}>
<WrapperLink to={`/-/web/detail/${packageName}`}> <WrapperLink to={`/-/web/detail/${packageName}`}>
{/* eslint-disable-next-line react/jsx-max-depth */} {/* eslint-disable-next-line react/jsx-max-depth */}
<PackageTitle>{packageName}</PackageTitle> <PackageTitle className="package-title">{packageName}</PackageTitle>
</WrapperLink> </WrapperLink>
</Grid> </Grid>
<GridRightAligned item={true} xs={true}> <GridRightAligned item={true} xs={true}>

View File

@ -14,7 +14,7 @@ auth:
password: test password: test
logs: logs:
- { type: stdout, format: pretty, level: warn } - { type: stdout, format: pretty, level: info }
packages: packages:
'protected-*': 'protected-*':

View File

@ -14,7 +14,7 @@ auth:
password: test password: test
logs: logs:
- { type: stdout, format: pretty, level: warn } - { type: stdout, format: pretty, level: info }
packages: packages:
'@*/*': '@*/*':

View File

@ -1,3 +1,5 @@
import { HELP_TITLE } from '../../src/components/Help/Help';
const scopedPackageMetadata = require('./partials/pkg-scoped'); const scopedPackageMetadata = require('./partials/pkg-scoped');
const protectedPackageMetadata = require('./partials/pkg-protected'); const protectedPackageMetadata = require('./partials/pkg-protected');
@ -12,16 +14,16 @@ describe('/ (Verdaccio Page)', () => {
await button.click(options); await button.click(options);
}; };
const evaluateSignIn = async function() { const evaluateSignIn = async function(matchText = 'Login') {
const text = await page.evaluate( const text = await page.evaluate(() => {
() => document.querySelector('button[data-testid="header--button-login"]').textContent return document.querySelector('button[data-testid="header--button-login"]').textContent;
); });
expect(text).toMatch('Login'); expect(text).toMatch(matchText);
}; };
const getPackages = async function() { const getPackages = async function() {
return await page.$$('.package-list-items .package-link a'); return await page.$$('.package-title');
}; };
const logIn = async function() { const logIn = async function() {
@ -54,31 +56,34 @@ describe('/ (Verdaccio Page)', () => {
await page.close(); await page.close();
}); });
test('should load without error', async () => { test('should display title', async () => {
const text = await page.evaluate(() => document.body.textContent); const text = await page.title();
await page.waitFor(1000);
// FIXME: perhaps it is not the best approach expect(text).toContain('verdaccio-server-e2e');
expect(text).toContain('Powered by');
}); });
test('should match title with no packages published', async () => { test('should match title with no packages published', async () => {
const text = await page.evaluate(() => document.querySelector('#help-card__title').textContent); 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 () => { test('should match title with first step', async () => {
const text = await page.evaluate(() => document.querySelector('#help-card').textContent); const text = await page.evaluate(() => document.querySelector('#help-card').textContent);
expect(text).toContain('npm adduser --registry http://0.0.0.0:55558'); expect(text).toContain('npm adduser --registry http://0.0.0.0:55558');
}); });
//
test('should match title with second step', async () => { test('should match title with second step', async () => {
const text = await page.evaluate(() => document.querySelector('#help-card').textContent); const text = await page.evaluate(() => document.querySelector('#help-card').textContent);
expect(text).toContain('npm publish --registry http://0.0.0.0:55558'); expect(text).toContain('npm publish --registry http://0.0.0.0:55558');
}); });
//
test('should match button Login to sign in', async () => { test('should match button Login to sign in', async () => {
await evaluateSignIn(); await evaluateSignIn();
}); });
//
test('should click on sign in button', async () => { test('should click on sign in button', async () => {
const signInButton = await page.$('button[data-testid="header--button-login"]'); const signInButton = await page.$('button[data-testid="header--button-login"]');
@ -88,6 +93,7 @@ describe('/ (Verdaccio Page)', () => {
expect(signInDialog).not.toBeNull(); expect(signInDialog).not.toBeNull();
}); });
//
test('should log in an user', async () => { test('should log in an user', async () => {
// we open the dialog // we open the dialog
@ -96,6 +102,7 @@ describe('/ (Verdaccio Page)', () => {
const buttonLogout = await page.$('#header--button-logout'); const buttonLogout = await page.$('#header--button-logout');
expect(buttonLogout).toBeDefined(); expect(buttonLogout).toBeDefined();
}); });
//
test('should logout an user', async () => { test('should logout an user', async () => {
// we assume the user is logged already // we assume the user is logged already
@ -105,6 +112,7 @@ describe('/ (Verdaccio Page)', () => {
await page.waitFor(1000); await page.waitFor(1000);
await evaluateSignIn(); await evaluateSignIn();
}); });
//
test('should check registry info dialog', async () => { test('should check registry info dialog', async () => {
const registryInfoButton = await page.$('#header--button-registryInfo'); const registryInfoButton = await page.$('#header--button-registryInfo');
@ -117,6 +125,7 @@ describe('/ (Verdaccio Page)', () => {
const closeButton = await page.$('#registryInfo--dialog-close'); const closeButton = await page.$('#registryInfo--dialog-close');
closeButton.click(); closeButton.click();
}); });
//
test('should publish a package', async () => { test('should publish a package', async () => {
await global.__SERVER__.putPackage(scopedPackageMetadata.name, scopedPackageMetadata); await global.__SERVER__.putPackage(scopedPackageMetadata.name, scopedPackageMetadata);
@ -126,13 +135,16 @@ describe('/ (Verdaccio Page)', () => {
const packagesList = await getPackages(); const packagesList = await getPackages();
expect(packagesList).toHaveLength(1); expect(packagesList).toHaveLength(1);
}); });
//
test('should navigate to the package detail', async () => { test('should navigate to the package detail', async () => {
const packagesList = await getPackages(); const packagesList = await getPackages();
// console.log("-->packagesList:", packagesList);
const firstPackage = packagesList[0]; const firstPackage = packagesList[0];
await firstPackage.click({ clickCount: 1, delay: 200 }); await firstPackage.click({ clickCount: 1, delay: 200 });
await page.waitFor(1000); await page.waitFor(1000);
const readmeText = await page.evaluate(() => document.querySelector('.markdown-body').textContent); const readmeText = await page.evaluate(() => document.querySelector('.markdown-body').textContent);
expect(readmeText).toMatch('test'); expect(readmeText).toMatch('test');
}); });
@ -140,7 +152,7 @@ describe('/ (Verdaccio Page)', () => {
const versionList = await page.$$('.sidebar-info .detail-info'); const versionList = await page.$$('.sidebar-info .detail-info');
expect(versionList).toHaveLength(1); expect(versionList).toHaveLength(1);
}); });
//
test('should display dependencies tab', async () => { test('should display dependencies tab', async () => {
const dependenciesTab = await page.$$('#dependencies-tab'); const dependenciesTab = await page.$$('#dependencies-tab');
expect(dependenciesTab).toHaveLength(1); expect(dependenciesTab).toHaveLength(1);

View File

@ -10,7 +10,12 @@ const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
module.exports = async function() { module.exports = async function() {
console.log(green('Setup Puppeteer')); 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; global.__BROWSER__ = browser;
mkdirp.sync(DIR); mkdirp.sync(DIR);
fs.writeFileSync(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint()); fs.writeFileSync(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());

View File

@ -6852,6 +6852,14 @@ https-proxy-agent@^2.2.1:
agent-base "^4.3.0" agent-base "^4.3.0"
debug "^3.1.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: humanize@0.0.9:
version "0.0.9" version "0.0.9"
resolved "https://registry.verdaccio.org/humanize/-/humanize-0.0.9.tgz#1994ffaecdfe9c441ed2bdac7452b7bb4c9e41a4" 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" resolved "https://registry.verdaccio.org/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI= integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI=
progress@^2.0.0: progress@^2.0.0, progress@^2.0.1:
version "2.0.3" version "2.0.3"
resolved "https://registry.verdaccio.org/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" resolved "https://registry.verdaccio.org/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== 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" resolved "https://registry.verdaccio.org/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
puppeteer@1.8.0: puppeteer@2.0.0:
version "1.8.0" version "2.0.0"
resolved "https://registry.verdaccio.org/puppeteer/-/puppeteer-1.8.0.tgz#9e8bbd2f5448cc19cac220efc0512837104877ad" resolved "https://registry.verdaccio.org/puppeteer/-/puppeteer-2.0.0.tgz#0612992e29ec418e0a62c8bebe61af1a64d7ec01"
integrity sha512-wJ7Fxs03l4dy/ZXQACUKBBobIuJaS4NHq44q7/QinpAXFMwJMJFEIPjzoksVzUhZxQe+RXnjXH69mg13yMh0BA== integrity sha512-t3MmTWzQxPRP71teU6l0jX47PHXlc4Z52sQv4LJQSZLq1ttkKS2yGM3gaI57uQwZkNaoGd0+HPPMELZkcyhlqA==
dependencies: dependencies:
debug "^3.1.0" debug "^4.1.0"
extract-zip "^1.6.6" extract-zip "^1.6.6"
https-proxy-agent "^2.2.1" https-proxy-agent "^3.0.0"
mime "^2.0.3" mime "^2.0.3"
progress "^2.0.0" progress "^2.0.1"
proxy-from-env "^1.0.0" proxy-from-env "^1.0.0"
rimraf "^2.6.1" rimraf "^2.6.1"
ws "^5.1.1" ws "^6.1.0"
q@^1.1.2, q@^1.5.1: q@^1.1.2, q@^1.5.1:
version "1.5.1" version "1.5.1"
@ -14209,14 +14217,14 @@ write@1.0.3:
dependencies: dependencies:
mkdirp "^0.5.1" mkdirp "^0.5.1"
ws@^5.1.1, ws@^5.2.0: ws@^5.2.0:
version "5.2.2" version "5.2.2"
resolved "https://registry.verdaccio.org/ws/-/ws-5.2.2.tgz#dffef14866b8e8dc9133582514d1befaf96e980f" resolved "https://registry.verdaccio.org/ws/-/ws-5.2.2.tgz#dffef14866b8e8dc9133582514d1befaf96e980f"
integrity sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA== integrity sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==
dependencies: dependencies:
async-limiter "~1.0.0" 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" version "6.2.1"
resolved "https://registry.verdaccio.org/ws/-/ws-6.2.1.tgz#442fdf0a47ed64f59b6a5d8ff130f4748ed524fb" resolved "https://registry.verdaccio.org/ws/-/ws-6.2.1.tgz#442fdf0a47ed64f59b6a5d8ff130f4748ed524fb"
integrity sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA== integrity sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==