Skip to content

Adding more tests#92

Merged
gauntface merged 144 commits into
GoogleChrome:masterfrom
prateekbh:master
Jan 18, 2017
Merged

Adding more tests#92
gauntface merged 144 commits into
GoogleChrome:masterfrom
prateekbh:master

Conversation

@prateekbh
Copy link
Copy Markdown
Collaborator

R: @jeffposnick @addyosmani @gauntface

Adding more tests for background sync queue.
Also working on jsDocs

jeffposnick and others added 30 commits September 25, 2016 22:25
* Deploy to GitHub Pages

* First attempt at jsdoc integration

* Just removing docs for now - creates a lot of noise

* Fixing linting issues
* Deploy to GitHub Pages

* Removing jsdoc and docs

* Fixes unit tests

* Adding browser download to gulpfile

* Minor console log tweak

* Updating selenium assistant to make gulp download work
* First attempt and minified build

* Removing old modules
* Changing minification for babili

* External sourcemap and tidy up of code

* Adding license header file

* Removing unused dep
* Pulling out minified JS Bundle

* Moving to shared build config. Still needs some work

* Moving to modular gulp taks and shared build

* Removing travis typo

* Removing travis TODO
* WIP

* Some more updates to match the latest spec

* Latest sw-routing updates

* Latest sw-runtime-caching updates

* Add .min. to output .js file

* Broadcast cache update changes

* Use .bind() to ensure this is set inside of callback

* Syntax tweaks

* Demo updates

* CacheWrapper => RequestWrapper

* CacheWrapper => RequestWrapper

* Lint cleanup
JSDoc for the sw-broadcast-cache-update project.
buildPath: 'build/test/constants.js',
projectDir: __dirname,
}),
buildJSBundle({
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Are these all being build so they can used in tests?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yeah, is thr a better way to do it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ping to @gauntface for best practices around test builds.


/**
* set the dbName to store the queue and requests
* defaults to defaultDBName
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would there ever be a need to set the database back to the default name?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

not really, but is used to set the DB name first time

import {getDbName} from './background-sync-idb-helper';

/**
* Class which maily interacts with outer service worker
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This doesn't explain what this class does.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

changed, please review

pushIntoQueue({request}) {
assert.isInstance({request}, Request);
this._queue.push({request});
return this._queue.push({request});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is return needed here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yep, it returns the underlying promise.
if the dev wants to catch the error or wants to wait upon it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you update the @return {void} JSDoc to reflect that?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

}

/**
* takes JSON object and return a Request object to be executed by
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Couldn't you say "Takes and object" rather than "takes a JSON object".

The input is parsed as JSON or anything.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ya sure...

* whose maxAge has expired
*
* @memberOf Queue
* @return {void}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: This isn't needed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done, earlier lint was throwing an error

}

/**
* saves the logical queue to DIB
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: IDB not DIB?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

'redirect': 'follow',
};

return queueUtils.getFetchableRequest({idbRequestObject: reqObj})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Whats the difference between get QueueableRequest and getFetchableRequest?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

getQueueableRequest => takes Request and makes it into JSON objec

getFetchableRequest => takes JSON and constructs Request Object

@gauntface
Copy link
Copy Markdown

Looking through the tests, I can see a few places where the constructor values are checked, but I didn't see any testing of queuing requests and make sure they eventually get made and fail requests get re-attempted - do these tests exist or do they still need writing?

@prateekbh
Copy link
Copy Markdown
Collaborator Author

@jeffposnick @gauntface
I got the documentation working and realized the documentation is a real mess in this PR. Apologies for that.

Please suggest how to go about it.
1.) I can scrap the entire PR and redo the documentation
2.) You can review the tests and code change to accept this, while I open another PR for just documentation

@jeffposnick
Copy link
Copy Markdown
Contributor

I wouldn't worry about the documentation as part of this PR. (None of the packages are in great shape, honestly, and that's one of the things we were going to look into tomorrow.)

I'll take another look at the actual code now!

pushIntoQueue({request}) {
assert.isInstance({request}, Request);
this._queue.push({request});
return this._queue.push({request});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you update the @return {void} JSDoc to reflect that?


let bcmanager;
/**
* broadcasts the message with the guven type and url
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"guven" ➡️ "given"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

*
* @param {Object} config
*/
function broadcastMessage(broadcastManager, {type, url}) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These parameters look odd. Can you normalize things so that broadcastManager is take in as a named property in a single Object parameter, alongside type and url?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

* @param {String} hash
* @return {Object} response
*/
async function getResponse(hash) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you wrap hash in an Object parameter, too? I know it's not as useful when there's only one parameter, but it's more confusing to have some methods take Objects and some take position parameters, and it also makes it easier to add in additional parameters later on.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

@prateekbh
Copy link
Copy Markdown
Collaborator Author

@jeffposnick fixed my documentation.
Its pretty decent than earlier
https://github.com/prateekbh/sw-helpers/tree/master/packages/sw-background-sync-queue

@jeffposnick
Copy link
Copy Markdown
Contributor

I didn't have any additional comments about the code that need to be addressed in this PR. Given the scope and history of this PR, I'm fine with merging and addressing follow-ups in smaller chunks.

@gauntface, anything you'd like to see resolved before this PR is merged?

@gauntface gauntface merged commit 86729ff into GoogleChrome:master Jan 18, 2017
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