Gruntfile.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*jshint node: true */
  2. "use strict";
  3. module.exports = function(grunt) {
  4. // https://wiki.saucelabs.com/display/DOCS/Platform+Configurator
  5. // A lot of the browsers seem to time out with Saucelab's unit testing
  6. // framework. Here are the browsers that work that get enough coverage for our
  7. // needs.
  8. var browsers = [
  9. {browserName: "chrome"},
  10. {browserName: "firefox", platform: "Linux"},
  11. {browserName: "internet explorer"}
  12. ];
  13. var tags = [];
  14. if (process.env.TRAVIS_PULL_REQUEST && process.env.TRAVIS_PULL_REQUEST != "false") {
  15. tags.push("pr" + process.env.TRAVIS_PULL_REQUEST);
  16. } else if (process.env.TRAVIS_BRANCH) {
  17. tags.push(process.env.TRAVIS_BRANCH);
  18. }
  19. var postBundleWithLicense = function(err, src, done) {
  20. if (!err) {
  21. // add the license
  22. var license = require('fs').readFileSync('lib/license_header.js');
  23. done(err, license + src);
  24. } else {
  25. done(err);
  26. }
  27. };
  28. grunt.initConfig({
  29. connect: {
  30. server: {
  31. options: {
  32. base: "",
  33. port: 8080
  34. }
  35. }
  36. },
  37. 'saucelabs-qunit': {
  38. all: {
  39. options: {
  40. urls: ["http://127.0.0.1:8080/test/index.html?hidepassed"],
  41. build: process.env.TRAVIS_JOB_ID,
  42. testname: "qunit tests",
  43. tags: tags,
  44. // Tests have statusCheckAttempts * pollInterval seconds to complete
  45. pollInterval: 2000,
  46. statusCheckAttempts: 15,
  47. "max-duration": 30,
  48. browsers: browsers,
  49. maxRetries: 2
  50. }
  51. }
  52. },
  53. jshint: {
  54. options: {
  55. jshintrc: "./.jshintrc"
  56. },
  57. all: ['./lib/*.js', "Gruntfile.js"]
  58. },
  59. browserify: {
  60. "utils": {
  61. files: {
  62. 'dist/jszip-utils.js': ['lib/index.js']
  63. },
  64. options: {
  65. standalone: 'JSZipUtils',
  66. postBundleCB: postBundleWithLicense
  67. }
  68. },
  69. "utils-ie": {
  70. files: {
  71. 'dist/jszip-utils-ie.js': ['lib/index_IE.js']
  72. },
  73. options: {
  74. postBundleCB: postBundleWithLicense
  75. }
  76. }
  77. },
  78. uglify: {
  79. options: {
  80. report: 'gzip',
  81. mangle: true,
  82. output: {
  83. comments: /^!/
  84. }
  85. },
  86. "jszip-utils": {
  87. src: 'dist/jszip-utils.js',
  88. dest: 'dist/jszip-utils.min.js'
  89. },
  90. "jszip-utils-ie": {
  91. src: 'dist/jszip-utils-ie.js',
  92. dest: 'dist/jszip-utils-ie.min.js'
  93. }
  94. }
  95. });
  96. grunt.loadNpmTasks("grunt-saucelabs");
  97. grunt.loadNpmTasks("grunt-contrib-connect");
  98. grunt.loadNpmTasks('grunt-browserify');
  99. grunt.loadNpmTasks('grunt-contrib-jshint');
  100. grunt.loadNpmTasks('grunt-contrib-uglify');
  101. // A task to cause Grunt to sit and wait, keeping the test server running
  102. grunt.registerTask("wait", function() {
  103. this.async();
  104. });
  105. grunt.registerTask("test-local", ["build", "connect", "wait"]);
  106. grunt.registerTask("test-remote", ["build", "connect", "saucelabs-qunit"]);
  107. if (process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY) {
  108. grunt.registerTask("test", ["jshint", "test-remote"]);
  109. } else {
  110. grunt.registerTask("test", ["jshint", "test-local"]);
  111. }
  112. grunt.registerTask("build", ["browserify", "uglify"]);
  113. grunt.registerTask("default", ["jshint", "build"]);
  114. };