<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Julian Mendonca on Medium]]></title>
        <description><![CDATA[Stories by Julian Mendonca on Medium]]></description>
        <link>https://medium.com/@julianmendon?source=rss-e9a3221cf922------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*WaBEcjsrMUfivDlI.jpg</url>
            <title>Stories by Julian Mendonca on Medium</title>
            <link>https://medium.com/@julianmendon?source=rss-e9a3221cf922------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 04:45:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@julianmendon/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hosted report on cypress with mochawesome and surge]]></title>
            <link>https://julianmendon.medium.com/hosted-report-on-cypress-with-mochawesome-and-surge-4bde727e8ce3?source=rss-e9a3221cf922------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bde727e8ce3</guid>
            <category><![CDATA[cypress]]></category>
            <category><![CDATA[surge]]></category>
            <category><![CDATA[mochawesome]]></category>
            <category><![CDATA[test]]></category>
            <category><![CDATA[node-cron]]></category>
            <dc:creator><![CDATA[Julian Mendonca]]></dc:creator>
            <pubDate>Wed, 20 May 2020 03:59:45 GMT</pubDate>
            <atom:updated>2020-10-23T03:53:35.836Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mochawesome report for cypress, hosted in surge</h3><p>I’ve created an automated test system for the company i work, I wanted to take the process more automated, so I made a program that runs all the cypress test every hour and save the results in a pretty HTML report, then host that page live in <a href="https://surge.sh/">https://surge.sh/</a> and send an email notifying the status of the process.</p><p>Most of the code for the mochawesome set up was taken from a <a href="https://dev.to/bushraalam/using-mochawesome-reporter-with-cypress-54pf">post</a> made by Bushra Alam</p><h3>Setup</h3><h3>Step 1: Installation</h3><p><em>Install Mocha</em></p><blockquote>npm install mocha --save-dev</blockquote><p><em>Install cypress-multi-reporters</em></p><blockquote>npm install cypress-multi-reporters --save-dev</blockquote><p><em>Install mochawesome</em></p><blockquote>npm install mochawesome --save-dev</blockquote><p><em>Install mochawesome-merge</em></p><blockquote>npm install mochawesome-merge --save-dev</blockquote><p><em>Install mochawesome-report-generator</em></p><blockquote>npm install mochawesome-report-generator --save-dev</blockquote><h3>Step 2: Add reporter settings in cypress.json</h3><blockquote>&quot;reporter&quot;: &quot;cypress-multi-reporters&quot;,<br> &quot;reporterOptions&quot;: {<br> &quot;reporterEnabled&quot;: &quot;mochawesome&quot;,<br> &quot;mochawesomeReporterOptions&quot;: {<br> &quot;reportDir&quot;: &quot;cypress/reports/mocha&quot;,<br> &quot;quite&quot;: true,<br> &quot;overwrite&quot;: false,<br> &quot;html&quot;: false,<br> &quot;json&quot;: true<br> }<br> }</blockquote><h3>Step 3: Add scripts in package.json file</h3><p><strong>For Windows:</strong></p><blockquote>&quot;scripts&quot;: {<br> &quot;clean:reports&quot;: &quot;rmdir /S /Q cypress\\reports &amp;&amp; mkdir cypress\\reports <br> &amp;&amp; mkdir cypress\\reports\\mochareports&quot;,<br> &quot;pretest&quot;: &quot;npm run clean:reports&quot;,<br> &quot;scripts&quot;: &quot;cypress run&quot;,<br> &quot;combine-reports&quot;: &quot;mochawesome-merge<br> cypress/reports/mocha/*.json &gt; cypress/reports/mochareports/report.json&quot;,<br> &quot;generate-report&quot;: &quot;marge cypress/reports/mochareports/<br> report.json -f index -o cypress/reports/mochareports&quot;,<br> &quot;posttest&quot;: &quot;npm run combine-reports &amp;&amp; npm run generate-report&quot;,<br> &quot;test&quot; : &quot;npm run scripts || npm run posttest&quot;<br> }</blockquote><p><strong>In my case i had to make a change in clean:reports, i installed rimraf using</strong></p><blockquote>npm i rimraf</blockquote><p>then set</p><blockquote>“clean:reports”</blockquote><p>to</p><blockquote>“rimraf cypress/reports &amp;&amp; mkdirp cypress/reports &amp;&amp; mkdirp cypress//reports//mochareports”</blockquote><p><strong>For Mac:</strong></p><blockquote>&quot;scripts&quot;: {<br> &quot;clean:reports&quot;: &quot;rm -R -f cypress/reports &amp;&amp; mkdir cypress/reports <br> &amp;&amp; mkdir cypress/reports/mochareports&quot;,<br> &quot;pretest&quot;: &quot;npm run clean:reports&quot;,<br> &quot;scripts&quot;: &quot;cypress run&quot;,<br> &quot;combine-reports&quot;: &quot;mochawesome-merge<br> cypress/reports/mocha/*.json &gt; cypress/reports/mochareports/report.json&quot;,<br> &quot;generate-report&quot;: &quot;marge cypress/reports/mochareports/<br> report.json -f report -o cypress/reports/mochareports&quot;,<br> &quot;posttest&quot;: &quot;npm run combine-reports &amp;&amp; npm run generate-report&quot;,<br> &quot;test&quot; : &quot;npm run scripts || npm run posttest&quot;<br> }</blockquote><p><strong>pretest</strong> script would create the report folders and clear them if they already exists</p><p><strong>test</strong> script will do the following:<br><strong>a. </strong>run your test suite<br><strong>b.</strong> create ‘mocha’ folder under ‘cypress/reports’<br><strong>c. </strong>create .json files (one for each spec executed) in the ‘mocha’ folder</p><p><strong>posttest</strong> script will combine all the .json files present in ‘cypress/reports/mocha’ folder and place the combined file ‘report.json’ in ‘cypress/reports/mochareports’ and create a beautiful html report.</p><h3>Execution</h3><p>It’s time to run test suites and view report.</p><blockquote>npm run test</blockquote><p>Pre and post scripts are automatically executed before and after the main script execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*z1hBGondtqNmD15A.gif" /></figure><p>You can find a sample project here: <a href="https://github.com/bushralam/Cypress">https://github.com/bushralam/Cypress</a></p><h3>Integration with surge!</h3><p>At this point we have an html report of the test generated with mochawesome, now we will make a script that updates the content of our new html in our web page.</p><h4>The first step will be to install surge</h4><blockquote>npm i -g surge</blockquote><h4>then execute the command:</h4><blockquote>surge</blockquote><p>it will ask you for an <strong>email and a password</strong>, if you dont have an account just put your email and password and it will be created.</p><h4>Now we have to add the script in package.json</h4><blockquote>“upload-files”: “surge — project ./cypress/reports/mochareports — domain yourtest.surge.sh”,</blockquote><p>This command will upload the html inside mochareport folder to you web page. Just replace yourtest.surge.sh for your page name.</p><p><strong>If you never created the page, it will be created automatically when you run the command</strong></p><h3><strong>Integration with node-mailer</strong></h3><h4>Instal node mailer</h4><blockquote>npm i nodemailer</blockquote><h4><strong>Then create a js file (I will name it mailSender.js) with this:</strong></h4><blockquote>var nodemailer = require(‘nodemailer’);</blockquote><blockquote>var transporter = nodemailer.createTransport({</blockquote><blockquote>service: ‘hotmail/gmail’,</blockquote><blockquote>auth: {</blockquote><blockquote>user: ‘mail@example.com’,</blockquote><blockquote>pass: ‘password’</blockquote><blockquote>}</blockquote><blockquote>});</blockquote><blockquote>const mailOptions = {</blockquote><blockquote>from: ‘mail@example.com’, // sender address</blockquote><blockquote>to: ‘mail2@example.com’, // list of receivers</blockquote><blockquote>subject: ‘Subject’, // Subject line</blockquote><blockquote>html: ‘&lt;p&gt;Test has been updated in&lt;a href=”http://yourtest.surge.sh/&quot;&gt;YourTest&lt;/a&gt;&lt;/p&gt;&#39;// plain text body</blockquote><blockquote>};</blockquote><blockquote>transporter.sendMail(mailOptions, function (err, info) {</blockquote><blockquote>if (err)</blockquote><blockquote>console.log(err)</blockquote><blockquote>else</blockquote><blockquote>console.log(info);</blockquote><blockquote>});</blockquote><p>First we import nodemailer then we set our sending mail credentials with nodemailer.createTransport, next we set our mail details and send the mail with transporter.sendMail().</p><p>Note that i set <strong>href=”https://yourtest.surge.sh/&quot;, </strong>in here it should go the name of the page where we host the test.</p><h4>inside the scripts in package.json you should add</h4><blockquote>“send-mail”: “node mailSender”,</blockquote><h4>and change the “test” script for</h4><blockquote>“test”: “npm run scripts || npm run posttest &amp;&amp; npm run upload-files &amp;&amp; npm run send-mail”</blockquote><p>Now after the test ends it will upload the new html in surge, and then send an email to notify you the test ended.</p><p>We can now make an script to run the test automatically every certain time.</p><h3>Setting for schedule</h3><p>For this script i will use <strong>node-cron</strong> for setting the schedule and <strong>shelljs</strong> for executing the “npm run test” command. So run this to install them</p><blockquote>npm i shelljs</blockquote><blockquote>npm i node-cron</blockquote><p>Then Create a js file which i will call <strong>runCommand.js</strong> and paste this:</p><blockquote>const cron = require(“node-cron”);</blockquote><blockquote>const shell = require(“shelljs”)</blockquote><blockquote>cron.schedule(“0 * * * *”, function () {</blockquote><blockquote>shell.exec(‘npm run test’)</blockquote><blockquote>});</blockquote><p>In here we use node-crone to set a schedule to run the “<strong>npm run test</strong>” command every hour. You can check <a href="https://www.npmjs.com/package/node-cron">https://www.npmjs.com/package/node-cron</a> for better explaining and usage in node-cron.</p><h3>We can now run</h3><blockquote>node runCommand.js</blockquote><p>and the test will run every hour, upload the files to surge and send us an email notifying us.</p><p>Thank you a lot for reading, hope this was a bit helpfull for you :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bde727e8ce3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>