UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

212 lines (152 loc) 6.26 kB
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>The source code</title> <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="../resources/prettify/prettify.js"></script> <style type="text/css"> .highlight { display: block; background-color: #ddd; } </style> <script type="text/javascript"> function highlight() { document.getElementById(location.hash.replace(/#/, "")).className = "highlight"; } </script> </head> <body onload="prettyPrint(); highlight();"> <pre class="prettyprint lang-js">/* Siesta 5.6.1 Copyright(c) 2009-2022 Bryntum AB https://bryntum.com/contact https://bryntum.com/products/siesta/license */ <span id='Siesta-Project-NodeJS'>/** </span>@class Siesta.Project.NodeJS @extends Siesta.Project Class, representing the NodeJS project. For a getting start guide and manual, please refer to &lt;a href=&quot;#!/guide/getting_started_browser&quot;&gt;Siesta getting started in browser environment&lt;/a&gt; guide. Synopsys ======== var siesta = require(&#39;siesta-lite&#39;) var project = new siesta.NodeJsHarness() project.configure({ title : &#39;Awesome Test Suite&#39;, autoCheckGlobals : true, expectedGlobals : [ &#39;Ext&#39;, &#39;Sch&#39; ], preload : [ ] }) project.plan( // simple string - url relative to project file &#39;sanity.t.js&#39;, // test file descriptor with own configuration options { url : &#39;basic.t.js&#39;, // replace `preload` option of project preload : [ &quot;../awesome-project-all.js&quot; ] }, // groups (&quot;folders&quot;) of test files (possibly with own options) { group : &#39;Sanity&#39;, autoCheckGlobals : false, items : [ &#39;data/crud.t.js&#39;, ... ] }, ... ) project.start() Running the test suite in NodeJS ================================ To run the suite in NodeJS, launch the project javascript file: &gt; node t/index.js */ !function () { var fs = require(&#39;fs&#39;) var path = require(&#39;path&#39;) var glob = require(&#39;glob&#39;) Class(&#39;Siesta.Project.NodeJS&#39;, { isa : Siesta.Project, does : [ Siesta.Util.Role.CanEscapeRegExp, Siesta.Launcher.Role.CanProcessArguments ], has : { <span id='Siesta-Project-NodeJS-cfg-testClass'> /** </span> * @cfg {Class} testClass The test class which will be used for creating test instances, defaults to {@link Siesta.Test.NodeJS}. * You can subclass {@link Siesta.Test.NodeJS} and provide a new class, please refer to the &lt;a href=&quot;#!/guide/extending_test_clas&quot;&gt;Extending test class&lt;/a&gt; guide. * * This option can be also specified in the test file descriptor. */ testClass : Siesta.Test.NodeJS, transparentEx : true, baseDirectory : null, contentManagerClass : Siesta.Content.Manager.NodeJS, scopeProvider : &#39;Scope.Provider.NodeJsEmbed&#39;, chdirToIndex : true, ecmaModulesEnabled : function () { return Boolean(require(&#39;module&#39;)._extensions[ &#39;.mjs&#39; ]) } }, methods : { getScopeProviderConfigFor : function (desc, launchId) { var config = this.SUPER(desc, launchId) config.requireFunc = PROJECT_REQUIRE || require return config }, startAnonymously : function () { var isLauncher = typeof AS_LAUNCHER != &#39;undefined&#39; var testFileGlob = this.ecmaModulesEnabled ? &quot;**/*.t.?(m)js&quot; : &quot;**/*.t.js&quot; var res = this.processArguments(process.argv.slice(isLauncher ? 2 : 3)) var argv = res.argv var options = res.options if (argv.length == 0 &amp;&amp; (options.help || options.version)) { // shortcut to show the help/version text immediately, w/o scanning current directory this.start() } else { var globPattern = argv[ 0 ] || options.glob || testFileGlob var files = glob.sync(globPattern, { matchBase : false, ignore : &#39;**/node_modules/**&#39; }) var baseDir = process.cwd() var me = this var items = [] files.forEach(function (file) { var stat = fs.statSync(file) if (stat.isDirectory()) { me.planDirectory(file, baseDir) } else items.push(file) }) this.plan(items) this.start() } }, <span id='Siesta-Project-NodeJS-method-planDirectory'> /** </span> * This method scans the given directory for test files (`*.t.js` by default) * and adds them to the project plan. * * @param {String} dirname The directory to scan for test files */ planDirectory : function (dirname, baseDir) { baseDir = baseDir || dirname var testFileGlob = this.ecmaModulesEnabled ? &quot;**/*.t.?(m)js&quot; : &quot;**/*.t.js&quot; var testsInDir = glob.sync(testFileGlob, { cwd : dirname, matchBase : true, ignore : &#39;**/node_modules/**&#39; }) this.plan( testsInDir.map(function (testFile) { return path.relative(baseDir, path.resolve(dirname, testFile)) }) ) } } }) //eof Siesta.Project.NodeJS }() </pre> </body> </html>