Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UPWARD specification, guide, tests, reference implementation #248

Merged
merged 23 commits into from
Oct 4, 2018

Conversation

zetlen
Copy link
Contributor

@zetlen zetlen commented Aug 22, 2018

This PR is a:

[x] New feature
[ ] Enhancement/Optimization
[ ] Refactor
[ ] Bugfix
[ ] Test for existing code
[x] Documentation

Summary

When this pull request is merged, it will add the UPWARD specification, guide, test suite, and reference implementation in JavaScript. See the README in this pull request for details.

@coveralls
Copy link

coveralls commented Aug 22, 2018

Coverage Status

Coverage decreased (-0.9%) to 19.428% when pulling 9a83510 on zetlen/upward into ef05a2d on release/2.0.

@zetlen zetlen force-pushed the zetlen/upward branch 2 times, most recently from 5d3af8b to fadb5f7 Compare August 23, 2018 12:55
Copy link
Contributor

@jimbo jimbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a first batch of feedback. Lots of files in this one.

if (mapping.hasOwnProperty(lowered)) {
return mapping[lowered];
}
if (value.match(/^\d*\.?\d+$/)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment either explaining the regex or giving an example.

'latin-1',
'base64',
'hex',
...Array.from({ length: 600 }, (_, i) => (i + 100).toString())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. 👍

}

get(path) {
return constants.get(prop) || dotLookup(this._data, path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is dotLookup a global or something? I don't see it defined or imported. Perhaps you meant this.depend, which is defined below but appears to be unused?

return value =>
allowed.includes(value)
? undefined
: `must be one of: ${allowed.join()}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the passing case, why does this return undefined, rather than '' like all the rest of these tests?

errors.push({
name,
errors: itemErrors
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like errors is defined at this point, so errors.push looks wrong to me here. Did you mean report.errors.push()?

@zetlen
Copy link
Contributor Author

zetlen commented Sep 18, 2018

Noting that I have to back-merge my integration branch into this.

@zetlen zetlen changed the base branch from master to release/1.0 September 25, 2018 20:41
@zetlen zetlen changed the base branch from release/1.0 to release/2.0 September 26, 2018 21:09
@zetlen
Copy link
Contributor Author

zetlen commented Sep 27, 2018

Closes #28.

return x;
}, rejectPreload);
} catch (e) {
rejectPreload();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like rejectPreload accepts a single argument, e. It's not being called with any arguments here, though. Did you mean to pass e to it?

mod => mod.resource.includes('/node_modules/')
: // Top-level modules injected by a downstream "issuer" are not
// entry points in production.
mod => !mod.issuer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments helping make this file understandable. 👍

// apply their changes synchronously. Use a proxy function to add a
// middleware which lazy loads UPWARD when it's time.
let upwardMiddleware;
let upwardMiddlewarePromise = new Promise((resolve, reject) => {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable, upwardMiddlewarePromise, appears to be unused. Is this dead code? How is this supposed to work?

: res.json()
);
};
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean and understandable. 👍

Tests would be good.

packages/upward-js/bin/server Outdated Show resolved Hide resolved
}
}

module.exports = Context;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what this file is doing?

@@ -0,0 +1,101 @@
const debug = require('debug')('upward-js:ContextPath');
const illegalPathChars = /(^[\.\[\]])|[^\.\w\$\/]/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment either explaining the regex or giving an example.


const readFile = promisify(fsReadFile);
class IOAdapter {
static default(upwardPath) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea. 👍

debug(
`returning middleware from visitor.downward() instead of object`
);
return passedMiddleware;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if any one of the requests returns a middleware, this error is thrown and caught, and only the middleware is returned. All the other requests are thrown out?

}
getResolverFor(defined, propertyName) {
let Resolver;
for (Resolver of ResolverList) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scoping of Resolver is misleading here.

  • Resolver is declared as a mutable variable prior to the for...of block
  • On each loop iteration, Resolver is reassigned and Resolver.recognize() is always called
  • On each loop iteration, there may be an early return

The only time this arrangement is useful is if the code following the for...of block is interested in the value of Resolver after the loop has completed. Otherwise, we would expect to see for (const Resolver of ResolverList) {}.

However, the code following the for...of block ("subsequent code") is not interested in the value of Resolver. In fact, the subsequent code always reassigns Resolver before ever reading its value. This is counterintuitive because Resolver appears to have been specifically declared such that it is meaningful, yet it isn't.

My recommendation:

getResolverFor(defined, propertyName) {
    for (const Resolver of ResolverList) {
        // ...
    }

    const definedResolver = defined.resolver

    const Resolver = definedResolver
        ? ResolversByType[definedResolver]
        : ResolverList.find(({ telltale }) => defined.hasOwnProperty(telltale))

    if (Resolver) {
        return new Resolver(this)
    } else {
        this.getResolverFailure = definedResolver
            ? 'Unrecognized resolver type...'
            : 'Unrecognized configuration...'
    }
}

@zetlen zetlen changed the title (WIP: DO NOT MERGE) Add UPWARD specification, guide, tests, reference impl Add UPWARD specification, guide, tests, reference implementation Oct 4, 2018
@magento magento deleted a comment from PWAStudioBot Oct 4, 2018
@PWAStudioBot
Copy link
Contributor

Fails
🚫

The following unit tests did not pass 😔. All tests must pass before this PR can be merged

packages/upward-js/lib/__tests__/buildResponse.test.js
  �[1m● �[22mTest suite failed to run
Cannot find module './mockGQLService' from 'index.js'

�[0m �[90m 2 | �[39m    assertOnResponse�[33m:�[39m require(�[32m'./assertOnResponse'�[39m)�[33m,�[39m�[0m
�[0m �[90m 3 | �[39m    getScenarios�[33m:�[39m require(�[32m'./getScenarios'�[39m)�[33m,�[39m�[0m
�[0m�[31m�[1m>�[22m�[39m�[90m 4 | �[39m    mockGQLService�[33m:�[39m require(�[32m'./mockGQLService'�[39m)�[33m,�[39m�[0m
�[0m �[90m   | �[39m                    �[31m�[1m^�[22m�[39m�[0m
�[0m �[90m 5 | �[39m    runServer�[33m:�[39m require(�[32m'./runServer'�[39m)�[0m
�[0m �[90m 6 | �[39m}�[33m;�[39m�[0m
�[0m �[90m 7 | �[39m�[0m

  �[2mat Resolver.resolveModule (�[22m�[0m�[36m../../node_modules/jest-resolve/build/index.js�[39m�[0m�[2m:221:17)�[22m
  �[2mat Object.<anonymous> (�[22m�[0m�[36m../upward-spec/suite/index.js�[39m�[0m�[2m:4:21)�[22m
packages/upward-js/lib/__tests__/server.test.js
  �[1m● �[22mTest suite failed to run
Cannot find module './mockGQLService' from 'index.js'

�[0m �[90m 2 | �[39m    assertOnResponse�[33m:�[39m require(�[32m'./assertOnResponse'�[39m)�[33m,�[39m�[0m
�[0m �[90m 3 | �[39m    getScenarios�[33m:�[39m require(�[32m'./getScenarios'�[39m)�[33m,�[39m�[0m
�[0m�[31m�[1m>�[22m�[39m�[90m 4 | �[39m    mockGQLService�[33m:�[39m require(�[32m'./mockGQLService'�[39m)�[33m,�[39m�[0m
�[0m �[90m   | �[39m                    �[31m�[1m^�[22m�[39m�[0m
�[0m �[90m 5 | �[39m    runServer�[33m:�[39m require(�[32m'./runServer'�[39m)�[0m
�[0m �[90m 6 | �[39m}�[33m;�[39m�[0m
�[0m �[90m 7 | �[39m�[0m

  �[2mat Resolver.resolveModule (�[22m�[0m�[36m../../node_modules/jest-resolve/build/index.js�[39m�[0m�[2m:221:17)�[22m
  �[2mat Object.<anonymous> (�[22m�[0m�[36m../upward-spec/suite/index.js�[39m�[0m�[2m:4:21)�[22m

Generated by 🚫 dangerJS

@zetlen zetlen merged commit 0c27d57 into release/2.0 Oct 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants