Skip to content

Commit 4bc284f

Browse files
Chore/issue 428 refactor smoke test and cases (#497)
* refactor smoke test and re-enable * cleanup dupe testing * refactor beforeEach to before * turn coverage checks back on * delete invalid test cases * xdescribe and xit * fix smoke test tag matching and add smoke tests to ggraphql * add more smoke testing * add missing plugin-graphql ChildrenQuery spec * cleanup TODOs for path references normalization * remove TODOs that will be tracked via github * clean up rollup todos * restore local request blocking to puppeteer * remove commented code from config * final thresholds for now * clean up missed TODOs and console logs
1 parent 16e19dd commit 4bc284f

File tree

71 files changed

+317
-600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+317
-600
lines changed

greenwood.config.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const path = require('path');
2-
// const pluginImportCommonjs = require('./packages/plugin-import-commonjs/src/index');
32
const pluginGoogleAnalytics = require('./packages/plugin-google-analytics/src/index');
43
const pluginGraphQL = require('./packages/plugin-graphql/src/index');
54
const pluginImportCss = require('./packages/plugin-import-css/src/index');
@@ -26,7 +25,6 @@ module.exports = {
2625
{ name: 'google-site-verification', content: '4rYd8k5aFD0jDnN0CCFgUXNe4eakLP4NnA18mNnK5P0' }
2726
],
2827
plugins: [
29-
// ...pluginImportCommonjs(),
3028
pluginGoogleAnalytics({
3129
analyticsId: 'UA-147204327-1'
3230
}),

nyc.config.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ module.exports = {
44

55
include: [
66
'packages/cli/src/commands/*.js',
7-
'packages/cli/src/data/*.js',
87
'packages/cli/src/lib/*.js',
98
'packages/cli/src/lifecycles/*.js',
9+
'packages/cli/src/plugins/*.js',
1010
'packages/plugin-*/src/*.js'
1111
],
1212

@@ -17,12 +17,12 @@ module.exports = {
1717
'text-summary'
1818
],
1919

20-
checkCoverage: false, // TODO renable
20+
checkCoverage: true,
2121

22-
statements: 85,
23-
branches: 75,
24-
functions: 90,
25-
lines: 85,
22+
statements: 80,
23+
branches: 65,
24+
functions: 85,
25+
lines: 80,
2626

2727
watermarks: {
2828
statements: [75, 85],

packages/cli/src/config/rollup.config.js

+4-25
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ function greenwoodWorkspaceResolver (compilation) {
8080
return {
8181
name: 'greenwood-workspace-resolver',
8282
resolveId(source) {
83-
// TODO better way to handle relative paths? happens in generateBundle too
8483
if ((source.indexOf('./') === 0 || source.indexOf('/') === 0) && path.extname(source) !== '.html' && fs.existsSync(path.join(userWorkspace, source))) {
8584
return source.replace(source, path.join(userWorkspace, source));
8685
}
@@ -126,7 +125,6 @@ function greenwoodHtmlPlugin(compilation) {
126125
: null;
127126
}))).filter(resource => resource);
128127

129-
// TODO should reduce here instead
130128
if (resourceHandler.length) {
131129
const response = await resourceHandler[0].serve(id);
132130

@@ -153,8 +151,7 @@ function greenwoodHtmlPlugin(compilation) {
153151
});
154152
const headScripts = root.querySelectorAll('script');
155153
const headLinks = root.querySelectorAll('link');
156-
157-
// TODO handle deeper paths. e.g. ../../../
154+
158155
headScripts.forEach((scriptTag) => {
159156
const parsedAttributes = parseTagForAttributes(scriptTag);
160157

@@ -165,9 +162,6 @@ function greenwoodHtmlPlugin(compilation) {
165162
} else {
166163
const { src } = parsedAttributes;
167164

168-
// TODO avoid using href and set it to the value of rollup fileName instead
169-
// since user paths can still be the same file,
170-
// e.g. ../theme.css and ./theme.css are still the same file
171165
mappedScripts.set(src, true);
172166

173167
const srcPath = src.replace('../', './');
@@ -196,12 +190,7 @@ function greenwoodHtmlPlugin(compilation) {
196190
${scriptTag.rawText}
197191
`.trim();
198192

199-
// have to write a file for rollup?
200193
fs.writeFileSync(path.join(scratchDir, filename), source);
201-
202-
// TODO avoid using href and set it to the value of rollup fileName instead
203-
// since user paths can still be the same file,
204-
// e.g. ../theme.css and ./theme.css are still the same file
205194
mappedScripts.set(id, true);
206195

207196
this.emitFile({
@@ -225,7 +214,6 @@ function greenwoodHtmlPlugin(compilation) {
225214
href = href.slice(1);
226215
}
227216

228-
// TODO handle auto expanding deeper paths
229217
const basePath = href.indexOf(tokenNodeModules) >= 0
230218
? projectDirectory
231219
: userWorkspace;
@@ -244,9 +232,6 @@ function greenwoodHtmlPlugin(compilation) {
244232
});
245233
}
246234

247-
// TODO avoid using href and set it to the value of rollup fileName instead
248-
// since user paths can still be the same file,
249-
// e.g. ../theme.css and ./theme.css are still the same file
250235
mappedStyles[parsedAttributes.href] = {
251236
type: 'asset',
252237
fileName: fileName.indexOf(tokenNodeModules) >= 0
@@ -298,7 +283,6 @@ function greenwoodHtmlPlugin(compilation) {
298283
try {
299284
const bundle = bundles[bundleId];
300285

301-
// TODO handle (!) Generated empty chunks .greenwood/about, .greenwood/index
302286
if (bundle.isEntry && path.extname(bundle.facadeModuleId) === '.html') {
303287
const html = fs.readFileSync(bundle.facadeModuleId, 'utf-8');
304288
const root = htmlparser.parse(html, {
@@ -373,7 +357,6 @@ function greenwoodHtmlPlugin(compilation) {
373357
}
374358
});
375359

376-
// TODO this seems hacky; hardcoded dirs :D
377360
bundle.fileName = bundle.facadeModuleId.replace('.greenwood', 'public');
378361
bundle.code = newHtml;
379362
}
@@ -390,7 +373,6 @@ function greenwoodHtmlPlugin(compilation) {
390373
const bundle = bundles[bundleId];
391374

392375
if (bundle.isEntry && path.extname(bundle.facadeModuleId) === '.html') {
393-
// TODO this seems hacky; hardcoded dirs :D
394376
const htmlPath = bundle.facadeModuleId.replace('.greenwood', 'public');
395377
let html = fs.readFileSync(htmlPath, 'utf-8');
396378
const root = htmlparser.parse(html, {
@@ -478,17 +460,15 @@ function greenwoodHtmlPlugin(compilation) {
478460
module.exports = getRollupConfig = async (compilation) => {
479461
const { scratchDir, outputDir } = compilation.context;
480462
const defaultRollupPlugins = [
481-
// TODO replace should come in via plugin-node-modules
482463
replace({ // https://github.com/rollup/rollup/issues/487#issuecomment-177596512
483464
'process.env.NODE_ENV': JSON.stringify('production')
484465
}),
485-
nodeResolve(), // TODO move to plugin-node-modules
466+
nodeResolve(),
486467
greenwoodWorkspaceResolver(compilation),
487468
greenwoodHtmlPlugin(compilation),
488469
multiInput(),
489-
json() // TODO make it part plugin-standard-json
470+
json()
490471
];
491-
// TODO greenwood standard plugins, then "Greenwood" plugins, then user plugins
492472
const customRollupPlugins = compilation.config.plugins.filter((plugin) => {
493473
return plugin.type === 'rollup';
494474
}).map((plugin) => {
@@ -497,12 +477,11 @@ module.exports = getRollupConfig = async (compilation) => {
497477

498478
if (compilation.config.optimization !== 'none') {
499479
defaultRollupPlugins.push(
500-
terser() // TODO extract to plugin-standard-javascript
480+
terser()
501481
);
502482
}
503483

504484
return [{
505-
// TODO Avoid .greenwood/ directory, do everything in public/?
506485
input: `${scratchDir}**/*.html`,
507486
output: {
508487
dir: outputDir,

packages/cli/src/index.js

-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// https://github.com/ProjectEvergreen/greenwood/issues/141
66
process.setMaxListeners(0);
77

8-
// TODO require('colors');
9-
108
const program = require('commander');
119
const runProductionBuild = require('./commands/build');
1210
const runDevServer = require('./commands/develop');
@@ -17,10 +15,6 @@ const greenwoodPackageJson = require('../package.json');
1715
let cmdOption = {};
1816
let command = '';
1917

20-
// TODO
21-
// console.log(`${chalk.rgb(175, 207, 71)('-------------------------------------------------------')}`);
22-
// console.log(`${chalk.rgb(175, 207, 71)('Welcome to Greenwood ♻️')}`);
23-
// console.log(`${chalk.rgb(175, 207, 71)('-------------------------------------------------------')}`);
2418
console.info('-------------------------------------------------------');
2519
console.info('Welcome to Greenwood ♻️');
2620
console.info('-------------------------------------------------------');
@@ -29,7 +23,6 @@ program
2923
.version(greenwoodPackageJson.version)
3024
.arguments('<script-mode>')
3125
.usage('<script-mode> [options]');
32-
// TODO .usage(`${chalk.green('<script-mode>')} [options]`);
3326

3427
program
3528
.command('build')
@@ -63,7 +56,6 @@ program
6356

6457
program.parse(process.argv);
6558

66-
// TODO pick build by default? Thinking of npx usage...
6759
if (program.parse.length === 0) {
6860
program.help();
6961
}

packages/cli/src/lib/browser.js

+12-16
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,19 @@ class BrowserRunner {
3636

3737
await page.setRequestInterception(true);
3838

39-
// only allow puppeteer to load necessary scripts needed for pre-rendering of the site itself
39+
// only allow puppeteer to load necessary (local) scripts needed for pre-rendering of the site itself
4040
page.on('request', interceptedRequest => {
41-
// const interceptedRequestUrl = interceptedRequest.url();
42-
43-
// console.debug('request', interceptedRequestUrl);
44-
// TODO handle serialize only requests
45-
interceptedRequest.continue();
46-
// if (
47-
// interceptedRequestUrl.indexOf('bundle.js') >= 0 || // webpack bundles, webcomponents-bundle.js
48-
// interceptedRequestUrl === requestUrl || // pages / routes
49-
// interceptedRequestUrl.indexOf('localhost:4000') >= 0 // Apollo GraphQL server
50-
// ) {
51-
// interceptedRequest.continue();
52-
// } else {
53-
// console.debug('aborting request', interceptedRequestUrl)
54-
// interceptedRequest.abort();
55-
// }
41+
const interceptedRequestUrl = interceptedRequest.url();
42+
43+
if (
44+
interceptedRequestUrl.indexOf('http://127.0.0.1') >= 0 ||
45+
interceptedRequestUrl.indexOf('localhost') >= 0
46+
) {
47+
interceptedRequest.continue();
48+
} else {
49+
// console.warn('aborting request', interceptedRequestUrl);
50+
interceptedRequest.abort();
51+
}
5652
});
5753

5854
try {

packages/cli/src/lib/router.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@ document.addEventListener('click', function(e) {
33
e.preventDefault();
44

55
if (e.path[0].href) {
6-
console.debug('linked clicked was...', e.path[0].href);
76
const target = e.path[0];
87
const route = target.href.replace(window.location.origin, '');
98
const routerOutlet = Array.from(document.getElementsByTagName('greenwood-route')).filter(outlet => {
109
return outlet.getAttribute('data-route') === route;
1110
})[0];
1211

13-
console.debug('routerOutlet', routerOutlet);
14-
1512
if (routerOutlet.getAttribute('data-template') === window.__greenwood.currentTemplate) {
1613
window.__greenwood.currentTemplate = routerOutlet.getAttribute('data-template');
1714
routerOutlet.loadRoute();
1815
} else {
19-
console.debug('new template detected, should do a hard reload');
2016
window.location.href = target;
2117
}
2218
}
@@ -26,8 +22,7 @@ class RouteComponent extends HTMLElement {
2622
loadRoute() {
2723
const route = this.getAttribute('data-route');
2824
const key = this.getAttribute('data-key');
29-
console.debug('load route ->', route);
30-
console.debug('with bundle ->', key);
25+
3126
fetch(key)
3227
.then(res => res.text())
3328
.then((response) => {

packages/cli/src/lifecycles/compile.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// TODO require('colors');
21
const initConfig = require('./config');
32
const initContext = require('./context');
43
const generateGraph = require('./graph');
@@ -21,7 +20,6 @@ module.exports = generateCompilation = () => {
2120
compilation.context = await initContext(compilation);
2221

2322
// generate a graph of all pages / components to build
24-
// TODO make this async somehow / run in parallel?
2523
console.info('Generating graph of workspace files...');
2624
compilation = await generateGraph(compilation);
2725

packages/cli/src/lifecycles/copy.js

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ module.exports = copyAssets = (compilation) => {
6565
}
6666
}
6767

68-
// TODO should be done via rollup detection, so Greenwood will only copy files used when actually imported by the user
6968
console.info('copying graph.json...');
7069
await copyFile(`${context.scratchDir}graph.json`, `${context.outputDir}/graph.json`);
7170

packages/cli/src/lifecycles/serve.js

-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ function getProdServer(compilation) {
165165
ctx.body = contents;
166166
}
167167

168-
// TODO break up into distinct font / icons / svg handlers, decouple from to assets/
169168
if (url.indexOf('assets/')) {
170169
const assetPath = path.join(outputDir, url);
171170
const ext = path.extname(assetPath);

packages/cli/src/plugins/resource/plugin-standard-font.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { ResourceInterface } = require('../../lib/resource-interface');
1111
class StandardFontResource extends ResourceInterface {
1212
constructor(compilation, options) {
1313
super(compilation, options);
14-
this.extensions = ['.woff2', '.woff', '.ttf']; // TODO support more types?
14+
this.extensions = ['.woff2', '.woff', '.ttf'];
1515
}
1616

1717
async serve(url) {

packages/cli/src/plugins/resource/plugin-standard-html.js

-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const remarkRehype = require('remark-rehype');
1616
const { ResourceInterface } = require('../../lib/resource-interface');
1717
const unified = require('unified');
1818

19-
// TODO better error handling / messaging for users if things are not where they are expected to be
2019
// general refactoring
2120
const getPageTemplate = (barePath, workspace, template) => {
2221
const templatesDir = path.join(workspace, 'templates');
@@ -118,8 +117,6 @@ const getAppTemplate = (contents, userWorkspace) => {
118117

119118
const getUserScripts = (contents) => {
120119
if (process.env.__GWD_COMMAND__ === 'build') { // eslint-disable-line no-underscore-dangle
121-
// TODO setup and teardown should be done together
122-
// console.debug('running in build mode, polyfill WebComponents for puppeteer');
123120
contents = contents.replace('<head>', `
124121
<head>
125122
<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
@@ -133,7 +130,6 @@ const getMetaContent = (url, config, contents) => {
133130
const metaContent = config.meta.map(item => {
134131
let metaHtml = '';
135132

136-
// TODO better way to implememnt this? should we implement this?
137133
for (const [key, value] of Object.entries(item)) {
138134
const isOgUrl = item.property === 'og:url' && key === 'content';
139135
const hasTrailingSlash = isOgUrl && value[value.length - 1] === '/';
@@ -151,7 +147,6 @@ const getMetaContent = (url, config, contents) => {
151147
: `<meta${metaHtml}/>`;
152148
}).join('\n');
153149

154-
// TODO make smarter so that if it already exists, then leave it alone
155150
contents = contents.replace(/<title>(.*)<\/title>/, '');
156151
contents = contents.replace('<head>', `<head><title>${title}</title>`);
157152
contents = contents.replace('<meta-outlet></meta-outlet>', metaContent);
@@ -219,7 +214,6 @@ class StandardHtmlResource extends ResourceInterface {
219214
}
220215
});
221216

222-
// TODO extract front matter contents from remark-frontmatter instead of frontmatter lib
223217
const settings = config.markdown.settings || {};
224218
const fm = frontmatter(markdownContents);
225219
processedMarkdown = await unified()

packages/cli/src/plugins/resource/plugin-standard-javascript.js

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class StandardJavaScriptResource extends ResourceInterface {
2828
}
2929
});
3030
}
31-
32-
// TODO pptional optimize w/ terser (not rollup)
3331
}
3432

3533
module.exports = {

packages/cli/src/plugins/resource/plugin-standard-json.js

-4
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ class StandardJsonResource extends ResourceInterface {
2222
let contentType = '';
2323
const { context } = this.compilation;
2424

25-
// TODO should be its own plugin / package, as part of data
2625
if (url.indexOf('graph.json') >= 0) {
2726
const json = await fs.promises.readFile(path.join(context.scratchDir, 'graph.json'), 'utf-8');
2827

2928
contentType = 'application/json';
3029
body = JSON.parse(json);
3130
} else {
32-
// TODO should be its own plugin / package
3331
const json = await fs.promises.readFile(url, 'utf-8');
3432

3533
contentType = 'text/javascript';
@@ -45,8 +43,6 @@ class StandardJsonResource extends ResourceInterface {
4543
}
4644
});
4745
}
48-
49-
// TODO include rollup json plugin support
5046
}
5147

5248
module.exports = {

0 commit comments

Comments
 (0)