diff --git a/package.json b/package.json index 87a04cb5..3ab67e69 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "mockery": "^2.0.0", "rimraf": "^2.5.2", "serve-static": "^1.11.2", - "steal-conditional": "^0.3.2", + "steal-conditional": "^0.3.4", "steal-qunit": "^1.0.0", "testee": "^0.4.0", "tree-kill": "^1.0.0", diff --git a/test/build_conditionals_test.js b/test/build_conditionals_test.js index 48d1eda7..7c3cecea 100644 --- a/test/build_conditionals_test.js +++ b/test/build_conditionals_test.js @@ -13,15 +13,14 @@ describe("build app using steal-conditional", function() { var open = testHelpers.open; var prmdir = denodeify(rmdir); 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(); }); it("simple substitution works", function(done) { + var bundles = path.join(basePath, "substitution", "dist", "bundles"); + var config = { config: path.join(basePath, "substitution", "package.json!npm") }; @@ -31,14 +30,12 @@ describe("build app using steal-conditional", function() { return multiBuild(config, { minify: false, quiet: true }); }) .then(function() { - var bundles = path.join( - basePath, "substitution", "dist", "bundles" - ); - // creates bundles for each possible string substitution - // exposed through the "cases" property in the condition module - assert.ok(fs.existsSync(path.join(bundles, "message", "en.js"))); - assert.ok(fs.existsSync(path.join(bundles, "message", "es.js"))); + return exists(path.join(bundles, "message", "en.js")); + }) + .then(function() { + // creates bundles for each possible string substitution + return exists(path.join(bundles, "message", "es.js")); }) .then(function() { var page = path.join( @@ -58,24 +55,23 @@ describe("build app using steal-conditional", function() { it("simple boolean conditional works", function(done) { this.timeout(20000); + var bundles = path.join(basePath, "boolean", "dist", "bundles"); - var options = { + var config = { config: path.join(basePath, "boolean", "package.json!npm") }; prmdir(path.join(basePath, "boolean", "dist")) .then(function() { - return multiBuild(options, { minify: false, quiet: true }); + return multiBuild(config, { minify: false, quiet: true }); }) .then(function() { - var bundles = path.join( - basePath, "boolean", "dist", "bundles" - ); - // each module that might be conditionally loaded once the // built app is run on the browser gets its own module - assert.ok(fs.existsSync(path.join(bundles, "foo.js"))); - assert.ok(fs.existsSync(path.join(bundles, "bar.js"))); + return exists(path.join(bundles, "foo.js")); + }) + .then(function() { + return exists(path.join(bundles, "bar.js")); }) .then(function() { var page = path.join( @@ -97,24 +93,21 @@ describe("build app using steal-conditional", function() { config: path.join(basePath, "substitution-tilde", "package.json!npm") }; + var bundles = path.join( + basePath, "substitution-tilde", "dist", "bundles", "conditionals" + ); + 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" - ); + // should create bundle for `en` variation + return exists(path.join(bundles, "message", "en.js")); + }) + .then(function() { + // should create bundle for `es` variation + return exists(path.join(bundles, "message", "es.js")); }) .then(function() { var page = path.join( @@ -133,33 +126,80 @@ describe("build app using steal-conditional", function() { .catch(done); }); - function copyDependencies() { - var prmdir = denodeify(rmdir); - var pcopy = denodeify(fs.copy); - - var srcModulesPath = path.join(__dirname, "..", "node_modules"); + it("substitution and steal plugins (less, stache, etc...)", function() { + var base = path.join(basePath, "substitution-ext"); + var bundle = path.join(base, "dist", "bundles", "conditionals"); - return prmdir(booleanPath) + return prmdir(path.join(base, "dist")) .then(function() { - return prmdir(substitutionPath); + return multiBuild({ + config: path.join(base, "package.json!npm") + }, { + quiet: true, + minify: false + }); }) .then(function() { - return pcopy( - path.join(srcModulesPath, "steal-conditional"), - path.join(booleanPath, "steal-conditional") - ); + // make sure each variation is detected + return exists(path.join(bundle, "blue.css")); }) .then(function() { - return pcopy( - path.join(srcModulesPath, "steal-conditional"), - path.join(substitutionPath, "steal-conditional") - ); + // make sure each variation is detected + return exists(path.join(bundle, "red.css")); + }); + }); + + it("substitution and subfolders", function() { + var base = path.join(basePath, "substitution-folders"); + var bundle = path.join(base, "dist", "bundles", "conditionals"); + + return prmdir(path.join(base, "dist")) + .then(function() { + return multiBuild({ + config: path.join(base, "package.json!npm") + }, { + quiet: true, + minify: false + }); }) .then(function() { - return pcopy( - path.join(srcModulesPath, "steal-conditional"), - path.join(substitutionTildePath, "steal-conditional") - ); + // make sure each variation is detected + return exists(path.join(bundle, "en", "message.js")); + }) + .then(function() { + // make sure each variation is detected + return exists(path.join(bundle, "es", "message.js")); }); + }); + + function copyDependencies() { + var copy = denodeify(fs.copy); + var src = path.join(__dirname, "..", "node_modules"); + + var folders = [ + path.join(basePath, "boolean"), + path.join(basePath, "substitution"), + path.join(basePath, "substitution-ext"), + path.join(basePath, "substitution-tilde"), + path.join(basePath, "substitution-folders") + ]; + + var promises = folders.map(function(dest) { + return copy( + path.join(src, "steal-conditional"), + path.join(dest, "node_modules", "steal-conditional") + ); + }); + + return Promise.all(promises); + } + + /** + * Check if the file path exists + * @param {string} path The file path + * @return {Promise} Resolves if the file exists, rejects otherwise. + */ + function exists(path) { + return denodeify(fs.access)(path, fs.F_OK); } }); diff --git a/test/conditionals/substitution-ext/blue.css b/test/conditionals/substitution-ext/blue.css new file mode 100644 index 00000000..f1a1f57b --- /dev/null +++ b/test/conditionals/substitution-ext/blue.css @@ -0,0 +1 @@ +body { background-color: blue; } diff --git a/test/conditionals/substitution-ext/folder/color.js b/test/conditionals/substitution-ext/folder/color.js new file mode 100644 index 00000000..e69de29b diff --git a/test/conditionals/substitution-ext/index.html b/test/conditionals/substitution-ext/index.html new file mode 100644 index 00000000..e69de29b diff --git a/test/conditionals/substitution-ext/main.js b/test/conditionals/substitution-ext/main.js new file mode 100644 index 00000000..a5e8a4b9 --- /dev/null +++ b/test/conditionals/substitution-ext/main.js @@ -0,0 +1,2 @@ +require("./#{folder/color}.css!"); + diff --git a/test/conditionals/substitution-ext/package.json b/test/conditionals/substitution-ext/package.json new file mode 100644 index 00000000..7eeb8312 --- /dev/null +++ b/test/conditionals/substitution-ext/package.json @@ -0,0 +1,21 @@ +{ + "name": "conditionals", + "version": "0.0.1", + "description": "", + "main": "main.js", + "scripts": { + }, + "dependencies": { + "steal-conditional": "^0.3.0" + }, + "steal": { + "paths": { + "css": "../../steal-css.js" + }, + "configDependencies": [ + "./node_modules/steal-conditional/conditional" + ] + }, + "author": "Bitovi", + "license": "MIT" +} diff --git a/test/conditionals/substitution-ext/red.css b/test/conditionals/substitution-ext/red.css new file mode 100644 index 00000000..74e5c3fa --- /dev/null +++ b/test/conditionals/substitution-ext/red.css @@ -0,0 +1 @@ +body { background-color: red; } diff --git a/test/conditionals/substitution-folders/en/message.js b/test/conditionals/substitution-folders/en/message.js new file mode 100644 index 00000000..7f2b398f --- /dev/null +++ b/test/conditionals/substitution-folders/en/message.js @@ -0,0 +1 @@ +module.exports = "hola, mundo!"; diff --git a/test/conditionals/substitution-folders/es/message.js b/test/conditionals/substitution-folders/es/message.js new file mode 100644 index 00000000..7f2b398f --- /dev/null +++ b/test/conditionals/substitution-folders/es/message.js @@ -0,0 +1 @@ +module.exports = "hola, mundo!"; diff --git a/test/conditionals/substitution-folders/lang.js b/test/conditionals/substitution-folders/lang.js new file mode 100644 index 00000000..a4732a12 --- /dev/null +++ b/test/conditionals/substitution-folders/lang.js @@ -0,0 +1 @@ +module.exports = "es"; diff --git a/test/conditionals/substitution-folders/main.js b/test/conditionals/substitution-folders/main.js new file mode 100644 index 00000000..6d87be77 --- /dev/null +++ b/test/conditionals/substitution-folders/main.js @@ -0,0 +1 @@ +require("~/#{lang}/message"); diff --git a/test/conditionals/substitution-folders/package.json b/test/conditionals/substitution-folders/package.json new file mode 100644 index 00000000..35a17cf2 --- /dev/null +++ b/test/conditionals/substitution-folders/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" +}