From 607cb6e168ee699e8393f59b3f25cf0415484afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Mathieu?= Date: Mon, 16 Jun 2014 20:26:47 +0200 Subject: [PATCH] update i18n tests to units and add has tests --- .travis.yml | 3 +- Gruntfile.js | 17 +- has.js | 2 +- i18n.js | 2 +- tests/README.md | 14 +- tests/has.js | 180 +++++++++++++++++ tests/i18n.js | 333 +++++++++++++++++++++++++++++++ tests/i18nBuilt.js | 194 ------------------ tests/intern.js | 101 ++++++++++ tests/intern.local.js | 19 ++ tests/local.js | 47 ----- tests/sauce.js | 45 ----- tests/testApp/dist/myapp/test.js | 6 +- tests/testBuilt.html | 52 ----- tests/testModules/module1.js | 3 + tests/testModules/module2.js | 3 + tests/testModules/module3.js | 3 + tests/testModules/plugin.js | 7 + 18 files changed, 669 insertions(+), 362 deletions(-) create mode 100644 tests/has.js create mode 100644 tests/i18n.js delete mode 100644 tests/i18nBuilt.js create mode 100644 tests/intern.js create mode 100644 tests/intern.local.js delete mode 100644 tests/local.js delete mode 100644 tests/sauce.js delete mode 100644 tests/testBuilt.html create mode 100644 tests/testModules/module1.js create mode 100644 tests/testModules/module2.js create mode 100644 tests/testModules/module3.js create mode 100644 tests/testModules/plugin.js diff --git a/.travis.yml b/.travis.yml index be76563..8b953e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,7 @@ node_js: '0.10' before_script: - npm install -g grunt-cli script: -- grunt jshint -- grunt intern:sauce +- grunt travis env: global: - secure: W5vbUYV3APtbtMw+dcogNIAB+G90nO9XTjYRBCkBMmRWOBAWan2BG3/9azENq6RHa8+J9fxd2VK/kcUz9sHTCezY1SfsUHmEKBR9/RiqFHi3HpucaLpqncGURvvAbwKCXmVnCbmEVBY6GCgQn2R/7bHEjp/gdFy7Q3oojnOtB4Q= diff --git a/Gruntfile.js b/Gruntfile.js index eb54d36..96c7a77 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,7 +4,8 @@ module.exports = function (grunt) { var filesList = [ "*.js", "*.json", - "i18n/*.js" + "i18n/*.js", + "tests/*.js" ]; @@ -48,17 +49,10 @@ module.exports = function (grunt) { reporters: ["console"] } }, - sauce: { - options: { - runType: 'runner', // defaults to 'client' - config: 'tests/sauce', - reporters: ['console'] - } - }, local: { options: { runType: 'runner', // defaults to 'client' - config: 'tests/local', + config: 'tests/intern.local', reporters: ['console', 'lcov'] } } @@ -73,9 +67,12 @@ module.exports = function (grunt) { // By default, lint and run all tests. - grunt.registerTask("default", ["jsbeautifier", "lineending", "jshint", "intern:local"]); + grunt.registerTask("default", ["jsbeautifier", "lineending", "jshint", "intern:remote"]); // Just lint grunt.registerTask("lint", ["jsbeautifier", "lineending", "jshint"]); + // Travis build + grunt.registerTask("travis", ["jshint", "intern:remote"]); + }; diff --git a/has.js b/has.js index 9d6aa7e..8c9d649 100644 --- a/has.js +++ b/has.js @@ -53,7 +53,7 @@ define(["module"], function (module) { if (tokens[i] !== ":" && tokens[i] !== "?" && tokens[i + 1] !== "?") { // The module could be another plugin var parts = tokens[i].split("!"); - parts = parts.map(normalize); + parts[0] = normalize(parts[0]); tokens[i] = parts.join("!"); } } diff --git a/i18n.js b/i18n.js index d548cc9..5e3b723 100644 --- a/i18n.js +++ b/i18n.js @@ -129,7 +129,7 @@ define(["./i18n/common", "./i18n/build", "module"], function (common, build, mod onLoad(); return; } - + config = config || {}; var moduleConfig = {}, diff --git a/tests/README.md b/tests/README.md index c23a36d..7438d85 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,5 +1,5 @@ -# i18n Plugin Tests -This directory contains the i18n plugin tests. +# Plugins Tests +This directory contains the plugins tests. ## Setup Before starting, install Intern and RequireJS by running @@ -13,14 +13,14 @@ setup your SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables as they are on https://saucelabs.com/appium/tutorial/3. -## Running the functional tests in Sauce Labs +## Running the units tests in Sauce Labs Run: ``` -$ node node_modules/intern/runner.js config=tests/sauce +$ node node_modules/intern/runner.js config=tests/intern ``` -## Running the functional tests locally +## Running the unit tests locally 1) Download selenium server 2.37.0 (http://www.seleniumhq.org/download/) and start it on the default port (4444): @@ -28,10 +28,10 @@ $ node node_modules/intern/runner.js config=tests/sauce $ java -jar selenium-server-standalone-2.37.0.jar ``` -2) Edit local.js to list which browsers to test +2) Edit [intern.local.js](./intern.local.js) to list which browsers to test 3) Run the tests: ``` -$ node node_modules/intern/runner.js config=tests/locale +$ node node_modules/intern/runner.js config=tests/intern.local ``` \ No newline at end of file diff --git a/tests/has.js b/tests/has.js new file mode 100644 index 0000000..bfbf9df --- /dev/null +++ b/tests/has.js @@ -0,0 +1,180 @@ +/* global moduleRequire:true, pluginRequire:true, testGlobal:true */ +define([ + "intern!object", + "intern/chai!assert" +], function (registerSuite, assert) { + + registerSuite({ + name: "has - module", + setup: function () { + moduleRequire = require.config({ + context: "module", + baseUrl: "../../", + config: { + has: { + "config-feature": true, + "config-feature2": false + } + } + }); + }, + beforeEach: function () {}, + "Cache setup from config": function () { + var dfd = this.async(); + + moduleRequire(["has"], dfd.callback(function (has) { + assert.isTrue(has.cache["config-feature"], "import feature from config"); + assert.isFalse(has.cache["config-feature2"], "import feature from config"); + assert.isUndefined(has.cache["undefined feature"], "import feature from config"); + })); + }, + "has function": function () { + var dfd = this.async(); + + moduleRequire(["has"], dfd.callback(function (has) { + assert.isTrue(has("config-feature"), "import feature from config"); + assert.isFalse(has("config-feature2"), "import feature from config"); + assert.isUndefined(has("undefined feature"), "import feature from config"); + })); + }, + "add feature": function () { + var dfd = this.async(); + + moduleRequire(["has"], dfd.callback(function (has) { + has.add("add-feature", function () { + return true; + }); + has.add("add-feature2", function () { + return false; + }); + assert.isTrue(has("add-feature"), "added a true feature."); + assert.isFalse(has("add-feature2"), "added a false feature"); + })); + }, + "add feature, lazy evaluation": function () { + var dfd = this.async(); + + moduleRequire(["has"], dfd.callback(function (has) { + testGlobal = false; + has.add("lazy-feature", function (global) { + return global.testGlobal; + }); + has.add("lazy-feature2", function (global) { + return global.testGlobal; + }, true); + testGlobal = true; + + assert.isTrue(has("lazy-feature"), + "should be true as the test function should be lazily evaluated."); + assert.isFalse(has("lazy-feature2"), + "should be false as the test function should be evaluated immediately."); + })); + }, + "add feature, force": function () { + var dfd = this.async(); + + moduleRequire(["has"], dfd.callback(function (has) { + has.add("config-feature", function () { + return false; + }, false, true); + has.add("config-feature", function () { + return true; + }, false); + + has.add("config-feature2", function () { + return true; + }, true, true); + has.add("config-feature2", function () { + return false; + }, true); + + assert.isFalse(has("config-feature"), "should be erased by false"); + assert.isTrue(has("config-feature2"), "should be erased by true"); + })); + } + }); + + registerSuite({ + name: "has - plugin", + setup: function () { + pluginRequire = require.config({ + context: "plugin", + baseUrl: "../../", + packages: [{ + name: "modules", + location: "tests/testModules/" + }], + config: { + has: { + "config-feature": true, + "config-feature2": false + } + } + }); + }, + "basic load": function () { + var dfd = this.async(); + + pluginRequire([ + "has!config-feature?modules/module1:modules/module2", + "has!config-feature2?modules/module1:modules/module2" + ], dfd.callback(function (module1, module2) { + assert.strictEqual(module1.msg, "module 1", + "config-feature is true so has should resolve to module1"); + assert.strictEqual(module2.msg, "module 2", + "config-feature2 is false so has should resolve to module2"); + })); + }, + "ternary variation": function () { + var dfd = this.async(); + + pluginRequire([ + "has!config-feature?modules/module1", + "has!config-feature?:modules/module2", + "has!config-feature2?modules/module1", + "has!config-feature2?:modules/module2" + ], dfd.callback(function (module1, undefined2, undefined1, module2) { + assert.strictEqual(module1.msg, "module 1", + "config-feature is true so has should resolve to module1"); + assert.strictEqual(module2.msg, "module 2", + "config-feature2 is false so has should resolve to module2"); + assert.isUndefined(undefined2); + assert.isUndefined(undefined1); + })); + }, + "chained ternary": function () { + var dfd = this.async(); + + pluginRequire([ + "has!config-feature?modules/module1:config-feature2?modules/module2:modules/module3", + "has!config-feature2?modules/module1:config-feature?modules/module2:modules/module3", + "has!config-feature2?modules/module1:config-feature2?modules/module2:modules/module3" + ], dfd.callback(function (module1, module2, module3) { + assert.strictEqual(module1.msg, "module 1"); + assert.strictEqual(module2.msg, "module 2"); + assert.strictEqual(module3.msg, "module 3"); + })); + }, + "undefined feature": function () { + var dfd = this.async(); + + pluginRequire([ + "has!undef-feature?modules/module1:modules/module2" + ], dfd.callback(function (module2) { + assert.strictEqual(module2.msg, "module 2"); + })); + }, + "normalization": function () { + var dfd = this.async(); + + pluginRequire([ + "has!config-feature?./tests/testModules/module1", + "has!config-feature?./tests/testModules/plugin!./resources!test" + ], dfd.callback(function (module1, plugin) { + assert.strictEqual(module1.msg, "module 1"); + assert.strictEqual(plugin.res, "./resources!test"); + })); + } + + }); +}); diff --git a/tests/i18n.js b/tests/i18n.js new file mode 100644 index 0000000..f035370 --- /dev/null +++ b/tests/i18n.js @@ -0,0 +1,333 @@ +/* global context:true, onlyLayer:true */ +define([ + "intern!object", + "intern/chai!assert" +], function (registerSuite, assert) { + var index = 0; + + function getNewContext() { + index++; + return "v" + index; + } + + function setupContext(options) { + context = getNewContext(); + require.config({ + context: context, + baseUrl: "../../", + packages: [{ + name: "myapp", + location: "tests/testApp/dist/myapp" + }], + config: { + i18n: { + layerOnly: options[0], + enhanceLayer: options[1], + languagePack: options[2] + } + }, + }); + } + + function execTest(locale, testFunc) { + var contextRequire = require.config({ + context: context, + locale: locale, + }); + + contextRequire(["myapp/test"], function (test) { + if (!onlyLayer) { + contextRequire(["i18n!myapp/nls/bundleC", "i18n!myapp/nls/bundleD"], function (bC, bD) { + test.bundleC = bC.MSG; + test.bundleD = bD.MSG; + testFunc(test); + }); + } else { + testFunc(test); + } + }); + } + + + registerSuite({ + name: "i18n - layerOnly - !enhanceLayer - languagePack", + setup: function () { + context = ""; + onlyLayer = true; + }, + beforeEach: function () { + setupContext([onlyLayer, false, true]); + }, + "fr": function () { + var dfd = this.async(); + var hint = "The text should come from the exact layer"; + + execTest("fr", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Fr from Layer Bundle A", hint); + assert.strictEqual(test.bundleB, "Fr from Layer Bundle B", hint); + })); + }, + "fr-fr": function () { + var dfd = this.async(); + var hint = "The text should come from the best layer (ie. fr)"; + + execTest("fr-fr", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Fr from Layer Bundle A", hint); + assert.strictEqual(test.bundleB, "Fr from Layer Bundle B", hint); + })); + }, + "en": function () { + var dfd = this.async(); + var hint = "The unknown layer en should be used"; + + execTest("en", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "En from Layer Bundle A", hint); + assert.strictEqual(test.bundleB, "En from Layer Bundle B", hint); + })); + }, + "it": function () { + var dfd = this.async(); + var hint = "The root layer should be used when a locale does not exist"; + + execTest("it", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Root Text from Layer Bundle A", hint); + assert.strictEqual(test.bundleB, "Root Text from Layer Bundle B", hint); + })); + } + }); + + registerSuite({ + name: "i18n - layerOnly - !enhanceLayer - !languagePack", + setup: function () { + context = ""; + onlyLayer = true; + }, + beforeEach: function () { + setupContext([onlyLayer, false, false]); + }, + "fr": function () { + var dfd = this.async(); + var hint = "The text should come from the exact layer"; + + execTest("fr", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Fr from Layer Bundle A", hint); + assert.strictEqual(test.bundleB, "Fr from Layer Bundle B", hint); + })); + }, + "fr-fr": function () { + var dfd = this.async(); + var hint = "The text should come from the best layer (ie. fr)"; + + execTest("fr-fr", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Fr from Layer Bundle A", hint); + assert.strictEqual(test.bundleB, "Fr from Layer Bundle B", hint); + })); + }, + "en": function () { + var dfd = this.async(); + var hint = "The en layer should not be discovered"; + + execTest("en", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Root Text from Layer Bundle A", hint); + assert.strictEqual(test.bundleB, "Root Text from Layer Bundle B", hint); + })); + }, + "it": function () { + var dfd = this.async(); + var hint = "The root layer should be used when a locale does not exist"; + + execTest("it", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Root Text from Layer Bundle A", hint); + assert.strictEqual(test.bundleB, "Root Text from Layer Bundle B", hint); + })); + } + }); + + registerSuite({ + name: "i18n - !layerOnly - !enhanceLayer - !languagePack", + setup: function () { + context = ""; + onlyLayer = false; + }, + beforeEach: function () { + setupContext([onlyLayer, false, false]); + }, + "fr": function () { + var dfd = this.async(); + var hintLayer = "The text should come from the exact layer"; + var hintBundle = "The best match should be found"; + + execTest("fr", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Fr from Layer Bundle A", hintLayer); + assert.strictEqual(test.bundleB, "Fr from Layer Bundle B", hintLayer); + assert.strictEqual(test.bundleC, "Fr from Bundle C", hintBundle); + assert.strictEqual(test.bundleD, "Fr from Bundle D", hintBundle); + })); + }, + "fr-fr": function () { + var dfd = this.async(); + var hintLayer = "The layer should not be enhanced"; + var hintBundle = "The best match should be found"; + + execTest("fr-fr", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Fr from Layer Bundle A", hintLayer); + assert.strictEqual(test.bundleB, "Fr from Layer Bundle B", hintLayer); + assert.strictEqual(test.bundleC, "Fr-fr from Bundle C", hintBundle); + assert.strictEqual(test.bundleD, "Fr from Bundle D", hintBundle); + })); + }, + "en": function () { + var dfd = this.async(); + var hintLayer = "The layer en should not be found"; + var hintBundle = "The best match should be found"; + + execTest("en", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Root Text from Layer Bundle A", hintLayer); + assert.strictEqual(test.bundleB, "Root Text from Layer Bundle B", hintLayer); + assert.strictEqual(test.bundleC, "Root Text from Bundle C", hintBundle); + assert.strictEqual(test.bundleD, "Root Text from Bundle D", hintBundle); + })); + } + }); + + registerSuite({ + name: "i18n - !layerOnly - enhanceLayer - !languagePack", + setup: function () { + context = ""; + onlyLayer = false; + }, + beforeEach: function () { + setupContext([onlyLayer, true, false]); + }, + "fr": function () { + var dfd = this.async(); + var hintLayer = "The text should come from the exact layer"; + var hintBundle = "The best match should be found"; + + execTest("fr", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Fr from Layer Bundle A", hintLayer); + assert.strictEqual(test.bundleB, "Fr from Layer Bundle B", hintLayer); + assert.strictEqual(test.bundleC, "Fr from Bundle C", hintBundle); + assert.strictEqual(test.bundleD, "Fr from Bundle D", hintBundle); + })); + }, + "fr-fr": function () { + var dfd = this.async(); + var hintLayer = "The layer should be enhanced"; + var hintBundle = "The best match should be found"; + + execTest("fr-fr", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Fr-fr from Bundle A", hintLayer); + assert.strictEqual(test.bundleB, "Fr from Layer Bundle B", hintLayer); + assert.strictEqual(test.bundleC, "Fr-fr from Bundle C", hintBundle); + assert.strictEqual(test.bundleD, "Fr from Bundle D", hintBundle); + })); + }, + "en": function () { + var dfd = this.async(); + var hintLayer = "The layer en should not be found"; + var hintBundle = "The best match should be found"; + + execTest("en", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Root Text from Layer Bundle A", hintLayer); + assert.strictEqual(test.bundleB, "Root Text from Layer Bundle B", hintLayer); + assert.strictEqual(test.bundleC, "Root Text from Bundle C", hintBundle); + assert.strictEqual(test.bundleD, "Root Text from Bundle D", hintBundle); + })); + } + }); + + registerSuite({ + name: "i18n - !layerOnly - !enhanceLayer - languagePack", + setup: function () { + context = ""; + onlyLayer = false; + }, + beforeEach: function () { + setupContext([onlyLayer, false, true]); + }, + "fr": function () { + var dfd = this.async(); + var hintLayer = "The text should come from the exact layer"; + var hintBundle = "The best match should be found"; + + execTest("fr", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Fr from Layer Bundle A", hintLayer); + assert.strictEqual(test.bundleB, "Fr from Layer Bundle B", hintLayer); + assert.strictEqual(test.bundleC, "Fr from Bundle C", hintBundle); + assert.strictEqual(test.bundleD, "Fr from Bundle D", hintBundle); + })); + }, + "fr-fr": function () { + var dfd = this.async(); + var hintLayer = "The layer should not be enhanced"; + var hintBundle = "The best match should be found"; + + execTest("fr-fr", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Fr from Layer Bundle A", hintLayer); + assert.strictEqual(test.bundleB, "Fr from Layer Bundle B", hintLayer); + assert.strictEqual(test.bundleC, "Fr-fr from Bundle C", hintBundle); + assert.strictEqual(test.bundleD, "Fr from Bundle D", hintBundle); + })); + }, + "en": function () { + var dfd = this.async(); + var hintLayer = "The layer en should be found"; + var hintBundle = "The best match should be found"; + + execTest("en", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "En from Layer Bundle A", hintLayer); + assert.strictEqual(test.bundleB, "En from Layer Bundle B", hintLayer); + assert.strictEqual(test.bundleC, "Root Text from Bundle C", hintBundle); + assert.strictEqual(test.bundleD, "Root Text from Bundle D", hintBundle); + })); + } + }); + + registerSuite({ + name: "i18n - !layerOnly - enhanceLayer - languagePack", + setup: function () { + context = ""; + onlyLayer = false; + }, + beforeEach: function () { + setupContext([onlyLayer, true, true]); + }, + "fr": function () { + var dfd = this.async(); + var hintLayer = "The text should come from the exact layer"; + var hintBundle = "The best match should be found"; + + execTest("fr", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Fr from Layer Bundle A", hintLayer); + assert.strictEqual(test.bundleB, "Fr from Layer Bundle B", hintLayer); + assert.strictEqual(test.bundleC, "Fr from Bundle C", hintBundle); + assert.strictEqual(test.bundleD, "Fr from Bundle D", hintBundle); + })); + }, + "fr-fr": function () { + var dfd = this.async(); + var hintLayer = "The layer should be enhanced"; + var hintBundle = "The best match should be found"; + + execTest("fr-fr", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "Fr-fr from Bundle A", hintLayer); + assert.strictEqual(test.bundleB, "Fr from Layer Bundle B", hintLayer); + assert.strictEqual(test.bundleC, "Fr-fr from Bundle C", hintBundle); + assert.strictEqual(test.bundleD, "Fr from Bundle D", hintBundle); + })); + }, + "en": function () { + var dfd = this.async(); + var hintLayer = "The layer en should be found"; + var hintBundle = "The best match should be found"; + + execTest("en", dfd.callback(function (test) { + assert.strictEqual(test.bundleA, "En from Layer Bundle A", hintLayer); + assert.strictEqual(test.bundleB, "En from Layer Bundle B", hintLayer); + assert.strictEqual(test.bundleC, "Root Text from Bundle C", hintBundle); + assert.strictEqual(test.bundleD, "Root Text from Bundle D", hintBundle); + })); + } + }); +}); diff --git a/tests/i18nBuilt.js b/tests/i18nBuilt.js deleted file mode 100644 index 54a2f6d..0000000 --- a/tests/i18nBuilt.js +++ /dev/null @@ -1,194 +0,0 @@ -define([ - 'intern!object', - 'intern/chai!assert', - 'require' -], function (registerSuite, assert, require) { - var testLayer = function (that, options, locale, layerResult, layerHint, bundleResult, bundleHint) { - return that.remote - .get(require.toUrl('./testBuilt.html?' + locale + '&' + options)) - // TODO waitForCondition - .wait(10000) - .elementById('layer') - .text() - .then(function (txt) { - assert.strictEqual(txt, layerResult, layerHint); - }) - .end() - .elementById('bundle') - .text() - .then(function (txt) { - assert.strictEqual(txt, bundleResult, bundleHint); - }) - .end(); - }; - - - registerSuite({ - name: 'i18n', - - // layerOnly - !enhanceLayer - languagePack - 'fr - layerOnly - !enhanceLayer - languagePack': function () { - return testLayer(this, 't&f&t', - 'fr', - 'Fr from Layer Bundle A Fr from Layer Bundle B', - 'The text should come from the exact layer', - ''); - }, - 'fr-fr - layerOnly - !enhanceLayer - languagePack': function () { - return testLayer(this, 't&f&t', - 'fr-fr', - 'Fr from Layer Bundle A Fr from Layer Bundle B', - 'The text should come from the best layer (ie. fr)', - ''); - }, - 'en - layerOnly - !enhanceLayer - languagePack': function () { - return testLayer(this, 't&f&t', - 'en', - 'En from Layer Bundle A En from Layer Bundle B', - 'The unknown layer en should be used', - ''); - }, - 'it - layerOnly - !enhanceLayer - languagePack': function () { - return testLayer(this, 't&f&t', - 'it', - 'Root Text from Layer Bundle A Root Text from Layer Bundle B', - 'The root layer should be used when a locale does not exist', - ''); - }, - - // layerOnly - !enhanceLayer - !languagePack - 'fr - layerOnly - !enhanceLayer - !languagePack': function () { - return testLayer(this, 't&f&f', - 'fr', - 'Fr from Layer Bundle A Fr from Layer Bundle B', - 'The text should come from the exact layer', - ''); - }, - 'fr-fr - layerOnly - !enhanceLayer - !languagePack': function () { - return testLayer(this, 't&f&f', - 'fr-fr', - 'Fr from Layer Bundle A Fr from Layer Bundle B', - 'The text should come from the best layer (ie. fr)', - ''); - }, - 'en - layerOnly - !enhanceLayer - !languagePack': function () { - return testLayer(this, 't&f&f', - 'en', - 'Root Text from Layer Bundle A Root Text from Layer Bundle B', - 'The en layer should not be discovered', - ''); - }, - 'it - layerOnly - !enhanceLayer - !languagePack': function () { - return testLayer(this, 't&f&f', - 'it', - 'Root Text from Layer Bundle A Root Text from Layer Bundle B', - 'The root layer should be used when a locale does not exist', - ''); - }, - - // !layerOnly - !enhanceLayer - !languagePack - 'fr - !layerOnly - !enhanceLayer - !languagePack': function () { - return testLayer(this, 'f&f&f', - 'fr', - 'Fr from Layer Bundle A Fr from Layer Bundle B', - 'The text should come from the exact layer', - 'Fr from Bundle C Fr from Bundle D', - 'The best match should be found'); - }, - 'fr-fr - !layerOnly - !enhanceLayer - !languagePack': function () { - return testLayer(this, 'f&f&f', - 'fr-fr', - 'Fr from Layer Bundle A Fr from Layer Bundle B', - 'The layer should not be enhanced', - 'Fr-fr from Bundle C Fr from Bundle D', - 'The best match should be found'); - }, - 'en - !layerOnly - !enhanceLayer - !languagePack': function () { - return testLayer(this, 'f&f&f', - 'en', - 'Root Text from Layer Bundle A Root Text from Layer Bundle B', - 'The layer en should not be found', - 'Root Text from Bundle C Root Text from Bundle D', - 'The best match should be found'); - }, - - // !layerOnly - enhanceLayer - !languagePack - 'fr - !layerOnly - enhanceLayer - !languagePack': function () { - return testLayer(this, 'f&t&f', - 'fr', - 'Fr from Layer Bundle A Fr from Layer Bundle B', - 'The text should come from the exact layer', - 'Fr from Bundle C Fr from Bundle D', - 'The best match should be found'); - }, - 'fr-fr - !layerOnly - enhanceLayer - !languagePack': function () { - return testLayer(this, 'f&t&f', - 'fr-fr', - 'Fr-fr from Bundle A Fr from Layer Bundle B', - 'The layer should be enhanced', - 'Fr-fr from Bundle C Fr from Bundle D', - 'The best match should be found'); - }, - 'en - !layerOnly - enhanceLayer - !languagePack': function () { - return testLayer(this, 'f&t&f', - 'en', - 'Root Text from Layer Bundle A Root Text from Layer Bundle B', - 'The layer en should not be found', - 'Root Text from Bundle C Root Text from Bundle D', - 'The best match should be found'); - }, - - // !layerOnly - !enhanceLayer - languagePack - 'fr - !layerOnly - !enhanceLayer - languagePack': function () { - return testLayer(this, 'f&f&t', - 'fr', - 'Fr from Layer Bundle A Fr from Layer Bundle B', - 'The text should come from the exact layer', - 'Fr from Bundle C Fr from Bundle D', - 'The best match should be found'); - }, - 'fr-fr - !layerOnly - !enhanceLayer - languagePack': function () { - return testLayer(this, 'f&f&t', - 'fr-fr', - 'Fr from Layer Bundle A Fr from Layer Bundle B', - 'The layer should not be enhanced', - 'Fr-fr from Bundle C Fr from Bundle D', - 'The best match should be found'); - }, - 'en - !layerOnly - !enhanceLayer - languagePack': function () { - return testLayer(this, 'f&f&t', - 'en', - 'En from Layer Bundle A En from Layer Bundle B', - 'The layer en should be found', - 'Root Text from Bundle C Root Text from Bundle D', - 'The best match should be found'); - }, - - // !layerOnly - enhanceLayer - languagePack - 'fr - !layerOnly - enhanceLayer - languagePack': function () { - return testLayer(this, 'f&t&t', - 'fr', - 'Fr from Layer Bundle A Fr from Layer Bundle B', - 'The text should come from the exact layer', - 'Fr from Bundle C Fr from Bundle D', - 'The best match should be found'); - }, - 'fr-fr - !layerOnly - enhanceLayer - languagePack': function () { - return testLayer(this, 'f&t&t', - 'fr-fr', - 'Fr-fr from Bundle A Fr from Layer Bundle B', - 'The layer should be enhanced', - 'Fr-fr from Bundle C Fr from Bundle D', - 'The best match should be found'); - }, - 'en - !layerOnly - enhanceLayer - languagePack': function () { - return testLayer(this, 'f&t&t', - 'en', - 'En from Layer Bundle A En from Layer Bundle B', - 'The layer en should not be found', - 'Root Text from Bundle C Root Text from Bundle D', - 'The best match should be found'); - }, - - }); -}); diff --git a/tests/intern.js b/tests/intern.js new file mode 100644 index 0000000..6f54c5e --- /dev/null +++ b/tests/intern.js @@ -0,0 +1,101 @@ +// run grunt --help for help on how to run +// Learn more about configuring this file at . +// These default settings work OK for most people. The options that *must* be changed below are the +// packages, suites, excludeInstrumentation, and (if you want functional tests) functionalSuites. +define({ + // The port on which the instrumenting proxy will listen + proxyPort: 9000, + + proxyUrl: "http://127.0.0.1:9000/", + + // Browsers to run integration testing against. Note that version numbers must be strings if used with Sauce + // OnDemand. Options that will be permutated are browserName, version, platform, and platformVersion; any other + // capabilities options specified for an environment will be copied as-is + environments: [ + // Desktop + { + browserName: "internet explorer", + version: "11", + platform: "Windows 8.1", + name: "requirejs-dplugins" + }, { + browserName: "internet explorer", + version: "10", + platform: "Windows 8", + name: "requirejs-dplugins" + }, { + browserName: "firefox", + version: "25", + platform: "Windows 7", + name: "requirejs-dplugins" + }, { + browserName: "chrome", + version: "33", + platform: "Windows 7", + name: "requirejs-dplugins" + }, { + browserName: "safari", + version: "7", + platform: "OS X 10.9", + name: "requirejs-dplugins" + }, + + // Mobile + /*{ + browserName: "android", + version: "4.3", + platform: "Linux", + name: "requirejs-dplugins" + }, { + browserName: "android", + version: "4.2", + platform: "Linux", + name: "requirejs-dplugins" + }, { + browserName: "iphone", + version: "7.0", + platform: "OS X 10.9", + name: "requirejs-dplugins" + }, { + browserName: "iphone", + version: "7.1", + platform: "OS X 10.9", + name: "requirejs-dplugins" + },*/ { + browserName: "ipad", + version: "7.0", + platform: "OS X 10.9", + name: "requirejs-dplugins" + }, { + browserName: "ipad", + version: "7.1", + platform: "OS X 10.9", + name: "requirejs-dplugins" + } + + ], + + // Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service + maxConcurrency: 3, + + // Whether or not to start Sauce Connect before running tests + useSauceConnect: true, + + // Connection information for the remote WebDriver service. If using Sauce Labs, keep your username and password + // in the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables unless you are sure you will NEVER be + // publishing this configuration file somewhere + webdriver: { + host: "localhost", + port: 4444 + }, + + useLoader: { + "host-browser": "../../node_modules/requirejs/require.js" + }, + + // Non-functional test suite(s) to run in each browser + suites: ["tests/has", "tests/i18n"], + + // A regular expression matching URLs to files that should not be included in code coverage analysis + excludeInstrumentation: /^(?:tests|node_modules)/ +}); diff --git a/tests/intern.local.js b/tests/intern.local.js new file mode 100644 index 0000000..dcd9b1d --- /dev/null +++ b/tests/intern.local.js @@ -0,0 +1,19 @@ +// run grunt --help for help on how to run +define([ + "./intern" +], function (intern) { + intern.useSauceConnect = false; + + intern.environments = [{ + browserName: "firefox" + }, { + browserName: "chrome" + }, { + browserName: "internet explorer", + requireWindowFocus: "true" + }]; + + intern.maxConcurrency = 1; + + return intern; +}); diff --git a/tests/local.js b/tests/local.js deleted file mode 100644 index 956dba7..0000000 --- a/tests/local.js +++ /dev/null @@ -1,47 +0,0 @@ -define({ - // The port on which the instrumenting proxy will listen - proxyPort: 9000, - - // A fully qualified URL to the Intern proxy - proxyUrl: 'http://localhost:9000/', - - // Default desired capabilities for all environments. Individual capabilities can be overridden by any of the - // specified browser environments in the `environments` array below as well. See - // https://code.google.com/p/selenium/wiki/DesiredCapabilities for standard Selenium capabilities and - // https://saucelabs.com/docs/additional-config#desired-capabilities for Sauce Labs capabilities. - // Note that the `build` capability will be filled in with the current commit ID from the Travis CI environment - // automatically - capabilities: { - 'selenium-version': '2.39.0', - 'idle-timeout': 30 - }, - - // Browsers to run integration testing against. Note that version numbers must be strings if used with Sauce - // OnDemand. Options that will be permutated are browserName, version, platform, and platformVersion; any other - // capabilities options specified for an environment will be copied as-is - environments: [{ - browserName: 'chrome' - }, { - browserName: 'firefox' - }], - - // Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service - maxConcurrency: 3, - - // Whether or not to start Sauce Connect before running tests - useSauceConnect: false, - - // Connection information for the remote WebDriver service. If using Sauce Labs, keep your username and password - // in the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables unless you are sure you will NEVER be - // publishing this configuration file somewhere - webdriver: { - host: 'localhost', - port: 4444 - }, - - // Functional test suite(s) to run in each browser once non-functional tests are completed - functionalSuites: ['tests/i18nBuilt'], - - // A regular expression matching URLs to files that should not be included in code coverage analysis - excludeInstrumentation: /^(?:tests|node_modules)/ -}); diff --git a/tests/sauce.js b/tests/sauce.js deleted file mode 100644 index 3eb4135..0000000 --- a/tests/sauce.js +++ /dev/null @@ -1,45 +0,0 @@ - -// Learn more about configuring this file at . -// These default settings work OK for most people. The options that *must* be changed below are the -// packages, suites, excludeInstrumentation, and (if you want functional tests) functionalSuites. -define({ - // The port on which the instrumenting proxy will listen - proxyPort: 9000, - - // A fully qualified URL to the Intern proxy - proxyUrl: "http://127.0.0.1:9000/", - - // Browsers to run integration testing against. Note that version numbers must be strings if used with Sauce - // OnDemand. Options that will be permutated are browserName, version, platform, and platformVersion; any other - // capabilities options specified for an environment will be copied as-is - environments: [ - { browserName: "internet explorer", version: "11", platform: "Windows 8.1", name : "requirejs-dplugins" }, - { browserName: "internet explorer", version: "10", platform: "Windows 8", name : "requirejs-dplugins" }, - { browserName: "firefox", version: "25", platform: "Windows 7", name : "requirejs-dplugins" }, - { browserName: "chrome", version: "33", platform: "Windows 7", name : "requirejs-dplugins" }, - { browserName: "safari", version: "7", platform: "OS X 10.9", name : "requirejs-dplugins" } - ], - - // Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service - maxConcurrency: 3, - - // Whether or not to start Sauce Connect before running tests - useSauceConnect: true, - - // Connection information for the remote WebDriver service. If using Sauce Labs, keep your username and password - // in the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables unless you are sure you will NEVER be - // publishing this configuration file somewhere - webdriver: { - host: "localhost", - port: 4444 - }, - - // Non-functional test suite(s) to run in each browser - //suites: [ 'tests/hello' ], - - // Functional test suite(s) to run in each browser once non-functional tests are completed - functionalSuites: ['tests/i18nBuilt'], - - // A regular expression matching URLs to files that should not be included in code coverage analysis - excludeInstrumentation: /^(?:tests|node_modules)/ -}); \ No newline at end of file diff --git a/tests/testApp/dist/myapp/test.js b/tests/testApp/dist/myapp/test.js index a1c103d..9d95041 100644 --- a/tests/testApp/dist/myapp/test.js +++ b/tests/testApp/dist/myapp/test.js @@ -1,4 +1,5 @@ require.config({ + context: context, config: { "i18n": { bundlesMap: { @@ -16,8 +17,7 @@ define("myapp/test", [ "i18n!myapp/nls/bundleB" ], function (bundleA, bundleB) { return { - log: function (element) { - element.innerHTML = bundleA.MSG + " " + bundleB.MSG; - } + bundleA: bundleA.MSG, + bundleB: bundleB.MSG }; }); diff --git a/tests/testBuilt.html b/tests/testBuilt.html deleted file mode 100644 index 171ee8b..0000000 --- a/tests/testBuilt.html +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - -

TEST FILE

-

-

- - diff --git a/tests/testModules/module1.js b/tests/testModules/module1.js new file mode 100644 index 0000000..25742ea --- /dev/null +++ b/tests/testModules/module1.js @@ -0,0 +1,3 @@ +define({ + msg: "module 1" +}); \ No newline at end of file diff --git a/tests/testModules/module2.js b/tests/testModules/module2.js new file mode 100644 index 0000000..1c80cad --- /dev/null +++ b/tests/testModules/module2.js @@ -0,0 +1,3 @@ +define({ + msg: "module 2" +}); \ No newline at end of file diff --git a/tests/testModules/module3.js b/tests/testModules/module3.js new file mode 100644 index 0000000..1597bcd --- /dev/null +++ b/tests/testModules/module3.js @@ -0,0 +1,3 @@ +define({ + msg: "module 3" +}); \ No newline at end of file diff --git a/tests/testModules/plugin.js b/tests/testModules/plugin.js new file mode 100644 index 0000000..3c26c80 --- /dev/null +++ b/tests/testModules/plugin.js @@ -0,0 +1,7 @@ +define({ + load: function (resource, req, onLoad) { + onLoad({ + res: resource + }); + } +}); \ No newline at end of file