0

I have an AngularJS 1.5.11 app where RequireJS 2.2.0 is used everywhere. Unit tests are needed. And I can't get even a dummy test executed. Please advise.

The error:

PhantomJS 2.1.1 (Linux 0.0.0): Executed 0 of 0 ERROR (0.044 secs / 0 secs)

Detailed debug level output from karma start --browsers PhantomJS_custom --log-level debug command: https://gist.github.com/sergibondarenko/1120d211aa2265b76669cd831495a6c1

Test: app/controllers/__tests__/loginController.spec.js

define('loginController', [], function () {
  describe('loginController', function () {
    it('dymmy test', function () {
      expect(true).toBe(false);
    });
  });
});

Karma config: https://gist.github.com/sergibondarenko/4b305341faa24883cb90e6f8f7490d74

Test-main: https://gist.github.com/sergibondarenko/6aa25bf71bfadf39883a59d7cda57a65

Dev dependencies:

:~/dev/qxip/hepic$ grep -rn devD package.json -A 9
20:  "devDependencies": {
21-    "jasmine": "^2.8.0",
22-    "jasmine-core": "^2.4.1",
23-    "karma": "^0.13.22",
24-    "karma-browserify": "^5.1.1",
25-    "karma-jasmine": "^0.3.8",
26-    "karma-phantomjs-launcher": "^1.0.4",
27-    "protractor": "^4.0.9",
28-    "watchify": "^3.9.0"
29-  },

The app structure is below. Some libs are in node_modules, other libs are in lib folder.

user@host:~/dev$ tree -L 1 theapp
theapp
├── app
├── css
├── font-awesome
├── fonts
├── img
├── index.html
├── karma.conf.js
├── lang
├── lib
├── node_modules
├── package.json
├── README.md
├── resources
├── scripts
├── share
├── templates
├── test-main.js
├── tests
└── widgets

Please tell me if you need more info.

3
  • where are you running your tests from ? Also, can you list the complete path for test-main.js instead of just the filename in karma.conf.js ? Commented Aug 27, 2017 at 17:11
  • @82Tuskers I run command karma start --browsers PhantomJS_custom --log-level debug from my app root folder - ~/dev/theapp. The complete path for the test-main.js is ~/dev/theapp/test-main.js, please look the app structure above. Commented Aug 27, 2017 at 19:38
  • can you add a folder beneath app called test; that is /app/test/ and then add your test file as test-file.spec.js. Let me know if that works. Commented Aug 27, 2017 at 19:46

1 Answer 1

1

In your karma.conf.js set this:

browsers: ['PhantomJS', 'PhantomJS_custom'],

    // you can define custom flags
    customLaunchers: {
      'PhantomJS_custom': {
        base: 'PhantomJS',
        options: {
          windowName: 'my-window',
          settings: {
            webSecurityEnabled: false
          },
        },
        flags: ['--load-images=true'],
        debug: true
      }
    },

    phantomjsLauncher: {
      // Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom)
      exitOnResourceError: true
    }

Then supposing that you have your karma.conf.js file in the root, the same level where your app subfolder is and your test-main.js is, execute your tests through:

karma start karma.conf.js
Sign up to request clarification or add additional context in comments.

6 Comments

but I have this part already, look the second gist above gist.github.com/sergibondarenko/…
so what about your files structure? is it as explained?
have you tried to execute your tests through karma start karma.conf.js so?
Yes, I did, the same error - PhantomJS 2.1.1 (Linux 0.0.0): Executed 0 of 0 ERROR (0.045 secs / 0 secs)
You have an issue in your test-main.js. In order to prove that, please remove your dynamic code, and at the moment just push a static test file to your array please: allTestFiles.push(HEREMYSTATICTESTFILE); and check if the static file gets executed. Get back to me once tried please
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.