<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mohammad Talha Noman</title>
    <description>The latest articles on Forem by Mohammad Talha Noman (@mtnomani).</description>
    <link>https://forem.com/mtnomani</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F101540%2F0edd7d1e-3006-419c-9532-7a2091936797.jpeg</url>
      <title>Forem: Mohammad Talha Noman</title>
      <link>https://forem.com/mtnomani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mtnomani"/>
    <language>en</language>
    <item>
      <title>SharePoint Online UI Automation using Puppeteer and Docker</title>
      <dc:creator>Mohammad Talha Noman</dc:creator>
      <pubDate>Mon, 18 Nov 2019 10:20:12 +0000</pubDate>
      <link>https://forem.com/mtnomani/sharepoint-online-ui-automation-using-puppeteer-and-docker-8h5</link>
      <guid>https://forem.com/mtnomani/sharepoint-online-ui-automation-using-puppeteer-and-docker-8h5</guid>
      <description>&lt;p&gt;UI automation helps you in great way to reduce manual testing every time you perform a deployment, also if you have a continuous integration and deployment in place it makes more sense to perform end to end tests regularly to be in full control of quality and customer satisfaction.&lt;/p&gt;

&lt;p&gt;As SharePoint online development tools progressing towards modern tooling and practices like TypeScript, NodeJS, Gulp, WebPack, modern JavaScript frameworks and libraries, SharePoint development is becoming more streamlined and controlled.&lt;/p&gt;

&lt;p&gt;Mostly UI Automation Tests which I have come across are based on PhantomJS browser which is actually a headless browser, as we have to run tests in Continuous Integration and Deployment pipeline. But what if you want to do more advanced scenarios inspect page, generate PDFs, page performance etc. Google has covered it for you with headless chrome and Puppeteer NodeJS api for controlling it. You can read more about it &lt;a href="https://medium.com/r/?url=https%3A%2F%2Fdevelopers.google.com%2Fweb%2Fupdates%2F2017%2F04%2Fheadless-chrome"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A simple scenario which I would like to test is to login to SharePoint online, validate that user has been logged in and a specific page exists in the pages library. I have already written an article about &lt;a href="https://dev.to/mtnomani/optimize-nodejs-applications-build-using-docker-4g25"&gt;Optimizing NodeJS application using Docker&lt;/a&gt;, so I will be using that as a base to show how we can run these tests inside docker container so that we have a consistent environment locally and during CI/CD pipeline.&lt;/p&gt;

&lt;p&gt;I have posted a &lt;a href="https://medium.com/r/?url=https%3A%2F%2Fraw.githubusercontent.com%2Ftalha0113%2FBlogs%2Fmaster%2FSharePointOnlineUIAutomation%2FBase%2FDockerfile"&gt;Docker&lt;/a&gt; file and &lt;a href="https://medium.com/r/?url=https%3A%2F%2Fraw.githubusercontent.com%2Ftalha0113%2FBlogs%2Fmaster%2FSharePointOnlineUIAutomation%2FBase%2Fpackage.json"&gt;package.json&lt;/a&gt; file which you can use to build an image with all dependencies required to run tests. Build an image and push it to you favorite private registry Docker Hub or Azure Registry. I am using jest as test platform to execute and write tests with TypeScript. I got inspiration from &lt;a href="https://medium.com/r/?url=https%3A%2F%2Ffacebook.github.io%2Fjest%2Fdocs%2Fen%2Fpuppeteer.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Download the source code from &lt;a href="https://medium.com/r/?url=https%3A%2F%2Fgithub.com%2Ftalha0113%2FBlogs%2Ftree%2Fmaster%2FSharePointOnlineUIAutomation%2FDevelopment"&gt;here&lt;/a&gt;. Provide SharePoint online site URL, username and password in the &lt;a href="https://medium.com/r/?url=https%3A%2F%2Fraw.githubusercontent.com%2Ftalha0113%2FBlogs%2Fmaster%2FSharePointOnlineUIAutomation%2FDevelopment%2FConfigurations%2Fenvironment.config.ts"&gt;environment.ts&lt;/a&gt; file. Replace "" with docker base image which has been pushed to private repository in the &lt;a href="https://medium.com/r/?url=https%3A%2F%2Fraw.githubusercontent.com%2Ftalha0113%2FBlogs%2Fmaster%2FSharePointOnlineUIAutomation%2FDevelopment%2FDockerfile"&gt;Docker file&lt;/a&gt;. Execute following commands in PowerShell as I am using it on windows machine. I have used Azure registry for docker images so have to login first before pulling the image if you are using docker hub private registry than you don't need to do that. If you want to use Azure registry make sure replace the tokens in the commands with appropriate values&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker login &lt;span class="s2"&gt;"&amp;lt;Azure Private Registry Url&amp;gt;"&lt;/span&gt; –username &lt;span class="s2"&gt;"&amp;lt;UserName&amp;gt;"&lt;/span&gt; –password &lt;span class="s2"&gt;"&amp;lt;Password&amp;gt;"&lt;/span&gt; 
docker-compose –file ./docker-compose.yml &lt;span class="nt"&gt;-p&lt;/span&gt; puppeteerclientazure up 
–force-recreate –build –remove-orphans
docker &lt;span class="nb"&gt;logout&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;Azure Private Registry Url"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should be able to see the results of tests in PowerShell&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MErQhE0y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/800/1%2AR6amcF9aQr28L5zymsxCLQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MErQhE0y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/800/1%2AR6amcF9aQr28L5zymsxCLQ.png" alt="" width="648" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should be able to execute all the tests in isolation inside docker container, you should use the same process in CI/CD pipeline by this way local development and testing is consistent with CI/CD pipeline. By this way we can catch issues as early as possible and achieve more quality.&lt;/p&gt;

&lt;p&gt;Originally posted on &lt;a href="https://medium.com/@MTNomani/sharepoint-online-ui-automation-using-puppeteer-and-docker-learning-space-on-wordpress-com-7168bbbfe027"&gt;Medium Blog&lt;/a&gt; Posting&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Optimize NodeJS Applications Build Using Docker</title>
      <dc:creator>Mohammad Talha Noman</dc:creator>
      <pubDate>Mon, 18 Nov 2019 10:08:08 +0000</pubDate>
      <link>https://forem.com/mtnomani/optimize-nodejs-applications-build-using-docker-4g25</link>
      <guid>https://forem.com/mtnomani/optimize-nodejs-applications-build-using-docker-4g25</guid>
      <description>&lt;p&gt;Azure DevOps has really great set of features when it comes to manage project from iterations, continuous integration, continuous delivery etc. With a small change in the code the whole CI/CD pipeline gets trigger and based on the architecture and size of nodejs based application it takes time, for instance Angular application continuous integration takes couple of minutes as it downloads and verify all the npm packages.&lt;/p&gt;

&lt;p&gt;In order to reduce this build/continuous integration time, keep packages version and integrity intact Docker comes into action.&lt;/p&gt;

&lt;p&gt;We need to create a docker image based on Node 9.1.0-alpine. This is very light weight image. We need to install all the required npm packages on it and save it in custom docker registry. I prefer Azure custom registry but you can use any private registry. This image will now have all the locked required dependencies so every time we perform code check in continuous integration instead downloading all the npm package will download the image which is fairly very small. Now we can also share the same image among the team and for different components development, that will help the code integrity as everyone has same dependencies and we are not flooding the machine with npm packages for every component.&lt;/p&gt;

&lt;p&gt;I am using this build process for Angular Applications, Save &lt;a href="https://medium.com/r/?url=https%3A%2F%2Fraw.githubusercontent.com%2Ftalha0113%2FBlogs%2Fmaster%2FOptimizeNodeJSApplicationsBuildUsingDocker%2FBase%2FDockerfile"&gt;Docker file&lt;/a&gt; and &lt;a href="https://medium.com/r/?url=https%3A%2F%2Fraw.githubusercontent.com%2Ftalha0113%2FBlogs%2Fmaster%2FOptimizeNodeJSApplicationsBuildUsingDocker%2FBase%2Fpackage.json"&gt;package.json&lt;/a&gt; file in a folder reserved for building base image. execute following command in PowerShell as I am using windows machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker login &lt;span class="s2"&gt;"&amp;lt;Docker RegistryUrl&amp;gt;"&lt;/span&gt; –username &lt;span class="s2"&gt;"&amp;lt;User Name&amp;gt;"&lt;/span&gt; –password &lt;span class="s2"&gt;"&amp;lt;Password&amp;gt;"&lt;/span&gt;
docker build –tag angular:5.0.1 ./
docker tag angular:5.0.1 &amp;lt;Docker RegistryUrl&amp;gt;/angular:5.0.1
docker push angular:5.0.1 &amp;lt;Docker RegistryUrl&amp;gt;/angular:5.0.1
docker &lt;span class="nb"&gt;logout&lt;/span&gt; &lt;span class="s2"&gt;"samples.azurecr.io"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace  with Private registry or azure registry like for azure "registryname.azurecr.io".&lt;/p&gt;

&lt;p&gt;Create a new directory for angular application. root of the directory must contain package.json, docker file, Source folder(contains all the source code for Angular application), dist folder and Configuration folder(contains webpack and karma configurations). In the docker file replace  with the private registry name you have.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker login &lt;span class="s2"&gt;"&amp;lt;Docker RegistryUrl&amp;gt;"&lt;/span&gt; –username &lt;span class="s2"&gt;"&amp;lt;User Name&amp;gt;"&lt;/span&gt; –password &lt;span class="s2"&gt;"&amp;lt;Password&amp;gt;"&lt;/span&gt;
docker build –tag angular-client-azure ./
docker run –rm –detach –name angular-client-azure-container 
–volume &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;pwd&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/Source:/app/Source 
–volume &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;pwd&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/Dist:/app/Dist –volume &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;pwd&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/Reports:/app/Reports 
&lt;span class="nt"&gt;-p&lt;/span&gt; 4321:4321 &lt;span class="nt"&gt;-i&lt;/span&gt; angular-client-azure
&lt;span class="o"&gt;(&lt;/span&gt;Volume defines mapping between host and container 
&lt;span class="k"&gt;in &lt;/span&gt;order to get data from container vice-versa. As we will 
need &lt;span class="nb"&gt;test &lt;/span&gt;reports and dist files&lt;span class="o"&gt;)&lt;/span&gt;
docker &lt;span class="nb"&gt;exec &lt;/span&gt;angular-client-azure-container npm &lt;span class="nb"&gt;test
&lt;/span&gt;docker &lt;span class="nb"&gt;exec &lt;/span&gt;angular-client-azure-container npm run build
docker &lt;span class="nb"&gt;exec &lt;/span&gt;angular-client-azure-container npm start &lt;span class="o"&gt;(&lt;/span&gt;Optional&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;(&lt;/span&gt;Once your work is finished with the component you can stop 
and remove the container along with the images&lt;span class="o"&gt;)&lt;/span&gt;
docker stop angular-client-azure-container
docker rmi angular-client-azure
docker rmi &amp;lt;Registry Name&amp;gt;.azurecr.io/angular:5.0.1
docker &lt;span class="nb"&gt;logout&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;Registry Name&amp;gt;.azurecr.io"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you will look at package.json file for application there isn't any dependency defined because we have all the dependencies in the container. "npm test" will execute the test and create all the report in the Reports folder. "npm run build" will perform the build and place all the bundles and associated files in Dist folder. If you want to perform code changes and keep the webpack-dev-server running you can execute "npm start".&lt;/p&gt;

&lt;p&gt;You can choose any Continuous Integration system and perform the same tasks automatically.&lt;/p&gt;

&lt;p&gt;Originally posted on &lt;a href="https://medium.com/@MTNomani/optimize-nodejs-applications-build-using-docker-7fc5c756271a"&gt;Medium Blog&lt;/a&gt; Posting&lt;/p&gt;

</description>
      <category>docker</category>
      <category>node</category>
    </item>
    <item>
      <title>Azure DevOps: CosmosDB &amp; Integration Tests</title>
      <dc:creator>Mohammad Talha Noman</dc:creator>
      <pubDate>Mon, 18 Nov 2019 09:45:04 +0000</pubDate>
      <link>https://forem.com/mtnomani/azure-devops-cosmosdb-integration-tests-26dc</link>
      <guid>https://forem.com/mtnomani/azure-devops-cosmosdb-integration-tests-26dc</guid>
      <description>&lt;p&gt;Azure DevOps offers great support when it comes to project management life cycle. Wether delivery plans, tasks management, git repositories, pull requests, reviews, continuous integration, continuous delivery etc. Everything is so powerful and provides full control to ship the software with higher confidence and iterate fast.&lt;/p&gt;

&lt;p&gt;I normally call DevOps a higher level orchestrator, It cannot solve the fast delivery and fast feedback loop. We need to setup a good base, like following coding practices, unit tests, required integration and maybe some end to end tests. Hookup all of these with Continuous Integration and Delivery pipelines.&lt;/p&gt;

&lt;p&gt;I was working on &lt;a href="https://docs.microsoft.com/en-us/azure/azure-functions/" rel="noopener noreferrer"&gt;Azure Functions&lt;/a&gt; which was hooked to &lt;a href="https://docs.microsoft.com/en-us/azure/cosmos-db/introduction" rel="noopener noreferrer"&gt;CosmosDB&lt;/a&gt;. I want to write some integration tests for that. Function was coded using .NET core and binding was used to communicate with CosmosDB. Just few words about CosmosDB, which is very powerful database in terms og Geo replication and low latency. Back to the application and writing some integration tests. You can have a reserved database in Azure used only for integration tests during builds, but there are some drawbacks&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Cleanup of data used during integration tests as tests might fail&lt;/li&gt;
&lt;li&gt;Cost, as each read, write operation and storage of data will cost a bit of money
Seems bit overkill for having a dedicated CosmosDB.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In order to solve this we have couple of options spin up a docker container provided by Microsoft which will expose endpoint and secret which can be passed to test runner as configurations. In order to run a container basically need a task to install from market place you can find the detail &lt;a href="https://docs.microsoft.com/en-us/azure/cosmos-db/tutorial-setup-ci-cd" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;br&gt;
Guidelines above provide are designer pipeline approach of course recommended approach is yaml pipeline which is consider pipeline as code so that it can become versioned controlled as part of your code. Here is the yaml task&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;task&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;CosmosDbEmulator@2&lt;/span&gt;
  &lt;span class="na"&gt;displayName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Cosmos&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;DB&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Emulator'&lt;/span&gt;
  &lt;span class="na"&gt;inputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;containerName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;azure-cosmosdb-emulator'&lt;/span&gt;
    &lt;span class="na"&gt;enableAPI&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;SQL'&lt;/span&gt;
    &lt;span class="na"&gt;portMapping&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;8081:8081,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;8901:8901,&lt;/span&gt;&lt;span class="nv"&gt;  &lt;/span&gt;&lt;span class="s"&gt;8902:8902,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;8979:8979,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;10250:10250,&lt;/span&gt;
 &lt;span class="s"&gt;10251:10251,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;10252:10252,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;10253:10253,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;10254:10254,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;10255:10255,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;10256:10256,&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;10350:10350'&lt;/span&gt;
    &lt;span class="na"&gt;hostDirectory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;$(Build.BinariesDirectory)\azure-cosmosdb-emulator'&lt;/span&gt;
    &lt;span class="na"&gt;consistency&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Session'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But there is a limitation in Azure DevOps it is only working with hosted agent vs2017-win2016. If we choose windows-latest it ends up in timeout during container spin up.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkcx15hat89p1h526sr2d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkcx15hat89p1h526sr2d.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What if we want to target windows-latest hosted machine which has latest visual studio and tools, container is timingout because of some limitations, so we can't utilize windows-latest hosted agent. Also it takes nearly 13 mins just to spin up a container.&lt;/p&gt;

&lt;p&gt;So how to execute integration tests fast and use the emulator on windows-latest hosted agent. Microsoft offers two versions of CosmosDB emulator one we have discussed in the form of docker container and other possibility is CosmosDB emulator. The emulator also comes with PowerShell module for interaction like starting a emulator etc.. Which exists by default on windows-latest, all we need is to import it and start the emulator, key and endpoint of CosmosDB emulator is always same until unless explicit mentioned to get a new key. Task to use in the yaml is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;pwsh&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;        
    &lt;span class="s"&gt;Import-Module "$env:ProgramFiles\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.&lt;/span&gt;
&lt;span class="s"&gt;CosmosDB.Emulator"&lt;/span&gt;
    &lt;span class="s"&gt;Start-CosmosDbEmulator -NoUI -DefaultPartitionCount &lt;/span&gt;&lt;span class="m"&gt;100&lt;/span&gt;
  &lt;span class="na"&gt;displayName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Cosmos&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;DB&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Emulator'&lt;/span&gt;
  &lt;span class="na"&gt;failOnStderr&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;errorActionPreference&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;stop&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can target windows-latest also spin up time of emulator has been reduced from 13 minutes to nearly 4 minutes.&lt;/p&gt;

&lt;p&gt;Now that's an encouragement to say yes to fast integration tests :) &lt;/p&gt;

</description>
      <category>cosmosdb</category>
      <category>devops</category>
      <category>azure</category>
      <category>testing</category>
    </item>
    <item>
      <title>Reusable Angular Vendor for SharePoint</title>
      <dc:creator>Mohammad Talha Noman</dc:creator>
      <pubDate>Mon, 18 Nov 2019 09:40:14 +0000</pubDate>
      <link>https://forem.com/mtnomani/reusable-angular-vendor-for-sharepoint-21p7</link>
      <guid>https://forem.com/mtnomani/reusable-angular-vendor-for-sharepoint-21p7</guid>
      <description>&lt;p&gt;I have been working with AngularJS to develop &lt;strong&gt;SharePoint&lt;/strong&gt; Apps. Now I wanted to develop new SharePoint Apps with &lt;strong&gt;Angular&lt;/strong&gt; 4 with all the awesomeness of new open source tools and build chains like Typescript, WebPack, GulpJS etc.&lt;/p&gt;

&lt;p&gt;So I started building the app as guide lines provided by &lt;a href="https://angular.io/guide/webpack"&gt;Angular Docs&lt;/a&gt;. The scenario is for single angular application on a page so &lt;a href="https://webpack.js.org/plugins/commons-chunk-plugin"&gt;CommonsChunkPlugin&lt;/a&gt; plays very well in order to eliminate common code from multiple bundles. But it develops module resolution structure only specific to the files in that application. So, you cannot use the vendor files for another application.&lt;/p&gt;

&lt;p&gt;In context of SharePoint I would like to have single vendor file and all the SharePoint Apps/WebParts should use the same vendor otherwise it will end up multiple vendor files with duplicate code.&lt;/p&gt;

&lt;p&gt;I came across an interesting article &lt;a href="https://robertknight.github.io/posts/webpack-dll-plugins"&gt;Optimizing Webpack build times and improving caching with DLL bundles&lt;/a&gt;. It helped me solve the issue in SharePoint world, so now I can have single vendor file. You may read more about WebPack &lt;a href="https://webpack.js.org/plugins/dll-plugin"&gt;DllPlugin&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The main idea is to structure the application in two parts vendor bundle build once and deploy to SharePoint site. Application/WebPart bundle to refer the vendor bundle. There can be many Applications/WebParts on the same page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Vendor Bundle
&lt;/h3&gt;

&lt;p&gt;In Vendor Bundle project install following npm packages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;@angular/animations&lt;/li&gt;
&lt;li&gt;@angular/common&lt;/li&gt;
&lt;li&gt;@angular/compiler&lt;/li&gt;
&lt;li&gt;@angular/core&lt;/li&gt;
&lt;li&gt;@angular/forms&lt;/li&gt;
&lt;li&gt;@angular/http&lt;/li&gt;
&lt;li&gt;@angular/platform-browser&lt;/li&gt;
&lt;li&gt;@angular/platform-browser-dynamic&lt;/li&gt;
&lt;li&gt;@angular/platform-server&lt;/li&gt;
&lt;li&gt;@angular/router&lt;/li&gt;
&lt;li&gt;core-js&lt;/li&gt;
&lt;li&gt;rxjs&lt;/li&gt;
&lt;li&gt;zone.js&lt;/li&gt;
&lt;li&gt;awesome-typescript-loader&lt;/li&gt;
&lt;li&gt;source-map-loader&lt;/li&gt;
&lt;li&gt;typescript&lt;/li&gt;
&lt;li&gt;webpack&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Create a &lt;a href="https://raw.githubusercontent.com/talha0113/Blogs/master/ReusableAngularVendorSharePoint/webpack.vendor.config.js"&gt;WebPack configuration&lt;/a&gt;, &lt;a href="https://raw.githubusercontent.com/talha0113/Blogs/master/ReusableAngularVendorSharePoint/tsconfig.json"&gt;tsconfig&lt;/a&gt; and &lt;a href="https://raw.githubusercontent.com/talha0113/Blogs/master/ReusableAngularVendorSharePoint/vendor.ts"&gt;vendor&lt;/a&gt; files in the root of the project. &lt;/p&gt;

&lt;p&gt;Edit package.json file and paste following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="s2"&gt;"scripts"&lt;/span&gt;: &lt;span class="o"&gt;{&lt;/span&gt; 
     &lt;span class="s2"&gt;"build"&lt;/span&gt;: &lt;span class="s2"&gt;"webpack –config ./webpack.vendor.config.js –progress –profile – bail"&lt;/span&gt;,
     ...
   &lt;span class="o"&gt;}&lt;/span&gt;
  ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open command line and execute "npm run build". It will generate &lt;strong&gt;vendor.js&lt;/strong&gt; contains all the base code from Angular and RxJS, also &lt;strong&gt;vendor-manifest.json&lt;/strong&gt; file contains all the reference about how to resolve the different modules from vendor.js. We will be using this file in the SharePoint Application/WebPart. You must publish these file as a npm package to your private/public registry to consume it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Application Bundle
&lt;/h3&gt;

&lt;p&gt;In order to create application you have to follow the guidelines as mentioned in the &lt;a href="https://angular.io/guide/webpack"&gt;Angular Docs&lt;/a&gt;, also we need to do some extra work. Install "vendor" package which we have built above and &lt;a href="https://raw.githubusercontent.com/talha0113/Blogs/master/ReusableAngularVendorSharePoint/webpack.app.config.js"&gt;WebPack configuration&lt;/a&gt; file. Change the path of directories based on your application structure. As you may notice I have used &lt;a href="https://webpack.js.org/plugins/dll-plugin/#dllreferenceplugin"&gt;DllReferencePlugin&lt;/a&gt; in the consumer/application project which provides information to WebPack from where to resolve the modules.&lt;/p&gt;

&lt;p&gt;This approach will not only eliminate duplicate code, but also reduce the build time as well because main chunk of code is coming from Angular which we have already bundled.&lt;/p&gt;

&lt;p&gt;Originally posted on &lt;a href="https://medium.com/@MTNomani/reusable-angular-vendor-for-sharepoint-8a0423692538"&gt;Medium Blog&lt;/a&gt; Posting&lt;/p&gt;

</description>
      <category>angular</category>
      <category>sharepoint</category>
      <category>webpack</category>
    </item>
  </channel>
</rss>
