That seems like boilerplate with all those snippets in separate scripts, but I’ve found that strict ordering of scripts matters with Mocha and I’ll leave it at that. Then I create the script to be tested as /js/lib/my-lib.js with a simple function. For dependencies such as mocha and chai, I specify the URL. Each script is picked up by a JavaScript partial that adds a script element of type="module". Then I use the front matter in that file to declare which scripts to import into the page. I use a /demos directory for my test suites, so I use hugo new demos/my-lib-test-suite.md which cretes the new demo post from the demos archetype. Now we refactor the blog test page to import the browser test from We need the part to pull the desired npm version otherwise, you’ll get a cached ES module in your browser. create a separate node suite that imports Chai and assigns it to the global scope, then imports the browser suite.create a browser suite that will be requested from unpkg.Once we’re “done”, we create a github repo and add the library and test suite to it, refactor the test approach as necessary (node vs browser) using await import() syntax, then publish to npm. This makes it a snap to create an ES module locally. ![]() Using even for remote scripts from another domain works right now. Use Mocha, Chai, module-type scripts, and ES import/export syntax. , a distribution network service for downloading npm packages.Ĭreate a page that will include script tags for mocha, chai, et al.NPM, a Node.js package management system., site for hosting projects built on git, a distributed version control system.Node.js, a server-side JavaScript environment.Chai.js, an assertion library used with Mocha.Mocha.js, an easy to use JavaScript test runner.With Hugo, I can even view test suites running locally. The reloading experience has been very much like running a test page with live-server. ![]() It’s the main reason why I switched to Hugo.īecause Hugo rebuilds and reloads things so quickly, it took me minutes to build the initial proof of concept using mocha, chai, and fast-check. How I use Hugo server for test-driving JavaScript development, with hugo server, github, npm, and unpkg.Īs a fan of test-driven development (TDD), I have been delighted to discover a way to do it directly in web pages served by Hugo, while running hugo server locally. JavaScript Testing TDD Hugo Node.js NPM ~ building & testing JavaScript, CSS, HTML ~ Using Hugo for TDD With Javascript 6 minute read
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |