Skip to content

Commit

Permalink
Add failing test for conditional build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Mujica committed Jan 16, 2017
1 parent cb7e471 commit 3221700
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -48,7 +48,7 @@
"mock-fs": "^3.12.1",
"mockery": "^1.4.1",
"rimraf": "^2.5.2",
"steal-conditional": "^0.2.0",
"steal-conditional": "^0.3.1",
"steal-css": "^1.0.0",
"steal-qunit": "^1.0.0",
"testee": "^0.2.0",
Expand Down
48 changes: 48 additions & 0 deletions test/build_conditionals_test.js
Expand Up @@ -15,6 +15,7 @@ describe("build app using steal-conditional", function() {
var basePath = path.join(__dirname, "conditionals");
var booleanPath = path.join(basePath, "boolean", "node_modules");
var substitutionPath = path.join(basePath, "substitution", "node_modules");
var substitutionTildePath = path.join(basePath, "substitution-tilde", "node_modules");

before(function() {
return copyDependencies();
Expand Down Expand Up @@ -91,6 +92,47 @@ describe("build app using steal-conditional", function() {
.catch(done);
});

it("substitution using `~` lookup scheme works", function(done) {
var config = {
config: path.join(basePath, "substitution-tilde", "package.json!npm")
};

prmdir(path.join(basePath, "substitution-tilde", "dist"))
.then(function() {
return multiBuild(config, { minify: false, quiet: true });
})
.then(function() {
var bundles = path.join(
basePath, "substitution-tilde", "dist", "bundles", "conditionals"
);

// creates bundles for each possible string substitution
assert.ok(
fs.existsSync(path.join(bundles, "message", "en.js")),
"should create bundle for `en` variation"
);
assert.ok(
fs.existsSync(path.join(bundles, "message", "es.js")),
"should create bundle for `es` variation"
);
})
.then(function() {
var page = path.join(
"test", "conditionals", "substitution-tilde", "index.html"
);

open(page, function(browser, close) {
find(browser, "translations", function(translations) {
assert.equal(translations.es, "hola, mundo!");
assert.ok(!translations.en,
"only the `es` translation should be loaded");
close();
}, close);
}, done);
})
.catch(done);
});

function copyDependencies() {
var prmdir = denodeify(rmdir);
var pcopy = denodeify(fs.copy);
Expand All @@ -112,6 +154,12 @@ describe("build app using steal-conditional", function() {
path.join(srcModulesPath, "steal-conditional"),
path.join(substitutionPath, "steal-conditional")
);
})
.then(function() {
return pcopy(
path.join(srcModulesPath, "steal-conditional"),
path.join(substitutionTildePath, "steal-conditional")
);
});
}
});
14 changes: 14 additions & 0 deletions test/conditionals/substitution-tilde/index.html
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>conditional modules build</title>
</head>
<body>
<script data-env="production"
data-main="conditionals/main"
data-config="package.json!npm"
src="../../../node_modules/steal/steal.js">
</script>
</body>
</html>
1 change: 1 addition & 0 deletions test/conditionals/substitution-tilde/lang.js
@@ -0,0 +1 @@
export default "es";
1 change: 1 addition & 0 deletions test/conditionals/substitution-tilde/main.js
@@ -0,0 +1 @@
import i18n from "~/message/#{lang}";
2 changes: 2 additions & 0 deletions test/conditionals/substitution-tilde/message/en.js
@@ -0,0 +1,2 @@
window.translations = window.translations || {};
window.translations.en = "hello, world!";
2 changes: 2 additions & 0 deletions test/conditionals/substitution-tilde/message/es.js
@@ -0,0 +1,2 @@
window.translations = window.translations || {};
window.translations.es = "hola, mundo!";
19 changes: 19 additions & 0 deletions test/conditionals/substitution-tilde/package.json
@@ -0,0 +1,19 @@
{
"name": "conditionals",
"version": "0.0.1",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"steal-conditional": "^0.3.0"
},
"system": {
"configDependencies": [
"./node_modules/steal-conditional/conditional"
]
},
"author": "",
"license": "ISC"
}
3 changes: 1 addition & 2 deletions test/conditionals/substitution/lang.js
@@ -1,5 +1,4 @@
module.exports = {
en: "en",
es: "es",
cases: ["en", "es"]
es: "es"
};
2 changes: 1 addition & 1 deletion test/conditionals/substitution/package.json
Expand Up @@ -7,7 +7,7 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"steal-conditional": "^0.2.0"
"steal-conditional": "^0.3.0"
},
"system": {
"configDependencies": [
Expand Down

0 comments on commit 3221700

Please sign in to comment.