Skip to content

Commit 607cb6e

Browse files
committed
update i18n tests to units and add has tests
1 parent e14f5d0 commit 607cb6e

File tree

18 files changed

+669
-362
lines changed

18 files changed

+669
-362
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ node_js: '0.10'
33
before_script:
44
- npm install -g grunt-cli
55
script:
6-
- grunt jshint
7-
- grunt intern:sauce
6+
- grunt travis
87
env:
98
global:
109
- secure: W5vbUYV3APtbtMw+dcogNIAB+G90nO9XTjYRBCkBMmRWOBAWan2BG3/9azENq6RHa8+J9fxd2VK/kcUz9sHTCezY1SfsUHmEKBR9/RiqFHi3HpucaLpqncGURvvAbwKCXmVnCbmEVBY6GCgQn2R/7bHEjp/gdFy7Q3oojnOtB4Q=

Gruntfile.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module.exports = function (grunt) {
44
var filesList = [
55
"*.js",
66
"*.json",
7-
"i18n/*.js"
7+
"i18n/*.js",
8+
"tests/*.js"
89
];
910

1011

@@ -48,17 +49,10 @@ module.exports = function (grunt) {
4849
reporters: ["console"]
4950
}
5051
},
51-
sauce: {
52-
options: {
53-
runType: 'runner', // defaults to 'client'
54-
config: 'tests/sauce',
55-
reporters: ['console']
56-
}
57-
},
5852
local: {
5953
options: {
6054
runType: 'runner', // defaults to 'client'
61-
config: 'tests/local',
55+
config: 'tests/intern.local',
6256
reporters: ['console', 'lcov']
6357
}
6458
}
@@ -73,9 +67,12 @@ module.exports = function (grunt) {
7367

7468

7569
// By default, lint and run all tests.
76-
grunt.registerTask("default", ["jsbeautifier", "lineending", "jshint", "intern:local"]);
70+
grunt.registerTask("default", ["jsbeautifier", "lineending", "jshint", "intern:remote"]);
7771

7872
// Just lint
7973
grunt.registerTask("lint", ["jsbeautifier", "lineending", "jshint"]);
8074

75+
// Travis build
76+
grunt.registerTask("travis", ["jshint", "intern:remote"]);
77+
8178
};

has.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ define(["module"], function (module) {
5353
if (tokens[i] !== ":" && tokens[i] !== "?" && tokens[i + 1] !== "?") {
5454
// The module could be another plugin
5555
var parts = tokens[i].split("!");
56-
parts = parts.map(normalize);
56+
parts[0] = normalize(parts[0]);
5757
tokens[i] = parts.join("!");
5858
}
5959
}

i18n.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ define(["./i18n/common", "./i18n/build", "module"], function (common, build, mod
129129
onLoad();
130130
return;
131131
}
132-
132+
133133
config = config || {};
134134

135135
var moduleConfig = {},

tests/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# i18n Plugin Tests
2-
This directory contains the i18n plugin tests.
1+
# Plugins Tests
2+
This directory contains the plugins tests.
33

44
## Setup
55
Before starting, install Intern and RequireJS by running
@@ -13,25 +13,25 @@ setup your SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables as they are
1313
on https://saucelabs.com/appium/tutorial/3.
1414

1515

16-
## Running the functional tests in Sauce Labs
16+
## Running the units tests in Sauce Labs
1717

1818
Run:
1919

2020
```
21-
$ node node_modules/intern/runner.js config=tests/sauce
21+
$ node node_modules/intern/runner.js config=tests/intern
2222
```
23-
## Running the functional tests locally
23+
## Running the unit tests locally
2424

2525
1) Download selenium server 2.37.0 (http://www.seleniumhq.org/download/) and start it on the default port (4444):
2626

2727
```
2828
$ java -jar selenium-server-standalone-2.37.0.jar
2929
```
3030

31-
2) Edit local.js to list which browsers to test
31+
2) Edit [intern.local.js](./intern.local.js) to list which browsers to test
3232

3333
3) Run the tests:
3434

3535
```
36-
$ node node_modules/intern/runner.js config=tests/locale
36+
$ node node_modules/intern/runner.js config=tests/intern.local
3737
```

tests/has.js

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/* global moduleRequire:true, pluginRequire:true, testGlobal:true */
2+
define([
3+
"intern!object",
4+
"intern/chai!assert"
5+
], function (registerSuite, assert) {
6+
7+
registerSuite({
8+
name: "has - module",
9+
setup: function () {
10+
moduleRequire = require.config({
11+
context: "module",
12+
baseUrl: "../../",
13+
config: {
14+
has: {
15+
"config-feature": true,
16+
"config-feature2": false
17+
}
18+
}
19+
});
20+
},
21+
beforeEach: function () {},
22+
"Cache setup from config": function () {
23+
var dfd = this.async();
24+
25+
moduleRequire(["has"], dfd.callback(function (has) {
26+
assert.isTrue(has.cache["config-feature"], "import feature from config");
27+
assert.isFalse(has.cache["config-feature2"], "import feature from config");
28+
assert.isUndefined(has.cache["undefined feature"], "import feature from config");
29+
}));
30+
},
31+
"has function": function () {
32+
var dfd = this.async();
33+
34+
moduleRequire(["has"], dfd.callback(function (has) {
35+
assert.isTrue(has("config-feature"), "import feature from config");
36+
assert.isFalse(has("config-feature2"), "import feature from config");
37+
assert.isUndefined(has("undefined feature"), "import feature from config");
38+
}));
39+
},
40+
"add feature": function () {
41+
var dfd = this.async();
42+
43+
moduleRequire(["has"], dfd.callback(function (has) {
44+
has.add("add-feature", function () {
45+
return true;
46+
});
47+
has.add("add-feature2", function () {
48+
return false;
49+
});
50+
assert.isTrue(has("add-feature"), "added a true feature.");
51+
assert.isFalse(has("add-feature2"), "added a false feature");
52+
}));
53+
},
54+
"add feature, lazy evaluation": function () {
55+
var dfd = this.async();
56+
57+
moduleRequire(["has"], dfd.callback(function (has) {
58+
testGlobal = false;
59+
has.add("lazy-feature", function (global) {
60+
return global.testGlobal;
61+
});
62+
has.add("lazy-feature2", function (global) {
63+
return global.testGlobal;
64+
}, true);
65+
testGlobal = true;
66+
67+
assert.isTrue(has("lazy-feature"),
68+
"should be true as the test function should be lazily evaluated.");
69+
assert.isFalse(has("lazy-feature2"),
70+
"should be false as the test function should be evaluated immediately.");
71+
}));
72+
},
73+
"add feature, force": function () {
74+
var dfd = this.async();
75+
76+
moduleRequire(["has"], dfd.callback(function (has) {
77+
has.add("config-feature", function () {
78+
return false;
79+
}, false, true);
80+
has.add("config-feature", function () {
81+
return true;
82+
}, false);
83+
84+
has.add("config-feature2", function () {
85+
return true;
86+
}, true, true);
87+
has.add("config-feature2", function () {
88+
return false;
89+
}, true);
90+
91+
assert.isFalse(has("config-feature"), "should be erased by false");
92+
assert.isTrue(has("config-feature2"), "should be erased by true");
93+
}));
94+
}
95+
});
96+
97+
registerSuite({
98+
name: "has - plugin",
99+
setup: function () {
100+
pluginRequire = require.config({
101+
context: "plugin",
102+
baseUrl: "../../",
103+
packages: [{
104+
name: "modules",
105+
location: "tests/testModules/"
106+
}],
107+
config: {
108+
has: {
109+
"config-feature": true,
110+
"config-feature2": false
111+
}
112+
}
113+
});
114+
},
115+
"basic load": function () {
116+
var dfd = this.async();
117+
118+
pluginRequire([
119+
"has!config-feature?modules/module1:modules/module2",
120+
"has!config-feature2?modules/module1:modules/module2"
121+
], dfd.callback(function (module1, module2) {
122+
assert.strictEqual(module1.msg, "module 1",
123+
"config-feature is true so has should resolve to module1");
124+
assert.strictEqual(module2.msg, "module 2",
125+
"config-feature2 is false so has should resolve to module2");
126+
}));
127+
},
128+
"ternary variation": function () {
129+
var dfd = this.async();
130+
131+
pluginRequire([
132+
"has!config-feature?modules/module1",
133+
"has!config-feature?:modules/module2",
134+
"has!config-feature2?modules/module1",
135+
"has!config-feature2?:modules/module2"
136+
], dfd.callback(function (module1, undefined2, undefined1, module2) {
137+
assert.strictEqual(module1.msg, "module 1",
138+
"config-feature is true so has should resolve to module1");
139+
assert.strictEqual(module2.msg, "module 2",
140+
"config-feature2 is false so has should resolve to module2");
141+
assert.isUndefined(undefined2);
142+
assert.isUndefined(undefined1);
143+
}));
144+
},
145+
"chained ternary": function () {
146+
var dfd = this.async();
147+
148+
pluginRequire([
149+
"has!config-feature?modules/module1:config-feature2?modules/module2:modules/module3",
150+
"has!config-feature2?modules/module1:config-feature?modules/module2:modules/module3",
151+
"has!config-feature2?modules/module1:config-feature2?modules/module2:modules/module3"
152+
], dfd.callback(function (module1, module2, module3) {
153+
assert.strictEqual(module1.msg, "module 1");
154+
assert.strictEqual(module2.msg, "module 2");
155+
assert.strictEqual(module3.msg, "module 3");
156+
}));
157+
},
158+
"undefined feature": function () {
159+
var dfd = this.async();
160+
161+
pluginRequire([
162+
"has!undef-feature?modules/module1:modules/module2"
163+
], dfd.callback(function (module2) {
164+
assert.strictEqual(module2.msg, "module 2");
165+
}));
166+
},
167+
"normalization": function () {
168+
var dfd = this.async();
169+
170+
pluginRequire([
171+
"has!config-feature?./tests/testModules/module1",
172+
"has!config-feature?./tests/testModules/plugin!./resources!test"
173+
], dfd.callback(function (module1, plugin) {
174+
assert.strictEqual(module1.msg, "module 1");
175+
assert.strictEqual(plugin.res, "./resources!test");
176+
}));
177+
}
178+
179+
});
180+
});

0 commit comments

Comments
 (0)