]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Add rollup-tests task to compile tests into one file timrwood/babel-and-rollup 3090/head
authorTim Wood <washwithcare@gmail.com>
Tue, 5 Apr 2016 15:36:06 +0000 (10:36 -0500)
committerTim Wood <washwithcare@gmail.com>
Tue, 5 Apr 2016 15:36:06 +0000 (10:36 -0500)
Gruntfile.js
package.json
tasks/qtest.js
tasks/rollup-tests.js [new file with mode: 0644]
tasks/rollup.js

index ae3361041a5ca1e5beeea5ffb0c60ba7060016f9..97fd72809e7184c08c34075330c17bb5a0151cb2 100644 (file)
@@ -12,8 +12,7 @@ module.exports = function (grunt) {
                 browserDisconnectTolerance: 2,
                 frameworks: ['qunit'],
                 files: [
-                    'min/moment-with-locales.js',
-                    'min/tests.js'
+                    'build/tests.js'
                 ],
                 sauceLabs: {
                     startConnect: true,
@@ -198,12 +197,12 @@ module.exports = function (grunt) {
 
     // test tasks
     grunt.registerTask('test', ['test:node']);
-    grunt.registerTask('test:node', ['transpile', 'qtest']);
+    grunt.registerTask('test:node', ['rollup-tests', 'qtest']);
     // TODO: For some weird reason karma doesn't like the files in
     // build/umd/min/* but works with min/*, so update-index, then git checkout
-    grunt.registerTask('test:server', ['transpile', 'update-index', 'karma:server']);
-    grunt.registerTask('test:browser', ['transpile', 'update-index', 'karma:chrome', 'karma:firefox']);
-    grunt.registerTask('test:sauce-browser', ['transpile', 'update-index', 'env:sauceLabs', 'karma:sauce']);
+    grunt.registerTask('test:server', ['rollup-tests', 'update-index', 'karma:server']);
+    grunt.registerTask('test:browser', ['rollup-tests', 'update-index', 'karma:chrome', 'karma:firefox']);
+    grunt.registerTask('test:sauce-browser', ['rollup-tests', 'update-index', 'env:sauceLabs', 'karma:sauce']);
     grunt.registerTask('test:meteor', ['exec:meteor-init', 'exec:meteor-test', 'exec:meteor-cleanup']);
 
     // travis build task
index 249eb1b4d5f1cbc9ce22c2afd05763ea01a27361..94724c831260805d317993fe904ab4031ff9ccfb 100644 (file)
@@ -65,7 +65,9 @@
         "karma-sauce-launcher": "latest",
         "qunit": "^0.7.5",
         "qunit-cli": "^0.1.4",
+        "rollup": "latest",
         "rollup-plugin-babel": "latest",
+        "rollup-plugin-multi-entry": "latest",
         "spacejam": "latest",
         "coveralls": "^2.11.2",
         "nyc": "^2.1.4"
index e0094984313c80655f53598e5caa36aa95ba3726..0894bb04036526cdaf61f9218e977aeb2fdfbef0 100644 (file)
@@ -1,34 +1,18 @@
+var testrunner = require('qunit');
+
+testrunner.options.log.assertions = false;
+testrunner.options.log.tests = false;
+testrunner.options.log.summary = false;
+testrunner.options.log.testing = false;
+testrunner.options.maxBlockDuration = 120000;
+
 module.exports = function (grunt) {
     grunt.task.registerTask('qtest', 'run tests locally', function () {
         var done = this.async();
 
-        var testrunner = require('qunit');
-
-        testrunner.options.log.assertions = false;
-        testrunner.options.log.tests = false;
-        testrunner.options.log.summary = false;
-        testrunner.options.log.testing = false;
-        testrunner.options.maxBlockDuration = 120000;
-
-        var tests;
-
-        if (grunt.option('only') != null) {
-            tests = grunt.file.expand.apply(null, grunt.option('only').split(',').map(function (file) {
-                if (file === 'moment') {
-                    return 'build/cjs/test/moment/*.js';
-                } else if (file === 'locale') {
-                    return 'build/cjs/test/locale/*.js';
-                } else {
-                    return 'build/cjs/test/' + file + '.js';
-                }
-            }));
-        } else {
-            tests = grunt.file.expand('build/umd/test/*.js');
-        }
-
         testrunner.run({
-            code: 'build/umd/moment.js',
-            tests: tests
+            code: 'moment.js',
+            tests: 'build/tests.js'
         }, function (err, report) {
             if (err) {
                 console.log('woot', err, report);
diff --git a/tasks/rollup-tests.js b/tasks/rollup-tests.js
new file mode 100644 (file)
index 0000000..c64cf02
--- /dev/null
@@ -0,0 +1,39 @@
+var rollup = require('rollup');
+var babelPlugin = require('rollup-plugin-babel');
+var multiEntry = require('rollup-plugin-multi-entry').default;
+
+function testFiles(grunt) {
+    var only = grunt.option('only') || '{moment,locale}/*';
+    return grunt.file.expand({
+        filter: 'isFile'
+    }, 'src/test/**/' + only + '{,.js,**/*.js}');
+}
+
+module.exports = function (grunt) {
+    grunt.task.registerTask('rollup-tests', 'bundle tests', function () {
+        var done = this.async();
+        var files = testFiles(grunt);
+
+        if (grunt.option('only')) {
+            console.log('Only testing files ' + files.join(', '));
+        }
+
+        rollup.rollup({
+            entry: files,
+            plugins: [
+                multiEntry(),
+                babelPlugin({
+                    babelrc: false,
+                    compact: false,
+                    presets: ['es2015-loose-rollup']
+                })
+            ]
+        }).then(function (bundle) {
+            return bundle.write({
+                format: 'iife',
+                moduleName: 'momentTests',
+                dest: 'build/tests.js'
+            });
+        }).then(done, done);
+    });
+};
index 2861988b3ad085af5004301ef7642dcbac255cff..fd91c9286fae503e406daa3df0420644508a8104 100644 (file)
@@ -39,15 +39,6 @@ module.exports = function (grunt) {
                 src: 'src/locales.js',
                 dest: 'build/umd/locales.js'
             }]
-        },
-        tests: {
-            options: {
-                format: 'iife'
-            },
-            files: [{
-                src: 'src/test/all.js',
-                dest: 'build/umd/test/all.js'
-            }]
         }
     });
 };