No Description

Gruntfile.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 and 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 version = require("./package.json").version;
  20. grunt.initConfig({
  21. connect: {
  22. server: {
  23. options: {
  24. base: "",
  25. port: 8080
  26. }
  27. }
  28. },
  29. 'saucelabs-qunit': {
  30. all: {
  31. options: {
  32. urls: ["http://127.0.0.1:8080/test/index.html?hidepassed"],
  33. build: process.env.TRAVIS_JOB_ID,
  34. throttled: 4,
  35. "max-duration": 1200, // seconds, IE6 is slow
  36. browsers: browsers,
  37. testname: "qunit tests",
  38. tags: tags,
  39. // Tests have statusCheckAttempts * pollInterval seconds to complete
  40. pollInterval: 2000,
  41. statusCheckAttempts: 240,
  42. "max-duration": 1200,
  43. browsers: browsers,
  44. maxRetries: 2
  45. }
  46. }
  47. },
  48. jshint: {
  49. // see https://github.com/gruntjs/grunt-contrib-jshint/issues/198
  50. // we can't override the options using the jshintrc path
  51. options: grunt.file.readJSON('.jshintrc'),
  52. production: ['./lib/**/*.js'],
  53. test: ['./test/helpers/**/*.js', './test/asserts/**/*.js'],
  54. documentation: {
  55. options: {
  56. // we include js files with jekyll, jshint can't see all
  57. // variables and we can't declare all of them
  58. undef: false,
  59. // 'implied' still give false positives in our case
  60. strict: false
  61. },
  62. files: {
  63. src: ['./documentation/**/*.js']
  64. }
  65. }
  66. },
  67. browserify: {
  68. all: {
  69. files: {
  70. 'dist/jszip.js': ['lib/index.js']
  71. },
  72. options: {
  73. browserifyOptions: {
  74. standalone: 'JSZip',
  75. transform: ['package-json-versionify'],
  76. insertGlobalVars: {
  77. process: undefined,
  78. Buffer: undefined,
  79. __filename: undefined,
  80. __dirname: undefined
  81. },
  82. builtins: false
  83. },
  84. banner: grunt.file.read('lib/license_header.js').replace(/__VERSION__/, version)
  85. }
  86. }
  87. },
  88. uglify: {
  89. options: {
  90. mangle: true,
  91. preserveComments: false,
  92. banner: grunt.file.read('lib/license_header.js').replace(/__VERSION__/, version)
  93. },
  94. all: {
  95. src: 'dist/jszip.js',
  96. dest: 'dist/jszip.min.js'
  97. }
  98. }
  99. });
  100. grunt.loadNpmTasks("grunt-contrib-connect");
  101. grunt.loadNpmTasks("grunt-saucelabs");
  102. grunt.loadNpmTasks('grunt-browserify');
  103. grunt.loadNpmTasks('grunt-contrib-jshint');
  104. grunt.loadNpmTasks('grunt-contrib-uglify');
  105. // A task to cause Grunt to sit and wait, keeping the test server running
  106. grunt.registerTask("wait", function() {
  107. this.async();
  108. });
  109. grunt.registerTask("test-local", ["build", "connect", "wait"]);
  110. grunt.registerTask("test-remote", ["build", "connect", "saucelabs-qunit"]);
  111. if (process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY) {
  112. grunt.registerTask("test", ["jshint", "test-remote"]);
  113. } else {
  114. grunt.registerTask("test", ["jshint", "test-local"]);
  115. }
  116. grunt.registerTask("build", ["browserify", "uglify"]);
  117. grunt.registerTask("default", ["jshint", "build"]);
  118. };