Skip to content

Commit

Permalink
Merge pull request #37 from meteor/devel
Browse files Browse the repository at this point in the history
Boilerplate refactor (meteor#8820)
  • Loading branch information
GulajavaMinistudio authored Jul 10, 2017
2 parents fed308b + 98b02f3 commit 3270c8b
Show file tree
Hide file tree
Showing 15 changed files with 420 additions and 196 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
7 changes: 7 additions & 0 deletions packages/boilerplate-generator-tests/.npm/package/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This directory and the files immediately inside it are automatically generated
when you change this package's NPM dependencies. Commit the files in this
directory (npm-shrinkwrap.json, .gitignore, and this README) to source control
so that others run the same versions of sub-dependencies.

You should NOT check in the node_modules directory that Meteor automatically
creates; if you are using git, the .gitignore file tells git to ignore it.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
13 changes: 13 additions & 0 deletions packages/boilerplate-generator-tests/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Npm.depends({'parse5': '3.0.2'});
Package.describe({
// These tests are in a separate package so that we can Npm.depend on parse5, a html parsing library
summary: "Tests for the boilerplate-generator package",
version: '1.0.0'
});

Package.onTest(function (api) {
api.use('ecmascript');
api.use(['tinytest', 'boilerplate-generator'], 'server');
api.addFiles('web.browser-tests.js', 'server');
api.addFiles('web.cordova-tests.js', 'server');
});
54 changes: 54 additions & 0 deletions packages/boilerplate-generator-tests/test-lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
export function generateHTMLForArch(arch) {
// Use a dummy manifest. None of these paths will be read from the filesystem, but css / js should be handled differently
const manifest = [
{
path: 'packages/bootstrap/css/bootstrap-responsive.css',
where: 'client',
type: 'css',
cacheable: true,
url: '/packages/bootstrap/css/bootstrap-responsive.css?hash=785760fc5ad665d7b54d56a3c2522797bb2cc150&v="1"',
size: 22111,
hash: '785760fc5ad665d7b54d56a3c2522797bb2cc150'
},
{
path: 'packages/templating-runtime.js',
where: 'client',
type: 'js',
cacheable: true,
url: '/packages/templating-runtime.js?hash=c18de19afda6e9f0db7faf3d4382a4c953cabe18&v="1"',
size: 24132,
hash: 'c18de19afda6e9f0db7faf3d4382a4c953cabe18'
},
];

// Set some extra options for boilerplate data.
// webapp_server usually constructs a Boilerplate object similarly
const inline = true;
const inlineScriptsAllowed = true;
const additionalStaticJs = [];
const meteorRuntimeConfig = 'config123';
const rootUrlPathPrefix = 'rootUrlPathPrefix';
const htmlAttributes = {
foo: 'foobar',
gems: '&"',
};

// A dummy rewrite hook to test ampersands
function bundledJsCssUrlRewriteHook(url) {
return url + '+rewritten_url=true';
}

const boilerplate = new Boilerplate(arch, manifest, {
baseDataExtension: {
htmlAttributes,
additionalStaticJs,
meteorRuntimeConfig,
rootUrlPathPrefix,
bundledJsCssUrlRewriteHook,
inlineScriptsAllowed,
inline
},
});

return boilerplate.toHTML();
};
41 changes: 41 additions & 0 deletions packages/boilerplate-generator-tests/web.browser-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { parse, serialize } from 'parse5';
import { generateHTMLForArch } from './test-lib';

const html = generateHTMLForArch('web.browser');

Tinytest.add("boilerplate-generator-tests - web.browser - well-formed html", function (test) {
const formatted = serialize(parse(html));
test.isTrue(formatted.replace(/\s/g, '') === html.replace(/\s/g, ''));
});

Tinytest.add("boilerplate-generator-tests - web.browser - include htmlAttributes", function (test) {
test.matches(html, /foo="foobar"/);
});

Tinytest.add("boilerplate-generator-tests - web.browser - escape htmlAttributes", function (test) {
test.matches(html, /gems="&""/);
});

Tinytest.add("boilerplate-generator-tests - web.browser - include js", function (test) {
test.matches(html, /<script[^<>]*src="[^<>]*templating[^<>]*">/);
});

Tinytest.add("boilerplate-generator-tests - web.browser - escape js", function (test) {
test.matches(html, /<script[^<>]*src="[^<>]*templating[^<>]*&amp;v=&quot;1&quot;[^<>]*">/);
});

Tinytest.add("boilerplate-generator-tests - web.browser - include css", function (test) {
test.matches(html, /<link[^<>]*href="[^<>]*bootstrap[^<>]*">/);
});

Tinytest.add("boilerplate-generator-tests - web.browser - escape css", function (test) {
test.matches(html, /<link[^<>]*href="[^<>]*bootstrap[^<>]*&amp;v=&quot;1&quot;[^<>]*">/);
});

Tinytest.add("boilerplate-generator-tests - web.browser - call rewriteHook", function (test) {
test.matches(html, /\+rewritten_url=true/);
});

Tinytest.add("boilerplate-generator-tests - web.browser - include runtime config", function (test) {
test.matches(html, /<script[^<>]*>[^<>]*__meteor_runtime_config__ =.*decodeURIComponent\(config123\)/);
});
33 changes: 33 additions & 0 deletions packages/boilerplate-generator-tests/web.cordova-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { parse, serialize } from 'parse5';
import { generateHTMLForArch } from './test-lib';

const html = generateHTMLForArch('web.cordova');

Tinytest.add("boilerplate-generator-tests - web.cordova - well-formed html", function (test) {
const formatted = serialize(parse(html));
test.isTrue(formatted.replace(/\s/g, '') === html.replace(/\s/g, ''));
});

Tinytest.add("boilerplate-generator-tests - web.cordova - include js", function (test) {
test.matches(html, /<script[^<>]*src="[^<>]*templating[^<>]*">/);
});

Tinytest.add("boilerplate-generator-tests - web.cordova - escape js", function (test) {
test.matches(html, /<script[^<>]*src="[^<>]*templating[^<>]*&amp;v=&quot;1&quot;[^<>]*">/);
});

Tinytest.add("boilerplate-generator-tests - web.cordova - include css", function (test) {
test.matches(html, /<link[^<>]*href="[^<>]*bootstrap[^<>]*">/);
});

Tinytest.add("boilerplate-generator-tests - web.cordova - escape css", function (test) {
test.matches(html, /<link[^<>]*href="[^<>]*bootstrap[^<>]*&amp;v=&quot;1&quot;[^<>]*">/);
});

Tinytest.add("boilerplate-generator-tests - web.cordova - do not call rewriteHook", function (test) {
test.notMatches(html, /\+rewritten_url=true/);
});

Tinytest.add("boilerplate-generator-tests - web.cordova - include runtime config", function (test) {
test.matches(html, /<script[^<>]*>[^<>]*\n[^<>]*__meteor_runtime_config__ =[^<>]*decodeURIComponent\(config123\)\)/);
});
106 changes: 0 additions & 106 deletions packages/boilerplate-generator/boilerplate-generator.js

This file was deleted.

28 changes: 0 additions & 28 deletions packages/boilerplate-generator/boilerplate_web.browser.html

This file was deleted.

46 changes: 0 additions & 46 deletions packages/boilerplate-generator/boilerplate_web.cordova.html

This file was deleted.

Loading

0 comments on commit 3270c8b

Please sign in to comment.