Skip to content

Commit

Permalink
Merge pull request #739 from stealjs/condition-eval
Browse files Browse the repository at this point in the history
Test conditionals using browser specific code
  • Loading branch information
Manuel Mujica committed Jun 12, 2017
2 parents 910fdcb + c2fb57e commit 95e4699
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -54,7 +54,7 @@
"mockery": "^2.0.0",
"rimraf": "^2.5.2",
"serve-static": "^1.11.2",
"steal-conditional": "^0.3.4",
"steal-conditional": "^0.3.5",
"steal-qunit": "^1.0.0",
"testee": "^0.4.0",
"tree-kill": "^1.0.0",
Expand Down
23 changes: 22 additions & 1 deletion test/build_conditionals_test.js
Expand Up @@ -172,6 +172,26 @@ describe("build app using steal-conditional", function() {
});
});

it("condition module should not be evaluated during build", function() {
this.timeout(20000);

var bundles = path.join(basePath, "condition-module", "dist", "bundles");

var config = {
config: path.join(basePath, "condition-module", "package.json!npm")
};

return prmdir(path.join(basePath, "boolean", "dist"))
.then(function() {
return multiBuild(config, { minify: false, quiet: true });
})
.then(function() {
// each module that might be conditionally loaded once the
// built app is run on the browser gets its own module
return exists(path.join(bundles, "foo.js"));
});
});

function copyDependencies() {
var copy = denodeify(fs.copy);
var src = path.join(__dirname, "..", "node_modules");
Expand All @@ -181,7 +201,8 @@ describe("build app using steal-conditional", function() {
path.join(basePath, "substitution"),
path.join(basePath, "substitution-ext"),
path.join(basePath, "substitution-tilde"),
path.join(basePath, "substitution-folders")
path.join(basePath, "substitution-folders"),
path.join(basePath, "condition-module")
];

var promises = folders.map(function(dest) {
Expand Down
1 change: 1 addition & 0 deletions test/conditionals/condition-module/cond.js
@@ -0,0 +1 @@
module.exports = document.querySelectorAll("#app").length;
1 change: 1 addition & 0 deletions test/conditionals/condition-module/foo.js
@@ -0,0 +1 @@
export const variable = window.variable = "foo";
14 changes: 14 additions & 0 deletions test/conditionals/condition-module/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-main="conditionals/main"
data-env="production"
data-config="package.json!npm"
src="../../../node_modules/steal/steal.js">
</script>
</body>
</html>
1 change: 1 addition & 0 deletions test/conditionals/condition-module/main.js
@@ -0,0 +1 @@
require("foo#?cond");
19 changes: 19 additions & 0 deletions test/conditionals/condition-module/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.4"
},
"system": {
"configDependencies": [
"./node_modules/steal-conditional/conditional"
]
},
"author": "",
"license": "ISC"
}

0 comments on commit 95e4699

Please sign in to comment.