|
| 1 | +// Karma configuration |
| 2 | + |
| 3 | +// Load Rollup dependencies |
| 4 | +const rollupConfig = { |
| 5 | + resolve: require('rollup-plugin-node-resolve'), |
| 6 | + commonjs: require('rollup-plugin-commonjs'), |
| 7 | + replace: require('rollup-plugin-replace'), |
| 8 | + babel: require('rollup-plugin-babel') |
| 9 | +} |
| 10 | + |
| 11 | +module.exports = function(config) { |
| 12 | + config.set({ |
| 13 | + |
| 14 | + // base path that will be used to resolve all patterns (eg. files, exclude) |
| 15 | + basePath: '', |
| 16 | + |
| 17 | + |
| 18 | + // frameworks to use |
| 19 | + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter |
| 20 | + frameworks: ['mocha', 'chai-spies', 'chai'], |
| 21 | + |
| 22 | + |
| 23 | + // list of files / patterns to load in the browser |
| 24 | + files: [ |
| 25 | + { pattern: 'src/index.js', watched: false }, |
| 26 | + { pattern: 'test/reference/*.*', included: false, served: true }, |
| 27 | + { pattern: require.resolve('pdftest/dist/pdftest.client.min.js'), watched: false }, |
| 28 | + { pattern: require.resolve('pdftest/dist/chai-pdftest.min.js'), watched: false }, |
| 29 | + 'test/**/*.js' |
| 30 | + ], |
| 31 | + |
| 32 | + |
| 33 | + // list of files / patterns to exclude |
| 34 | + exclude: [ |
| 35 | + 'test/manual/', |
| 36 | + ], |
| 37 | + |
| 38 | + |
| 39 | + // preprocess matching files before serving them to the browser |
| 40 | + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor |
| 41 | + preprocessors: { |
| 42 | + 'src/index.js': ['rollup'], |
| 43 | + 'test/**/*.js': ['rollupTests'], |
| 44 | + }, |
| 45 | + |
| 46 | + |
| 47 | + // test results reporter to use |
| 48 | + // possible values: 'dots', 'progress' |
| 49 | + // available reporters: https://npmjs.org/browse/keyword/karma-reporter |
| 50 | + reporters: ['mocha'], |
| 51 | + |
| 52 | + |
| 53 | + // web server port |
| 54 | + port: 9876, |
| 55 | + |
| 56 | + |
| 57 | + // enable / disable colors in the output (reporters and logs) |
| 58 | + colors: true, |
| 59 | + |
| 60 | + |
| 61 | + // level of logging |
| 62 | + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG |
| 63 | + logLevel: config.LOG_INFO, |
| 64 | + |
| 65 | + |
| 66 | + // enable / disable watching file and executing tests whenever any file changes |
| 67 | + autoWatch: true, |
| 68 | + |
| 69 | + |
| 70 | + // start these browsers |
| 71 | + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher |
| 72 | + browsers: ['Chrome'], |
| 73 | + |
| 74 | + |
| 75 | + // Continuous Integration mode |
| 76 | + // if true, Karma captures browsers, runs the tests and exits |
| 77 | + singleRun: false, |
| 78 | + |
| 79 | + // Concurrency level |
| 80 | + // how many browser should be started simultaneous |
| 81 | + concurrency: Infinity, |
| 82 | + |
| 83 | + |
| 84 | + // Remove timeouts so the PDF snapshot GUI can wait on user feedback. |
| 85 | + browserNoActivityTimeout: 0, |
| 86 | + |
| 87 | + |
| 88 | + // Suppress console.log messages |
| 89 | + client: { |
| 90 | + // captureConsole: false |
| 91 | + }, |
| 92 | + |
| 93 | + |
| 94 | + // Rollup preprocessor |
| 95 | + // Setup as a normal Rollup config object, just without the input |
| 96 | + // It has its own autoWatch behaviour, so Karma's file watcher must be disabled on its files |
| 97 | + rollupPreprocessor: { |
| 98 | + output: { |
| 99 | + name: 'html2pdf', |
| 100 | + format: 'iife', |
| 101 | + globals: { |
| 102 | + jspdf: 'jsPDF', |
| 103 | + html2canvas: 'html2canvas' |
| 104 | + } |
| 105 | + }, |
| 106 | + plugins: [ |
| 107 | + rollupConfig.resolve(), |
| 108 | + rollupConfig.commonjs(), |
| 109 | + rollupConfig.replace({ 'process.env.NODE_ENV': JSON.stringify('production') }), |
| 110 | + rollupConfig.babel({ exclude: 'node_modules/**' }) |
| 111 | + ] |
| 112 | + }, |
| 113 | + |
| 114 | + customPreprocessors: { |
| 115 | + rollupTests: { |
| 116 | + base: 'rollup', |
| 117 | + options: { |
| 118 | + output: { |
| 119 | + name: 'html2pdf_test', |
| 120 | + format: 'iife', |
| 121 | + globals: { |
| 122 | + html2pdf: 'html2pdf', |
| 123 | + }, |
| 124 | + }, |
| 125 | + }, |
| 126 | + }, |
| 127 | + }, |
| 128 | + }) |
| 129 | +} |
0 commit comments