Skip to content

Commit

Permalink
update i18n tests to units and add has tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clmath committed Jun 16, 2014
1 parent e14f5d0 commit 607cb6e
Show file tree
Hide file tree
Showing 18 changed files with 669 additions and 362 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
17 changes: 7 additions & 10 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = function (grunt) {
var filesList = [
"*.js",
"*.json",
"i18n/*.js"
"i18n/*.js",
"tests/*.js"
];


Expand Down Expand Up @@ -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']
}
}
Expand All @@ -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"]);

};
2 changes: 1 addition & 1 deletion has.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("!");
}
}
Expand Down
2 changes: 1 addition & 1 deletion i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ define(["./i18n/common", "./i18n/build", "module"], function (common, build, mod
onLoad();
return;
}

config = config || {};

var moduleConfig = {},
Expand Down
14 changes: 7 additions & 7 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,25 +13,25 @@ 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):

```
$ 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
```
180 changes: 180 additions & 0 deletions tests/has.js
Original file line number Diff line number Diff line change
@@ -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");
}));
}

});
});
Loading

0 comments on commit 607cb6e

Please sign in to comment.