Skip to content

Commit a20543b

Browse files
author
Chuck Dumont
authored
Merge pull request #63 from chuckdumont/work
i18n unit tests
2 parents e8ad028 + 07a950e commit a20543b

File tree

15 files changed

+104
-4
lines changed

15 files changed

+104
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = [
2+
[/define dependencies not supported in langauge files/]
3+
];
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
define(["dojo/i18n!./nls/strings"], function(strings) {
2+
strings;
3+
throw new Error("Should not get here");
4+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
define(["dep"], function() {
2+
return {
3+
root: ({
4+
hello: 'Hello'
5+
})
6+
};
7+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var path = require("path");
2+
var DojoWebpackPlugin = require("../../../../index");
3+
module.exports = {
4+
entry: "test/index",
5+
plugins: [
6+
new DojoWebpackPlugin({
7+
loaderConfig: {
8+
paths:{test: "."}
9+
},
10+
loader: path.join(__dirname, "../../../js/dojo/dojo.js")
11+
})
12+
]
13+
};

test/TestCases/loaders/i18n/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
define(["dojo/_base/config", "dojo/i18n!./nls/strings1", "dojo/i18n!./nls/strings2"], function(config, strings1, strings2) {
2+
const lang = config.locale ? config.locale : "default";
3+
it(`should load strings for ${lang} language`, function() {
4+
strings1.hello.should.be.eql(lang === "fr" ? "Bonjoure" : lang === "es" ? "Hola" : "Hello");
5+
strings2.goodby.should.be.eql(lang === "fr" ? "Bon par" : lang === "de" ? "Auf Wiedersehen" : "Good by");
6+
it("should load locale specific strings", function(done) {
7+
// load a locale specific bundle
8+
require(["dojo/i18n!./nls/fr/strings1"], function(strings) {
9+
strings.hello.should.be.eql("Bonjoure");
10+
done();
11+
});
12+
});
13+
});
14+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define({
2+
hello: 'Hallo'
3+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define({
2+
goodby: 'Auf Wiedersehen'
3+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define({
2+
hello: 'Hola'
3+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define({
2+
goodby: 'Bueno por'
3+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define({
2+
hello: 'Bonjoure'
3+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define({
2+
goodby: 'Bon par'
3+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
define({
2+
root: ({
3+
hello: 'Hello'
4+
}),
5+
"fr":true,
6+
"es":true,
7+
"de":false
8+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
define([], function() {
2+
return {
3+
root: ({
4+
goodby: 'Good by'
5+
}),
6+
"fr":true,
7+
"es":false,
8+
"de":true
9+
};
10+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var path = require("path");
2+
var DojoWebpackPlugin = require("../../../../index");
3+
4+
module.exports = [undefined, "fr", "es", "de"].map(locale => {
5+
return {
6+
entry: "test/index",
7+
plugins: [
8+
new DojoWebpackPlugin({
9+
loaderConfig: {
10+
paths:{test: "."},
11+
has: {"host-browser": 0, "dojo-config-api": 1}
12+
},
13+
locales: ["fr", "es", "de"],
14+
loader: path.join(__dirname, "../../../js/dojo/dojo.js"),
15+
locale: locale
16+
})
17+
]
18+
};
19+
});

test/test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ describe("TestCases", () => {
3535
});
3636

3737
describe("ErrorTestCases", () => {
38-
runTestCases(path.join(__dirname, "ErrorTestCases"), true);
38+
runTestCases(path.join(__dirname, "ErrorTestCases"));
3939
});
4040

41-
function runTestCases(casesPath, isErrorTest) {
41+
function runTestCases(casesPath) {
4242
var categories = fs.readdirSync(casesPath);
4343
categories = categories.map(function(cat) {
4444
return {
@@ -52,9 +52,12 @@ function runTestCases(casesPath, isErrorTest) {
5252
describe(category.name, function() {
5353
category.tests.forEach(function(testName) {
5454
var suite = describe(testName, function() {});
55-
it(testName + isErrorTest ? " should fail" : " should compile", function(done) {
55+
var testDirectory = path.join(casesPath, category.name, testName);
56+
const isErrorTest = fs.existsSync(path.join(testDirectory, "expectedError.js"));
57+
const isCompilerErrors = fs.existsSync(path.join(testDirectory, "errors.js"));
58+
const isCompilerWarnings = fs.existsSync(path.join(testDirectory, "warnings.js"));
59+
it(testName + (isErrorTest ? " should fail" : " should compile") + (isCompilerErrors ? " with errors" : isCompilerWarnings ? " with warnings" : ""), function(done) {
5660
this.timeout(60000);
57-
var testDirectory = path.join(casesPath, category.name, testName);
5861
var outputDirectory = path.join(__dirname, "js", "TestCases", category.name, testName);
5962
var options = require(path.join(testDirectory, "webpack.config.js"));
6063
var optionsArr = [].concat(options);
@@ -183,6 +186,7 @@ function checkArrayExpectation(testDirectory, object, kind, filename, upperCaseK
183186
} else if(!expected[i].test(array[i]))
184187
return done(new Error(`${upperCaseKind} ${i}: ${array[i]} doesn't match ${expected[i].toString()}`)), true;
185188
}
189+
return done(), true;
186190
} else if(array.length > 0) {
187191
return done(new Error(`${upperCaseKind}s while compiling:\n\n${array.join("\n\n")}`)), true;
188192
}

0 commit comments

Comments
 (0)