From f499f7b44cfbc1029ca1c45cf4e4552e6aa45b85 Mon Sep 17 00:00:00 2001 From: Franck Garcia Date: Tue, 23 Jul 2013 09:14:00 -0400 Subject: [PATCH] test(e2e): add a test for dojo adapter Closes #328 --- package.json | 1 + test/e2e/dojo/dependency.js | 7 ++++ test/e2e/dojo/karma.conf.js | 64 +++++++++++++++++++++++++++++++++++++ test/e2e/dojo/main.js | 32 +++++++++++++++++++ test/e2e/dojo/test.js | 18 +++++++++++ 5 files changed, 122 insertions(+) create mode 100644 test/e2e/dojo/dependency.js create mode 100644 test/e2e/dojo/karma.conf.js create mode 100644 test/e2e/dojo/main.js create mode 100644 test/e2e/dojo/test.js diff --git a/package.json b/package.json index be1c9b463..636f09c8b 100644 --- a/package.json +++ b/package.json @@ -142,6 +142,7 @@ "karma-ng-scenario": "*", "karma-coffee-preprocessor": "*", "karma-html2js-preprocessor": "*", + "karma-dojo":"*", "semver": "~1.1.4", "grunt-contrib-watch": "~0.5.0" }, diff --git a/test/e2e/dojo/dependency.js b/test/e2e/dojo/dependency.js new file mode 100644 index 000000000..f4cdd0f32 --- /dev/null +++ b/test/e2e/dojo/dependency.js @@ -0,0 +1,7 @@ +define(function() { + // return the module value + return function (a, b) { + return a + b; + }; + } +); diff --git a/test/e2e/dojo/karma.conf.js b/test/e2e/dojo/karma.conf.js new file mode 100644 index 000000000..1be838974 --- /dev/null +++ b/test/e2e/dojo/karma.conf.js @@ -0,0 +1,64 @@ +module.exports = function(config) { + config.set({ + // base path, that will be used to resolve files and exclude + basePath: '', + + frameworks: ['jasmine', 'dojo'], + + // list of files / patterns to load in the browser + files: [ + 'main.js', + + // all the sources, tests + {pattern: '*.js', included: false} + ], + + + // test results reporter to use + // possible values: dots || progress + reporters: ['dots'], + + + // web server port + port: 9876, + + + // cli runner port + runnerPort: 9100, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG + logLevel: config.LOG_INFO, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + + // Start these browsers, currently available: + // - Chrome + // - ChromeCanary + // - Firefox + // - Opera + // - Safari + // - PhantomJS + browsers: [process.env.TRAVIS ? 'Firefox' : 'Chrome'], + + + // Continuous Integration mode + // if true, it capture browsers, run tests and exit + singleRun: false, + + plugins: [ + 'karma-dojo', + 'karma-jasmine', + 'karma-chrome-launcher', + 'karma-firefox-launcher' + ] + }); +}; diff --git a/test/e2e/dojo/main.js b/test/e2e/dojo/main.js new file mode 100644 index 000000000..08d68f781 --- /dev/null +++ b/test/e2e/dojo/main.js @@ -0,0 +1,32 @@ +var allTestFiles = []; +var TEST_REGEXP = /test.*\.js$/; + +Object.keys(window.__karma__.files).forEach(function(file) { + if (TEST_REGEXP.test(file)) { + allTestFiles.push(file); + } +}); + +var dojoConfig = { + packages: [ + { name:"local" ,location:"/base"}, + { name: "dojo", location: "http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo" }, + { name: "dojox", location: "http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojox" } + ], + asynch: true +}; + + +/** + * This function must be defined and is called back by the dojo adapter + * @returns {string} a list of dojo spec/test modules to register with your testing framework + */ +window.__karma__.dojoStart = function(){ + return allTestFiles; +} + + + + + + diff --git a/test/e2e/dojo/test.js b/test/e2e/dojo/test.js new file mode 100644 index 000000000..fd12b2862 --- /dev/null +++ b/test/e2e/dojo/test.js @@ -0,0 +1,18 @@ +define(['local/dependency','dojo/_base/lang'], function(dep,lang) { + + // jasmine + describe('something', function() { + it('should pass', function() { + expect(true).toBe(true); + }); + + it('should sum', function() { + expect(dep(1, 2)).toBe(3); + }); + + it('should trim using a dojo AMD module',function(){ + expect(lang.trim(" len4 ").length).toEqual(4); + }); + + }); +});