CircleCI Part 2: Unit Testing with Jest

All correct you’ve got lower back possibly from someplace else or I have no idea some bizarre desktop learning algorithms despatched you here if you haven’t watched my earlier video which introduces the idea of unit checking out and steady integration i’d endorse that you just do this tutorial is subsidized by means of circle CI link to discover extra right here probably I have no idea I do not know how this magical publish-production stuff works and but what i am gonna do on this video is i’m honestly gonna make exactly what I pointed out here i am going to make a sketch dot JS file that has a little bit off script code in it i’m gonna create a node challenge so i will be able to run a unit experiment i’m gonna push that project to github and i’m going to link it with circle CI so that the experiment will probably be run earlier than i can merge any changes now github merge understand what do all these matters mean I can even furnish some hyperlinks to videos that you simply could wish to watch earlier than arriving right here if you haven’t used any of those tools before but yeah i’m simply plopping you correct within the center right here if you’ve in no way programmed before no might be probably probably this thing will be exciting right here but yeah ok that gonna be proper so what what do I got this is my coding train github institution and so what I wish to do is I wish to make a brand new repository but i’m gonna do it in a fairly one of a kind approach i am not sure why however i am simply going to a primary one i am gonna do is i’ve a nice folder right here on my laptop called trying out scan experiment checking out dying experiment is the name of my new undertaking cuz it’s all about scan experiment testing it’s trying out and i’ll make a file in it and i’m just gonna call it sketch j/s and i’m going to this incidentally i’ll use the trying out framework that i use in the MoMA i will show you something called jest i’m basically gonna do the illustration that is in the getting started tutorial and jest no longer my invention right here so i am gonna write a really simple perform referred to as the sum and what its gonna do is it is gonna return the sum of two numbers so once more i am displaying you a absolutely trivial illustration that’s style of silly and and and and apparent just to unsee what the entire pieces are and the way it works after which hopefully what i am gonna do is after this i’m definitely gonna add some unit tests to my neural community library thing that i’ve been working on in any other video tutorials however i’m going to get to that later so i’m just scripting this now what do I need to do well with a view to run the exams I must I have got to make a node challenge so one way that i can do that’s with the aid of incidentally in terminal and i am in my listing testing test test and i’m gonna say NPM in it that’s a approach to create a node venture in that directory rather all this is doing is making the bundle.Json file which is the configuration file in your node task and once more any other node tutorials i have go by way of this just a little extra so i’m gonna do this and it can be pronouncing this utility will stroll you by means of making a package deal blah blah blah i need the identify to be checking out scan scan it is variant 1.0 it’s all about all about checking out experiment checking out experiment scan an entry factor is sketched yes we would even auto-detected that was once in there test command whoo the experiment command now i don’t must do this here due to the fact that they constantly trade it later but i know what it is gonna be it’ll be just simply is the amande like JavaScript scan scan just anyway just get repository oh I shouldn’t have one yet hit enter keyword phrases trying out scan then creator is the coding train license MIT I have no idea after which i might say ok and then now if we appear back in Adam appear at this this new file has seemed the package deal that JSON file and that is the file that has all the configuration settings for my assignment that is the essential file there is a scan script i can run referred to as jest it’s all about testing it can be by using the coding instruct in its license MIT and so on okay so now let’s go to the jest site and i’m gonna definitely click on on get started so one factor that i will be able to pull from here is that if I wish to run a test with jest I have got to set up the node package jest and once more i am we refer you to my video about node package deal manager and quite a lot of you who have skilled this will probably be telling you why are not you making use of yarn since supposedly that’s better for a form of reasons i am certain i’ll hear about however i am still on the earth of NPM so i am gonna grasp this and i’ll paste this into terminal now I just want to mention what the I shown in different tutorials what – – keep implies that approach I wish to use this node package in my venture for example i am doing some thing on text analysis so i need the no average textual content evaluation package deal i will say npm install’ keep node natural however save dev manner i’m utilizing this but just for the rationale of progress my mission itself once I post and unencumber it is not doesn’t mean the gest package i want just only for developing it so i’m gonna hit enter and what put on my waiting tune did you get most effective finished okay and now we’re excellent now simply to double-assess this seem at this package deal a json now has dev dependencies jest variation 22 point one point 4 so that – – retailer – dev put it right here in dev dependencies so identity now i’ve my checking out framework now how do I write a experiment one of the crucial things you could do not forget from after I was once watching at the p5 task is the supply folder had your whole JavaScript code and the scan folder had your whole checking out code they usually have been the equal directory buildings for every listing or JavaScript file there was once a corresponding listing JavaScript file for trying out and this is a nice means of doing it from what I comprehend it might end up just a little unwieldy after a while to kind of maintain these reproduction directory structures just supplies a bunch of exclusive ways of doing it through basically the key phrase test and there may be there is a technique of getting a folder that has assessments in it but what i will do right here that is the simplest factor on the planet is i’m just gonna make a brand new file and i am gonna call that file keep in mind if it is experiment dot sketchy-ass or sketch dot test similar to pretty certain it can be sketch dot scan touch ass let’s are attempting calling it that and then let’s go back to the getting started web page and see what it says some so this is illustration that by the way i am doing precisely the equal instance i’m creating and it says the kre-o file referred to as some experiment is so you will see just goes to grasp that this file is associated with this file these are the assessments for this file so now I ought to write those tests boy so i’m going to move and simply preserve falling along with this and i am just going to to be honest with you replica paste the code the illustration and later i will attempt to write my possess test in a extra intriguing approach and we can see this makes sense there is a function I wrote called some that receives two numbers and returns those two numbers introduced together so you will find that is now the syntax the API to count on as a perform to be as a operate those are features which might be a part of jest right some is my operate experiment is a part of jest and this is written with a really great lovely es6 arrow syntax just simply just to love unpack this for a second despite the fact that i love the best way this is written i will try to write experiment this solution to you what i’m gonna do is i am gonna just spoil this out into more than one lines of code just so you can in order that you can see it in a relatively exceptional approach and simply supply me a 2nd even as I do this in the most convoluted method so what this is announcing here now you will discover it can be like I want to run this experiment that is the name of my test and the perform to run the experiment is known as some experiment and it is down right here so that is simply it is exactly the equal as this but it surely’s simply written in a sort of extra lengthy-winded less ordinary like much less fancy more recent means of writing JavaScript all right so I believe we’re type of competent I neglected some stuff here which i’m going to get to excellent I wanted to fail these first i have my JavaScript file and i have my trying out file so there isn’t any motive why i could not now and in bundle that chase saw Jason it says experiment jest and i’ve the dependency k let’s let’s are trying it so now i am here i am gonna hit clear and i am going to assert right here we go NPM test one failed now I already be aware of I failed cuz it type of did that on motive because i don’t be pleasant and like see the experiment fail however we will simply see why did it fail hmm steady sum equals required dot slash some Oh what’s that can not to find module dots some all proper so here’s the article i am utilizing a feature of node that isn’t necessary when just doing client-facet programming which is a patron-facet program would have an HTML file which simply imports all the JavaScript documents i’m making use of however be aware of we must do that extra explicitly and it is a little intricate right here given that maybe you might make the argument if i am writing client-side code I will have to run like exams in the browser and there is a whole colossal world it is like potentialities right here however i am trying to persist with the very very basics the simplest viable state of affairs and if we seem right here in sketch that we will see consistent sum now for it well constant that’s a I would say let’s sum but that is just right it can be no longer going to vary now can it now not gonna be reassigned steady sum equals required dot sum good what this particularly must be in my case is dot sketch this can be a manner require is saying i am going to require a different JavaScript file dot cut down within the same directory known as sketch contact sure then that’s do you suppose that may be better now i’m nonetheless lacking a section I mean i’m now not even going to faux that since i do know that is gonna run it didn’t fail some isn’t a operate so that’s a further error message the motive why imported that file safely however I did not export it so this is one of the matters I do I just say export dot modules no module dot exports module dot exports equals some so that is again there is a lot more to this in phrases of how one can link in reference specific documents but on a very normal level that is pronouncing this node module must export the sum perform that is the one I wish to testify it more than one functions I could export multiple capabilities there is a variety distinct ways i will do this so now here we go whoo-hoo okay so that they experiment go so this is basically if that is MIT alum I’ve type of come to the end of the trying out factor all I’ve done to this point is created this I wrote my code and it would were a p5 project I the module factor is gonna muck that up a little bit so probably i will show you somewhat trick about that in a second but all I’ve completed is write this section so the subsequent matters that I need to do is send this project up to github and then work out a technique to enable any one contributing it to it to have the assessments routinely run be a circle CI ok so that is going to happen within the subsequent video [Music] you

Add Comment