<?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 Oleg Safarov on Medium]]></title>
        <description><![CDATA[Stories by Oleg Safarov on Medium]]></description>
        <link>https://medium.com/@mikesummers-27?source=rss-30b6e1dc1e7c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*cyWNbeiOrnD2TwEE.</url>
            <title>Stories by Oleg Safarov on Medium</title>
            <link>https://medium.com/@mikesummers-27?source=rss-30b6e1dc1e7c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:13:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mikesummers-27/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[3 Tricks to Test Your Widgets with Flutter More Comfortably]]></title>
            <link>https://medium.com/swlh/3-tricks-to-test-your-widgets-with-flutter-more-comfortably-88fcae5616cc?source=rss-30b6e1dc1e7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/88fcae5616cc</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[tricks]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Oleg Safarov]]></dc:creator>
            <pubDate>Wed, 02 Dec 2020 18:09:51 GMT</pubDate>
            <atom:updated>2020-12-04T18:52:30.316Z</atom:updated>
            <content:encoded><![CDATA[<h4>Or what I learned about testing Flutter widgets by getting bumps</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U02gUyEc5vdVP0Id" /><figcaption>Photo by <a href="https://unsplash.com/@mluotio83?utm_source=medium&amp;utm_medium=referral">Miikka Luotio</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Young and bold</h4><p>Flutter has managed to make a noise by claiming to produce natively compiled fast and beautifully designed applications for all the platforms, including mobile, from the same code base. However, even with that swift pace in our industry we’re all so keen on moaning about, it’s still a pretty young framework — as of 2020 it’s merely 3 years old (<em>release 1.22.4</em>).</p><p>As a typical youngster, the framework is prone to some obscurities. Particularly, its documentation, although very informative and even with some video lessons, still has quite a few blind spots that programmers are supposed to figure out on their own. To cap it all, an official package for testing Flutter widgets <a href="https://api.flutter.dev/flutter/flutter_test/flutter_test-library.html">flutter_test</a> features a rather confusing system of emulating asynchronous tasks and rendering components, making it likely to encounter some of its vague ideas. For this very reason, I’d like to present 3 tiny tricks that came to me as revelations, while trudging through the testing realm of Flutter.</p><h4>pump vs pumpAndSettle</h4><p>Flutter tests are based upon a fake system of rendering frames and performing asynchronous tasks for widgets passed to a method pumpWidget of the WidgetTester class: it draws frames as long as they are pumped manually by pump() of WidgetTester. To put it simply, the whole test screen filled with widgets is frozen, and it’s our responsibility to thrust it forward.</p><p>Moreover, all the futures are also waiting for us to move the fake clock forward by passing the duration parameter to the same method — in other words, <strong>all things are run synchronously</strong>. For instance, here we’re literally shifting a clock arrow by 100 milliseconds: tester.pump(Duration(milliseconds: 100))</p><p>However, it implies that we should know how many frames we must pump consecutively. Otherwise, we’re met with a semi-finished rendering and are likely to fail the test. Luckily, there is another method pumpAndSettle in the same class. It runs its counterpart pump() periodically until there are no frames to draw, returning the number of pumped frames.</p><p>Now, there is a great lure for us, lazy developers, to apply pumpAndSettle() everywhere instead of just pump(). Unfortunately, we’re discouraged to do so by an <a href="https://api.flutter.dev/flutter/flutter_test/WidgetController/pumpAndSettle.html">official remark</a>:</p><blockquote>In general, it is better practice to figure out exactly why each frame is needed, and then to pump exactly as many frames as necessary. This will help catch regressions where, for instance, an animation is being started one frame later than it should.</blockquote><p>Thus, they urge us into using pump() to avoid excessive frames and therefore surplus work. Besides, pumpAndSettle() always pumps at least once and by default sets the clock forward 100 milliseconds, even if there is no such a need.</p><p>Apart from that piece of writing, you’ll hardly come across any other elaboration on the issue, let alone any recipes as to how to know how many frames is enough for any individual case. For instance, navigation tends to require 2 pumps, whereas for animations the count varies from case to case. After trial and error, I’ve drawn a conclusion, that the best approach is to use both methods, but consciously. Use pumpAndSettle():</p><ul><li>If it’s a standard animation after such actions of WidgetTester as tap(), showKeyboard(), etc.</li><li>To figure out what number of frames there are to render your widget, or if it differs from what you expect. For instance, to draw a widget with FutureBuilder it might take at least 2 pumps: the first for registering a future and the second for processing its result. After performing that analysis, it’s better to replace it with pump() to not miss any anomalies afterwards.</li></ul><p>For any other cases, it’s better to pump separately and with a certain number of duration if necessary. For example, if you mock getting some data from storage inside your widget and run Future.delayed(Duration(milliseconds: new Random().nextInt(250))), then it’s logical to push the clock forward at least for the same amount of time: tester.pump(Duration(milliseconds: 250)).</p><h4>runAsync — when lying is too deceptive</h4><p>Thanks to the synchronous nature of Flutter tests, at times developers stumble upon a weird behaviour when they try to run asynchronous code beyond the context of pumped frames for widgets. In other words, the same Future.delayed() will freeze a process if it’s called somewhere in your testWidgets method, but not inside a widget, that’s passed to pumpWidget()of WidgetTester.</p><p>Welcome one more useful method runAsync of WidgetTester! It serves to perform such truly asynchronous tasks as long as they can’t be pumped with your widgets:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5fd161e9790fa8fcf93cd31b7dc0735/href">https://medium.com/media/f5fd161e9790fa8fcf93cd31b7dc0735/href</a></iframe><p>Unfortunately, this aspect is not mentioned in <a href="https://flutter.dev/docs/cookbook/testing/widget/introduction">introductory lessons on testing Flutter widgets</a> yet. Moreover, it would even be quite complicated to comprehend the feature without knowing an entire picture of the Flutter synchronous approach. Although we can read about the mission runAsync() undertakes in a <a href="https://api.flutter.dev/flutter/flutter_test/LiveTestWidgetsFlutterBinding/runAsync.html">brief explanation about the method itself</a>, perhaps, it would be far better to highlight the functionality earlier in that very introduction. Otherwise, a programmer discovers that such a method exists through pain and StackOverflow instead of the official documentation.</p><h4>find.byWidgetPredicate or searching for unsearchable</h4><p>It’s a basic and well-known fact of Dart that it regards components of a library (functions, classes and their members, etc.) prefixed with underscore as hidden from other modules. However, sometimes we use such private parts without even knowing it. For instance, a deceptively looking constructor FlatButton.icon in effect hides a factory producing an instance of a private class _FlatButtonWithIcon derived from FlatButton:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00a0baba74091b338c85829fc494c03f/href">https://medium.com/media/00a0baba74091b338c85829fc494c03f/href</a></iframe><p>Now, we could attempt to find such a widget in a conventional way to tap it: find.byType(FlatButton). Unfortunately, it would retrieve no finders, since the method expects the precise FlatButton type, whereas ours is unreachable _FlatButtonWithIcon. As for find.byIcon(), it returns merely an icon which won’t react to the tapmethod of WidgetTester.</p><p>In such a case there turns up to be a more flexible approach:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37c8ac4f4c13b677d99828443fc3cb70/href">https://medium.com/media/37c8ac4f4c13b677d99828443fc3cb70/href</a></iframe><p>Here we look for an ancestor of a widget with a standard icon Icons.addas an example and the type of FlatButton which also includes our dear _FlatButtonWithIcon as a derived class. Thus, by combining several types of finders, we can even test widgets concealed in their libraries. The same pattern works likewise for a few more buttons with their own private classes produced by factories: RaisedButton.icon, OutlinedButton.icon, TextButton.icon, etc.</p><h4>Final thoughts</h4><p>Obviously, programmers are destined to get more experienced through their own trials and errors however well-documented or mature technologies they exploit. Whereas smoothness of the process of learning can vary from tool to tool. In terms of the Flutter testing features, guys from Google have managed to make the entry level rather low, but some deeper conceptions should definitely get a more intent focus from official sources.</p><p>Even though this article is by no means an exhaustible tutorial, but rather a quick look at a few slightly neglected aspects, I hope it might still help clarify such tricky details of testing widgets with Flutter. After all, contributions from community are also an imperative part of active development for any ecosystem.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88fcae5616cc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/3-tricks-to-test-your-widgets-with-flutter-more-comfortably-88fcae5616cc">3 Tricks to Test Your Widgets with Flutter More Comfortably</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Quick Approach to Mend SEO in Vue]]></title>
            <link>https://medium.com/swlh/a-quick-approach-to-mend-seo-in-vue-8a94753eebfc?source=rss-30b6e1dc1e7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a94753eebfc</guid>
            <category><![CDATA[seo]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[prerender]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[vue]]></category>
            <dc:creator><![CDATA[Oleg Safarov]]></dc:creator>
            <pubDate>Sun, 10 May 2020 09:26:24 GMT</pubDate>
            <atom:updated>2020-05-11T10:46:01.907Z</atom:updated>
            <content:encoded><![CDATA[<h4>Why SEO is Problematic for SPA and How to Address the Issue Without Radical Changes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mmFllVglzI34MMEh" /><figcaption>Photo by <a href="https://unsplash.com/@danborn?utm_source=medium&amp;utm_medium=referral">Daniel Born</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Why SEO is Broken in SPA?</h4><p>Developing Single Page Applications (SPA) is fun. Well, at least for us, programmers. However, there are professionals for whom the usage of this technology might grow painful. First and foremost, I’m talking about SEO specialists and the burning issue of indexing SPA sites by search engines, providing your application isn’t for solely internal needs.</p><p>To put it simply, in order for a web site to appear in search results it must be indexed by so-called web crawlers: special bots wandering around page content and extracting necessary data. The trouble with SPA though is that initially there is almost no content ready for the crawlers to consume, apart from a basic markup of a page template. It’s easy to have a peek at what such bots might encounter by merely sending a direct GET request to any route of your SPA. E.g., using standard curl for Linux: curl http://myspa/about -H ‘Accept: text/html, */*’</p><p>In other words, the crawlers will have to await until an SPA framework has rendered an entire page, and in the meantime requests to server will hinder it even more. Thus, the process of crawling demands more sophisticated logic, and not all search engines can implement it nowadays. Their digestion capabilities were very well pictured by <a href="https://moz.com/blog/search-engines-ready-for-javascript-crawling">a 2017 JS SEO experiment</a>. In a nutshell, except for Google and Ask, the rest demonstrated very poor results when dealing with distinct JS frameworks. Although it’s already been 3 years since that study, even Google still encounter problems indexing SPA: crawling takes far more time, whereas some of their useful tools like URL Inspection or Mobile-Friendly Test are totally blind to such pages.</p><p>I’d like to share this tutorial for addressing the problem while using Vue.js — one of the most eminent SPA frameworks nowadays.</p><h4>What Can Resurrect SEO in Vue?</h4><p><a href="https://ssr.vuejs.org/#what-is-server-side-rendering-ssr">The official documentation for Vue</a> says that there are 2 main ways to deal with the issue. The first is using Vue to render pages on server — server-side rendering (SSR). Simply speaking, one gets all the advantages of static sites with better SEO and already compiled markup without having to wait for JS to render it in a browser. However, it’s quite a complicated task to include such logic into an existent pure SPA, and this approach is rather handy for big projects because of its depth and complexity.</p><p>The other technology is about prerendering routes partially during building to serve them as static ones, but nearly without any alterations to your client-specific logic. It’s brought in a form of <a href="https://github.com/chrisvfritz/prerender-spa-plugin">a plugin for Webpack</a> and uses <a href="https://github.com/puppeteer/puppeteer">Puppeteer</a> under the hood — a library with API for manipulating Chrome manually. Even though this approach can be included into fully implemented SPA without drastic changes, there are still some difficulties to tackle.</p><h4>Prerequisites</h4><p>In my case, I developed an SPA without Webpack and had to include it at later stages, even though still being appalled by <a href="https://npm.anvaka.com/#/view/2d/webpack">this</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*G_jyw37X1r5SzvVsPVEecQ.png" /></figure><p>It’s not a tiny galaxy or map of metro, but a graph of dependencies dragged by Webpack. However, the tool turned out useful for setting up an entire process of building, and it does provide freedom to write one’s own plugins instead of relying heavily on other externals. So, let’s put up with its too sociable disposition and take some steps towards setting everything up for prerendering.</p><p>Having installed the Node.js environment alongside Vue (including vue-router), the further step is to obtain necessary packages: webpack, webpack-cli and finally prerender-spa-plugin itself. For each of those packages a command like npm install webpack --save-dev should be run. Then create a configuration file webpack.config.js in the root folder for steering the entire forthcoming logic of prerendering and bundling.</p><h4>Configuring Build Process</h4><p>As mentioned, it will not demand too much time to implement some steps of building on your own without bringing additional plugins for Webpack. Let’s assume that it will include the next stages:</p><ul><li><strong>Cleaning a build folder</strong>:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc9691691d1607fc95fdb7c0b1883b39/href">https://medium.com/media/bc9691691d1607fc95fdb7c0b1883b39/href</a></iframe><p>Here everything happens in the apply method where an action for cleaning the folder is run synchronously through a <a href="https://webpack.js.org/api/compiler-hooks/#hooks">Webpack event hook</a> entryOption, which is called right after processing its entry configuration option. tap accepts a plugin name and the callback itself.</p><ul><li><strong>Copying external libraries to the build folder</strong>:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee8541874ab17ba8b7e80b14aafbd999/href">https://medium.com/media/ee8541874ab17ba8b7e80b14aafbd999/href</a></iframe><ul><li><strong>Rewriting URLs</strong>. Puppeteer, on which the prerenderer plugin is dependent, runs its own server. If your client code contains fetching from server, or URLs to static resources differ from their absolute paths in your project, then you’re likely to emulate the respective responses from your server somehow. For example, API responses could be preliminary copied as JSON files and removed thereafter using other Webpack hooks (e.g., done). During prerendering the files can be served through the mechanism of proxy addresses (equal to <a href="https://webpack.js.org/configuration/dev-server/#devserverproxy">that of Webpack</a>) which helps amend requested URLs. For instance, a path/api/somemethod could be substituted with an address http://localhost:8000/client/somemethod.json which would point to the respective file placed into the client build folder:</li></ul><pre>&quot;proxy&quot;: { <br>  &quot;/api/somemethod&quot;: {<br>    &quot;target&quot;: &quot;<a href="http://localhost:8000/client">http://localhost:8000/client</a>&quot;,<br>    &quot;pathRewrite&quot;: { &quot;/api/somemethod&quot; : &quot;/somemethod.json&quot; }<br>  }<br>}</pre><p>If there is a need for, say, interception of client requests, then extending an existent class of prerenderer might come in handy:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e19a2156398650b5cf22d202f92ba58c/href">https://medium.com/media/e19a2156398650b5cf22d202f92ba58c/href</a></iframe><p>The overhead code performs the same action as the previous sample of proxy: it reacts to a GET request with a certain URL to provide the client with a JSON response.</p><p>Finally, the ultimate version of webpack.config.js including all of the described steps might look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f640c12ffca38f6aa6c4670ceaaa92f/href">https://medium.com/media/4f640c12ffca38f6aa6c4670ceaaa92f/href</a></iframe><h4>Adjusting Client</h4><p>Another necessary step is to prepare Vue components on client. Firstly, the router has to work in <a href="https://router.vuejs.org/guide/essentials/history-mode.html">the history mode</a> to make it use a standard browser API method history.pushStatefor URL navigation and get rid of a hash tag in addresses. This setting also requires serving the main html page as a history fallback for routes from server:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/badd69194637aba36030e664f3b8f42f/href">https://medium.com/media/badd69194637aba36030e664f3b8f42f/href</a></iframe><p>The above handler should be placed after all other handlers related to API to not intercept them.</p><p>Secondly, the prerenderer has to know when a page is ready to capture its content safely — its option in webpack.config.js comes in useful:</p><pre>renderer: new PrerenderSpaPlugin.PuppeteerRenderer({</pre><pre>   renderAfterDocumentEvent: &#39;render-event&#39;</pre><pre>})</pre><p>On client you should fire the event at the moment when the page content is ripe enough for capturing. For instance, in mounted of the main Vue component: document.dispatchEvent(new Event(‘render-event’)). Alternatively, there are settings like renderAfterElementExists and renderAfterTime, though the latter is obviously less dependable as the process time might vary.</p><p>Before dealing with the last stage of preparing Vue, the prerendered pages of the previous step should be provided by server. The logic can be placed into the fallback handler implemented for the router history mode earlier:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5452ba9fdf9be4c5156aca229a846870/href">https://medium.com/media/5452ba9fdf9be4c5156aca229a846870/href</a></iframe><p>Here the server checks if a prerendered path is requested: if it exists, then it will point the response to its folder, otherwise the default template will be taken.</p><p>Now the application is well prepared for debugging and therefore for the last step with a rather peculiar name.</p><h4>Hydration</h4><p>Briefly, the procedure implies Vue comparing what there is already at its fingertips —static DOM — and what it must render overall — virtual DOM. Then, instead of wasting resources to perform already accomplished work afresh, it will concentrate its efforts only on breathing in life into the static markup to make it dynamic again.</p><p>To start the process itself you need to add a custom attribute data-server-rendered=&quot;true&quot; to the root element of Vue — usually withid=”app”.</p><p>Then there is a part requiring patience and perseverance because, despite its seeming simplicity, it might produce lots of intricate errors, that have no universal remedy to prescribe — just a long process of debugging and cutting your prerendered code short.</p><p>First and foremost, make sure that your application uses the development version of Vue (vue.js) to make its messages verbose. In the Web Developer Tools pay your attention to any errors and warnings akin to ‘<em>The client-side rendered virtual DOM tree is not matching server-rendered content</em>’. The warnings might reveal more details about the error by portraying two trees for visual comparison: the actually prerendered nodes and those of the virtual DOM built by Vue. As a rule of thumb, you ought to avoid any mutations to your component template during prerendering, that is to say, mutations in the mounted hook. For instance, this sample will trigger the mismatch error during Hydration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0a86ff7e5d784672e8f51698a26b0fa/href">https://medium.com/media/a0a86ff7e5d784672e8f51698a26b0fa/href</a></iframe><p>However, initialising items in data outright or in beforeMount would resolve the issue. Thus, such mutations should be moved from mounted for prerendering and performed squarely in a browser.</p><p>Another useful option of the prerenderer plugin to tackle the problem is inject. It can be leveraged to include a global variable while prerendering to encapsulate additional client logic during the process and avoid unnecessary computations and rendering:</p><pre>renderer: new PrerenderSpaPlugin.PuppeteerRenderer({</pre><pre>   inject: true // It is possible to pass any object here</pre><pre>})</pre><p>Now, using this property, we could mend the previous component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74b3af1506ee7ee5a5974575c4eda4a0/href">https://medium.com/media/74b3af1506ee7ee5a5974575c4eda4a0/href</a></iframe><p>Here, if an injected global property with a default name __PRERENDER_INJECTED (an option injectProperty to rename it) is present in window, then prerendering is underway, and conversely its absence indicates an application running in a browser.</p><p>In a nutshell, the prerendered outcome should be concise to keep balance between making page content too heavy to get from server and leaving it insufficient to provide crawlers with any useful data. That’s why Hydration, although appearing too restrictive, can actually help you out with cutting out superfluous data on prerendered pages to leave only necessary tags outlining HTML layout, structured data, meta elements, etc.</p><h4>Final Thoughts</h4><p>In short, prerendering provides a great way for SPA to offset their natural lack of supporting SEO. Additionally, the technology also facilitates the process of rendering SPA pages in a browser since they can be served partially prepared for deeper computation on client.</p><p>Using the prerenderer plugin for Webpack implies a flexible approach: without reinventing the wheel one can still write their own small plugins to define the building process, avoiding over-reliance on other dependencies. Moreover, the strategy can even be implemented at later stages of developing and at a rather low cost: no radical rewriting is necessary, but merely small iterative steps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a94753eebfc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/a-quick-approach-to-mend-seo-in-vue-8a94753eebfc">A Quick Approach to Mend SEO in Vue</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>