Run all test.html files in the directory - mocha-phantomjs

I have a module, I am testing this module with mocha-phantomjs. I created a filepackage.json

{
  "name"        : "demo-test",
  "scripts": {
    "test": "npm run test-debug",
    "test-debug": "mocha-phantomjs ./test/Test1.html"
  },
  "dependencies" : {
    "mocha"     : "1.13.x",
    "commander" : "1.2.x",
    "which"     : "~1.0.5",
    "mocha-phantomjs": "3.3.2"
  },
  "devDependencies" : {
    "chai"          : "1.8.x",
    "coffee-script" : "1.6.x",
    "requirejs"     : "2.1.x",
    "jquery"        : "2.1.0"
  }
}

Then I ran npm install, and then npm testto run the test. It works great and runs tests test1.html. Now I want all the files (test1, test2, ...) in the test directory to be executed at startup npm test.

I can run all html files by calling them separately in the package.json file, but if there is a way to download all the Html files.

+4
source share
2 answers

, Tests.html mocha-phantomjs, , , script .

Tests.html :

<script src="controller-tests/one-controller-test.js"></script>
<script src="controller-tests/another-controller-test.js"></script>
<script src="controller-tests/yet-another-controller-test.js"></script>
<script src="service-tests/one-service-test.js"></script>
<script src="service-tests/another-service-test.js"></script>
<script src="service-tests/yet-another-service-test.js"></script>

, RequireJS AMD, test-init.js , :

Tests.html

<script src="test-init.js"></script>

-init.js

require('controller-tests/init.js');
require('service-tests/init.js');

-/init.js

require('one-controller-test.js');
require('another-controller-test.js');
require('yet-another-controller-test.js');

-/init.js

require('one-service-test.js');
require('another-service-test.js');
require('yet-another-service-test.js');
+1

DanAri.

.

Mocha BDD

, Mocha "BDD" html "test" . "test.html". "test/test.html" - Mocha .

RequireJS/AMD

(AMD) RequireJS, .

-index.html
  |
  -/js/rjsMain.js
-test/test.html
  |
  -/js/rjsTest.js

RequireJS ( "rjsConfig.js" ). , ..

, RequireJS "/js/rjsMain.js" :

require(['rjsConfig'], function () {
    require(['app/main'], function () {});
});

Require "main.js", Mocha.

, Require. .

PhantomJS

PhantomJS , ? . .

, , .

, , , "load_ajax.js" - , , .

https://gist.github.com/kalharbi/fc9d4f71b5e2a8f485cc

.

0

Source: https://habr.com/ru/post/1527860/


All Articles