From cf7ec8a025fc7a2f586406c3f9e3efdf652c9f2f Mon Sep 17 00:00:00 2001 From: Manuel Mujica Date: Wed, 26 Apr 2017 14:19:38 -0600 Subject: [PATCH 1/4] Refactor conditional build tests - Refactor copyDependencies - Replace deprecated `fs.exists` with `fs.access` --- test/build_conditionals_test.js | 106 +++++++++++++++----------------- 1 file changed, 49 insertions(+), 57 deletions(-) diff --git a/test/build_conditionals_test.js b/test/build_conditionals_test.js index 48d1eda7..d700ae4c 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( @@ -134,32 +127,31 @@ describe("build app using steal-conditional", function() { }); function copyDependencies() { - var prmdir = denodeify(rmdir); - var pcopy = denodeify(fs.copy); - - var srcModulesPath = path.join(__dirname, "..", "node_modules"); + 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-tilde") + ]; + + var promises = folders.map(function(dest) { + return copy( + path.join(src, "steal-conditional"), + path.join(dest, "node_modules", "steal-conditional") + ); + }); + + return Promise.all(promises); + } - return prmdir(booleanPath) - .then(function() { - return prmdir(substitutionPath); - }) - .then(function() { - return pcopy( - path.join(srcModulesPath, "steal-conditional"), - path.join(booleanPath, "steal-conditional") - ); - }) - .then(function() { - return pcopy( - path.join(srcModulesPath, "steal-conditional"), - path.join(substitutionPath, "steal-conditional") - ); - }) - .then(function() { - return pcopy( - path.join(srcModulesPath, "steal-conditional"), - path.join(substitutionTildePath, "steal-conditional") - ); - }); + /** + * 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.constants.F_OK); } }); From 3cc6f0941b6c0d471e042bca839741ac69f1c1b9 Mon Sep 17 00:00:00 2001 From: Manuel Mujica Date: Thu, 27 Apr 2017 14:51:40 -0600 Subject: [PATCH 2/4] Make sure conditional substitution builds correctly 1. Substitution in modules with plugins 2. Substitution of folder names Part of stealjs/steal-conditional/issues/38 --- package.json | 2 +- test/build_conditionals_test.js | 50 ++++++++++++++++++- test/conditionals/substitution-ext/blue.css | 1 + .../substitution-ext/folder/color.js | 0 test/conditionals/substitution-ext/index.html | 0 test/conditionals/substitution-ext/main.js | 2 + .../substitution-ext/package.json | 21 ++++++++ test/conditionals/substitution-ext/red.css | 1 + .../substitution-folders/en/message.js | 1 + .../substitution-folders/es/message.js | 1 + .../conditionals/substitution-folders/lang.js | 1 + .../conditionals/substitution-folders/main.js | 1 + .../substitution-folders/package.json | 19 +++++++ 13 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 test/conditionals/substitution-ext/blue.css create mode 100644 test/conditionals/substitution-ext/folder/color.js create mode 100644 test/conditionals/substitution-ext/index.html create mode 100644 test/conditionals/substitution-ext/main.js create mode 100644 test/conditionals/substitution-ext/package.json create mode 100644 test/conditionals/substitution-ext/red.css create mode 100644 test/conditionals/substitution-folders/en/message.js create mode 100644 test/conditionals/substitution-folders/es/message.js create mode 100644 test/conditionals/substitution-folders/lang.js create mode 100644 test/conditionals/substitution-folders/main.js create mode 100644 test/conditionals/substitution-folders/package.json diff --git a/package.json b/package.json index 3cbe3d12..cf7ab606 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "mockery": "^2.0.0", "rimraf": "^2.5.2", "serve-static": "^1.11.2", - "steal-conditional": "^0.3.2", + "steal-conditional": "stealjs/steal-conditional#fix-substitution", "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 d700ae4c..6453fcca 100644 --- a/test/build_conditionals_test.js +++ b/test/build_conditionals_test.js @@ -126,6 +126,52 @@ describe("build app using steal-conditional", function() { .catch(done); }); + 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(path.join(base, "dist")) + .then(function() { + return multiBuild({ + config: path.join(base, "package.json!npm") + }, { + quiet: true, + minify: false + }); + }) + .then(function() { + // make sure each variation is detected + return exists(path.join(bundle, "blue.css")); + }) + .then(function() { + // 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() { + // 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"); @@ -133,7 +179,9 @@ describe("build app using steal-conditional", function() { var folders = [ path.join(basePath, "boolean"), path.join(basePath, "substitution"), - path.join(basePath, "substitution-tilde") + path.join(basePath, "substitution-ext"), + path.join(basePath, "substitution-tilde"), + path.join(basePath, "substitution-folders") ]; var promises = folders.map(function(dest) { 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" +} From b60c37850b7c980dfb8bbb1fbb895acb62acf009 Mon Sep 17 00:00:00 2001 From: Manuel Mujica Date: Thu, 27 Apr 2017 15:24:33 -0600 Subject: [PATCH 3/4] Fix tests fs.constansts is undefined on Node 4/6. --- test/build_conditionals_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/build_conditionals_test.js b/test/build_conditionals_test.js index 6453fcca..7c3cecea 100644 --- a/test/build_conditionals_test.js +++ b/test/build_conditionals_test.js @@ -200,6 +200,6 @@ describe("build app using steal-conditional", function() { * @return {Promise} Resolves if the file exists, rejects otherwise. */ function exists(path) { - return denodeify(fs.access)(path, fs.constants.F_OK); + return denodeify(fs.access)(path, fs.F_OK); } }); From 7edd2c3272778e866a8381cc8452f30b1f97fe91 Mon Sep 17 00:00:00 2001 From: Manuel Mujica Date: Wed, 10 May 2017 09:46:10 -0600 Subject: [PATCH 4/4] Use steal-conditional@0.3.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cf7ab606..5131d613 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "mockery": "^2.0.0", "rimraf": "^2.5.2", "serve-static": "^1.11.2", - "steal-conditional": "stealjs/steal-conditional#fix-substitution", + "steal-conditional": "^0.3.4", "steal-qunit": "^1.0.0", "testee": "^0.4.0", "tree-kill": "^1.0.0"