From 3e70c7319b754df4832ac2ba67eb69e5e8a67921 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Tue, 21 Jul 2015 17:28:18 -0700 Subject: [PATCH] Separate coffee and less self-tests --- .../.meteor/.gitignore | 0 .../.meteor/packages | 1 - .../.meteor/release | 0 .../f1.coffee | 0 .../f2.coffee | 0 .../f3.coffee | 0 .../packages/local-pack/p.coffee | 0 .../packages/local-pack/package.js | 3 +- .../apps/caching-less/.meteor/.gitignore | 1 + .../tests/apps/caching-less/.meteor/packages | 9 ++ tools/tests/apps/caching-less/.meteor/release | 1 + .../imports/dotdot.less | 0 tools/tests/apps/caching-less/output.js | 1 + .../packages/local-pack/p.less | 0 .../packages/local-pack/package.js | 4 + .../subdir/foo.import.less | 0 .../subdir/nested-root.less | 0 .../top.less | 0 tools/tests/compiler-plugins.js | 140 ++++++++++-------- 19 files changed, 99 insertions(+), 61 deletions(-) rename tools/tests/apps/{coffee-and-less => caching-coffee}/.meteor/.gitignore (100%) rename tools/tests/apps/{coffee-and-less => caching-coffee}/.meteor/packages (97%) rename tools/tests/apps/{coffee-and-less => caching-coffee}/.meteor/release (100%) rename tools/tests/apps/{coffee-and-less => caching-coffee}/f1.coffee (100%) rename tools/tests/apps/{coffee-and-less => caching-coffee}/f2.coffee (100%) rename tools/tests/apps/{coffee-and-less => caching-coffee}/f3.coffee (100%) rename tools/tests/apps/{coffee-and-less => caching-coffee}/packages/local-pack/p.coffee (100%) rename tools/tests/apps/{coffee-and-less => caching-coffee}/packages/local-pack/package.js (50%) create mode 100644 tools/tests/apps/caching-less/.meteor/.gitignore create mode 100644 tools/tests/apps/caching-less/.meteor/packages create mode 100644 tools/tests/apps/caching-less/.meteor/release rename tools/tests/apps/{coffee-and-less => caching-less}/imports/dotdot.less (100%) create mode 100644 tools/tests/apps/caching-less/output.js rename tools/tests/apps/{coffee-and-less => caching-less}/packages/local-pack/p.less (100%) create mode 100644 tools/tests/apps/caching-less/packages/local-pack/package.js rename tools/tests/apps/{coffee-and-less => caching-less}/subdir/foo.import.less (100%) rename tools/tests/apps/{coffee-and-less => caching-less}/subdir/nested-root.less (100%) rename tools/tests/apps/{coffee-and-less => caching-less}/top.less (100%) diff --git a/tools/tests/apps/coffee-and-less/.meteor/.gitignore b/tools/tests/apps/caching-coffee/.meteor/.gitignore similarity index 100% rename from tools/tests/apps/coffee-and-less/.meteor/.gitignore rename to tools/tests/apps/caching-coffee/.meteor/.gitignore diff --git a/tools/tests/apps/coffee-and-less/.meteor/packages b/tools/tests/apps/caching-coffee/.meteor/packages similarity index 97% rename from tools/tests/apps/coffee-and-less/.meteor/packages rename to tools/tests/apps/caching-coffee/.meteor/packages index 54d0b6c074..fb8ddd4545 100644 --- a/tools/tests/apps/coffee-and-less/.meteor/packages +++ b/tools/tests/apps/caching-coffee/.meteor/packages @@ -5,6 +5,5 @@ meteor-platform coffeescript -less local-pack standard-minifiers diff --git a/tools/tests/apps/coffee-and-less/.meteor/release b/tools/tests/apps/caching-coffee/.meteor/release similarity index 100% rename from tools/tests/apps/coffee-and-less/.meteor/release rename to tools/tests/apps/caching-coffee/.meteor/release diff --git a/tools/tests/apps/coffee-and-less/f1.coffee b/tools/tests/apps/caching-coffee/f1.coffee similarity index 100% rename from tools/tests/apps/coffee-and-less/f1.coffee rename to tools/tests/apps/caching-coffee/f1.coffee diff --git a/tools/tests/apps/coffee-and-less/f2.coffee b/tools/tests/apps/caching-coffee/f2.coffee similarity index 100% rename from tools/tests/apps/coffee-and-less/f2.coffee rename to tools/tests/apps/caching-coffee/f2.coffee diff --git a/tools/tests/apps/coffee-and-less/f3.coffee b/tools/tests/apps/caching-coffee/f3.coffee similarity index 100% rename from tools/tests/apps/coffee-and-less/f3.coffee rename to tools/tests/apps/caching-coffee/f3.coffee diff --git a/tools/tests/apps/coffee-and-less/packages/local-pack/p.coffee b/tools/tests/apps/caching-coffee/packages/local-pack/p.coffee similarity index 100% rename from tools/tests/apps/coffee-and-less/packages/local-pack/p.coffee rename to tools/tests/apps/caching-coffee/packages/local-pack/p.coffee diff --git a/tools/tests/apps/coffee-and-less/packages/local-pack/package.js b/tools/tests/apps/caching-coffee/packages/local-pack/package.js similarity index 50% rename from tools/tests/apps/coffee-and-less/packages/local-pack/package.js rename to tools/tests/apps/caching-coffee/packages/local-pack/package.js index 4f0df7b7b1..3ac09e5496 100644 --- a/tools/tests/apps/coffee-and-less/packages/local-pack/package.js +++ b/tools/tests/apps/caching-coffee/packages/local-pack/package.js @@ -1,6 +1,5 @@ Package.onUse(function (api) { - api.use(['coffeescript', 'less']); + api.use(['coffeescript']); api.addFiles(['p.coffee']); - api.addFiles('p.less', 'client', {isImport: true}); api.export('FromPackage'); }); diff --git a/tools/tests/apps/caching-less/.meteor/.gitignore b/tools/tests/apps/caching-less/.meteor/.gitignore new file mode 100644 index 0000000000..4083037423 --- /dev/null +++ b/tools/tests/apps/caching-less/.meteor/.gitignore @@ -0,0 +1 @@ +local diff --git a/tools/tests/apps/caching-less/.meteor/packages b/tools/tests/apps/caching-less/.meteor/packages new file mode 100644 index 0000000000..17287c5d1b --- /dev/null +++ b/tools/tests/apps/caching-less/.meteor/packages @@ -0,0 +1,9 @@ +# Meteor packages used by this project, one per line. +# +# 'meteor add' and 'meteor remove' will edit this file for you, +# but you can also edit it by hand. + +meteor-platform +less +local-pack +standard-minifiers diff --git a/tools/tests/apps/caching-less/.meteor/release b/tools/tests/apps/caching-less/.meteor/release new file mode 100644 index 0000000000..621e94f0ec --- /dev/null +++ b/tools/tests/apps/caching-less/.meteor/release @@ -0,0 +1 @@ +none diff --git a/tools/tests/apps/coffee-and-less/imports/dotdot.less b/tools/tests/apps/caching-less/imports/dotdot.less similarity index 100% rename from tools/tests/apps/coffee-and-less/imports/dotdot.less rename to tools/tests/apps/caching-less/imports/dotdot.less diff --git a/tools/tests/apps/caching-less/output.js b/tools/tests/apps/caching-less/output.js new file mode 100644 index 0000000000..b179ee9534 --- /dev/null +++ b/tools/tests/apps/caching-less/output.js @@ -0,0 +1 @@ +console.log("Hello world"); diff --git a/tools/tests/apps/coffee-and-less/packages/local-pack/p.less b/tools/tests/apps/caching-less/packages/local-pack/p.less similarity index 100% rename from tools/tests/apps/coffee-and-less/packages/local-pack/p.less rename to tools/tests/apps/caching-less/packages/local-pack/p.less diff --git a/tools/tests/apps/caching-less/packages/local-pack/package.js b/tools/tests/apps/caching-less/packages/local-pack/package.js new file mode 100644 index 0000000000..a3106d3794 --- /dev/null +++ b/tools/tests/apps/caching-less/packages/local-pack/package.js @@ -0,0 +1,4 @@ +Package.onUse(function (api) { + api.use(['less']); + api.addFiles('p.less', 'client', {isImport: true}); +}); diff --git a/tools/tests/apps/coffee-and-less/subdir/foo.import.less b/tools/tests/apps/caching-less/subdir/foo.import.less similarity index 100% rename from tools/tests/apps/coffee-and-less/subdir/foo.import.less rename to tools/tests/apps/caching-less/subdir/foo.import.less diff --git a/tools/tests/apps/coffee-and-less/subdir/nested-root.less b/tools/tests/apps/caching-less/subdir/nested-root.less similarity index 100% rename from tools/tests/apps/coffee-and-less/subdir/nested-root.less rename to tools/tests/apps/caching-less/subdir/nested-root.less diff --git a/tools/tests/apps/coffee-and-less/top.less b/tools/tests/apps/caching-less/top.less similarity index 100% rename from tools/tests/apps/coffee-and-less/top.less rename to tools/tests/apps/caching-less/top.less diff --git a/tools/tests/compiler-plugins.js b/tools/tests/compiler-plugins.js index 29384207ae..7e5bd984cb 100644 --- a/tools/tests/compiler-plugins.js +++ b/tools/tests/compiler-plugins.js @@ -18,33 +18,92 @@ function startRun(sandbox) { return run; }; -// Tests the actual cache logic used by coffeescript and less. -selftest.define("compiler plugin caching - coffee/less", function () { +// Tests the actual cache logic used by coffeescript. +selftest.define("compiler plugin caching - coffee", function () { var s = new Sandbox({ fakeMongo: true }); - // Create an app that uses coffeescript and less. - s.createApp("myapp", "coffee-and-less"); + s.createApp("myapp", "caching-coffee"); s.cd("myapp"); // Ask them to print out when they build a file (instead of using it from the // cache) as well as when they load cache from disk. s.set('METEOR_COFFEESCRIPT_CACHE_DEBUG', 't'); - s.set("METEOR_LESS_CACHE_DEBUG", "t"); var run = startRun(s); // First program built (server or web.browser) compiles everything. run.match('CACHE(coffeescript): Ran (#1) on: ' + JSON.stringify( ['/f1.coffee', '/f2.coffee', '/f3.coffee', '/packages/local-pack/p.coffee'] )); - run.match('CACHE(less): Ran (#1) on: ' + JSON.stringify( - ["/subdir/nested-root.less", "/top.less"])); // Second program doesn't need to compile anything because compilation works - // the same on both programs. (Note that there is no less.render execution in - // the second program, because it has archMatching: 'web'. We'll see this - // more clearly when the next call later is "#2" --- we didn't miss a call!) + // the same on both programs. run.match("CACHE(coffeescript): Ran (#2) on: []"); // App prints this: run.match("Coffeescript X is 2 Y is 1 FromPackage is 4"); + s.write("f2.coffee", "share.Y = 'Y is 3'\n"); + // Only recompiles f2. + run.match('CACHE(coffeescript): Ran (#3) on: ["/f2.coffee"]'); + // And other program doesn't even need to do f2. + run.match("CACHE(coffeescript): Ran (#4) on: []"); + // Program prints this: + run.match("Coffeescript X is 2 Y is 3 FromPackage is 4"); + + // Force a rebuild of the local package without actually changing the + // coffeescript file in it. This should not require us to coffee.compile + // anything (for either program). + s.append("packages/local-pack/package.js", "\n// foo\n"); + run.match("CACHE(coffeescript): Ran (#5) on: []"); + run.match("CACHE(coffeescript): Ran (#6) on: []"); + run.match("Coffeescript X is 2 Y is 3 FromPackage is 4"); + + // But writing to the actual source file in the local package should + // recompile. + s.write("packages/local-pack/p.coffee", "FromPackage = 'FromPackage is 5'"); + run.match('CACHE(coffeescript): Ran (#7) on: ["/packages/local-pack/p.coffee"]'); + run.match('CACHE(coffeescript): Ran (#8) on: []'); + run.match("Coffeescript X is 2 Y is 3 FromPackage is 5"); + + // We never should have loaded cache from disk, since we only made + // each compiler once and there were no cache files at this point. + run.forbid('CACHE(coffeescript): Loaded'); + + // Kill the run. Change one coffee file and re-run. + run.stop(); + s.write("f2.coffee", "share.Y = 'Y is edited'\n"); + run = startRun(s); + + // This time there's a cache to load! + run.match('CACHE(coffeescript): Loaded /packages/local-pack/p.coffee'); + run.match('CACHE(coffeescript): Loaded /f1.coffee'); + run.match('CACHE(coffeescript): Loaded /f3.coffee'); + // And we only need to re-compiler the changed file, even though we restarted. + run.match('CACHE(coffeescript): Ran (#1) on: ["/f2.coffee"]'); + run.match('CACHE(coffeescript): Ran (#2) on: []'); + + run.match('Coffeescript X is 2 Y is edited FromPackage is 5'); + + run.stop(); +}); + +// Tests the actual cache logic used by less. +selftest.define("compiler plugin caching - less", function () { + var s = new Sandbox({ fakeMongo: true }); + + s.createApp("myapp", "caching-less"); + s.cd("myapp"); + // Ask them to print out when they build a file (instead of using it from the + // cache) as well as when they load cache from disk. + s.set("METEOR_LESS_CACHE_DEBUG", "t"); + var run = startRun(s); + + // First program built (web.browser) compiles everything. + run.match('CACHE(less): Ran (#1) on: ' + JSON.stringify( + ["/subdir/nested-root.less", "/top.less"])); + // There is no less.render execution in the server program, because it has + // archMatching:'web'. We'll see this more clearly when the next call later + // is "#2" --- we didn't miss a call! + // App prints this: + run.match("Hello world"); + // Check that the CSS is what we expect. var checkCSS = selftest.markStack(function (borderStyleMap) { var builtBrowserProgramDir = files.pathJoin( @@ -69,87 +128,52 @@ selftest.define("compiler plugin caching - coffee/less", function () { el0: "dashed", el1: "dotted", el2: "solid", el3: "groove", el4: "ridge"}; checkCSS(expectedBorderStyles); - s.write("f2.coffee", "share.Y = 'Y is 3'\n"); - // Only recompiles f2. - run.match('CACHE(coffeescript): Ran (#3) on: ["/f2.coffee"]'); - run.match('CACHE(less): Ran (#2) on: []'); - // And other program doesn't even need to do f2. - run.match("CACHE(coffeescript): Ran (#4) on: []"); - // Program prints this: - run.match("Coffeescript X is 2 Y is 3 FromPackage is 4"); - // Force a rebuild of the local package without actually changing the - // coffeescript file in it. This should not require us to coffee.compile - // anything (for either program). + // less file in it. This should not require us to less.render + // anything. s.append("packages/local-pack/package.js", "\n// foo\n"); - run.match("CACHE(coffeescript): Ran (#5) on: []"); - run.match('CACHE(less): Ran (#3) on: []'); - run.match("CACHE(coffeescript): Ran (#6) on: []"); - run.match("Coffeescript X is 2 Y is 3 FromPackage is 4"); - - // But writing to the actual source file in the local package should - // recompile. - s.write("packages/local-pack/p.coffee", "FromPackage = 'FromPackage is 5'"); - run.match('CACHE(coffeescript): Ran (#7) on: ["/packages/local-pack/p.coffee"]'); - run.match('CACHE(less): Ran (#4) on: []'); - run.match('CACHE(coffeescript): Ran (#8) on: []'); - run.match("Coffeescript X is 2 Y is 3 FromPackage is 5"); + run.match('CACHE(less): Ran (#2) on: []'); + run.match("Hello world"); // Writing to a single less file only re-renders the root that depends on it. s.write('packages/local-pack/p.less', '@el4-style: inset;\n'); expectedBorderStyles.el4 = 'inset'; - run.match('CACHE(coffeescript): Ran (#9) on: []'); - run.match('CACHE(less): Ran (#5) on: ["/top.less"]'); - // Note that since this was a client-only change, we're smart enough to not - // rebuild the server at all. So the next coffee.compile will be #10. + run.match('CACHE(less): Ran (#3) on: ["/top.less"]'); run.match("Client modified -- refreshing"); checkCSS(expectedBorderStyles); // This works for changing a root too. s.write('subdir/nested-root.less', '.el0 { border-style: double; }\n'); expectedBorderStyles.el0 = 'double'; - // Only #10, not #11, because client-only changes don't rebuild the server! - run.match('CACHE(coffeescript): Ran (#10) on: []'); - run.match('CACHE(less): Ran (#6) on: ["/subdir/nested-root.less"]'); + run.match('CACHE(less): Ran (#4) on: ["/subdir/nested-root.less"]'); run.match("Client modified -- refreshing"); checkCSS(expectedBorderStyles); // Adding a new root works too. s.write('yet-another-root.less', '.el6 { border-style: solid; }\n'); expectedBorderStyles.el6 = 'solid'; - run.match('CACHE(coffeescript): Ran (#11) on: []'); - run.match('CACHE(less): Ran (#7) on: ["/yet-another-root.less"]'); + run.match('CACHE(less): Ran (#5) on: ["/yet-another-root.less"]'); run.match("Client modified -- refreshing"); checkCSS(expectedBorderStyles); // We never should have loaded cache from disk, since we only made - // each compiler once and there was no cache.json at this point. - run.forbid('CACHE(coffeescript): Loaded'); + // each compiler once and there were no cache files at this point. run.forbid('CACHE(less): Loaded'); - // Kill the run. Change one coffee file and one less file and re-run. + // Kill the run. Change one file and re-run. run.stop(); - s.write("f2.coffee", "share.Y = 'Y is edited'\n"); s.write('packages/local-pack/p.less', '@el4-style: double;\n'); expectedBorderStyles.el4 = 'double'; run = startRun(s); - // This time there's a cache to load! - run.match('CACHE(coffeescript): Loaded /packages/local-pack/p.coffee'); - run.match('CACHE(coffeescript): Loaded /f1.coffee'); - run.match('CACHE(coffeescript): Loaded /f3.coffee'); - // And we only need to re-compiler the changed file, even though we restarted. - run.match('CACHE(coffeescript): Ran (#1) on: ["/f2.coffee"]'); - // Note that for MultiFileCachingCompiler we load all the cache entries, even - // for the not-up-to-date top.less, because we only key off of filename, not - // off of cache key. + // This time there's a cache to load! Note that for MultiFileCachingCompiler + // we load all the cache entries, even for the not-up-to-date file top.less, + // because we only key off of filename, not off of cache key. run.match('CACHE(less): Loaded {}/subdir/nested-root.less'); run.match('CACHE(less): Loaded {}/top.less'); run.match('CACHE(less): Loaded {}/yet-another-root.less'); run.match('CACHE(less): Ran (#1) on: ["/top.less"]'); - run.match('CACHE(coffeescript): Ran (#2) on: []'); - - run.match('Coffeescript X is 2 Y is edited FromPackage is 5'); + run.match('Hello world'); checkCSS(expectedBorderStyles); s.write('bad-import.less', '@import "/foo/bad.less";\n');