Better way to integrate maven/qunit/phantomjs?

前端 未结 5 1940
旧巷少年郎
旧巷少年郎 2021-01-31 20:16

I have been investigating the best way to do JS unit testing in our maven CI environment. What I currently have cobbled together is the following in my maven project:

5条回答
  •  花落未央
    2021-01-31 21:06

    Using Kyle's answer and another plugin I was able to get a full solution that doesn't require anything but maven preinstalled and sets up phantomjs and qunit to allow the running of tests. I started with a maven-grunt plugin (github.com/eirslett/frontend-maven-plugin) and followed the steps in this guide (http://blog.trifork.com/2014/10/07/setting-up-maven-to-use-gruntnodejs/) to get it set up. Then I tried to use qunit within maven and I ran into phantomjs trouble and came across this post and found out about Kyle's plugin (github.com/klieber/phantomjs-maven-plugin). I had to use a custom qunit source explained in this guide (http://techblog.dorogin.com/2013/08/issues-with-grunt-contrib-qunit.html). This allowed me to use kyles plugin to install phantomjs then link the binary through grunt options to the custom qunit. In the end my pom looked like:

    `    
            com.github.klieber
            phantomjs-maven-plugin
            0.4
            
              
                generate-resources
                
                  install
                
              
            
            
              1.9.8
            
          
          
            com.github.eirslett
            frontend-maven-plugin
            0.0.20
            
              
                install node and npm
                generate-resources
                
                  install-node-and-npm
                
                
                  v0.10.33
                  1.3.6
                
              
              
                npm install
                generate-resources
                
                  npm
                
                
                  install
                
              
              
                grunt build
                generate-resources
                
                  grunt
                
                
                  --phantomPath=${phantomjs.binary}
                
              
            
          
    `  
    

    My Gruntfile.js looked like:

    `    module.exports = function(grunt) {
          grunt.loadNpmTasks('grunt-croc-qunit');
          grunt.initConfig({
          pkg: grunt.file.readJSON('package.json'),
          qunit: {
            options: {
              'phantomPath': grunt.option('phantomPath')
            },
            all:['src/test/*.html']
          }
      });
      grunt.registerTask('default',['qunit']);
    };`  
    

    And my package.json looked like:

    `    {
      "name":"reporting",
      "version":"0.0.1",
      "dependencies": {
        "grunt": "~0.4.5",
        "grunt-cli": "~0.1.13",
        "grunt-croc-qunit":"~0.3.0"
      },
      "devDependencies":{ }
    }`  
    

提交回复
热议问题