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

clean-up: break filterRequest out into more functions #26

Closed
groovecoder opened this issue Jul 15, 2016 · 3 comments
Closed

clean-up: break filterRequest out into more functions #26

groovecoder opened this issue Jul 15, 2016 · 3 comments

Comments

@groovecoder
Copy link
Member

Probably into a new module, and then write tests.

@groovecoder
Copy link
Member Author

I've broken some functions out, but I'm having trouble writing tests for background.js because it uses DOM/Web APIs that I guess aren't available in node? E.g.,

lcrouch:blok lcrouch$ ./node_modules/.bin/tape tests/test-background.js
/Users/lcrouch/code/blok/js/background.js:6
var testpilotPingChannel = new BroadcastChannel(TESTPILOT_TELEMETRY_CHANNEL)
                               ^

ReferenceError: BroadcastChannel is not defined

@rpl - any advice on how to test these bits?

@rpl
Copy link
Member

rpl commented Jul 28, 2016

@groovecoder yep,there are at least two strategies that we can use:

inject the dependency explicitly

we can rewrite the module so that any code that uses the BroadcastChannel is inside a function that took the window object as a parameter, e.g.:

exports.backgroundEntryPoint = function({BroadcastChannel}) {
...
}

the real background script will call the function with the background window object as a parameter,
the test will pass an object with a mock/shim/spy BroadcastChannel, e.g.:

node global global

In node you can define new globals by adding them to the global global, eg.:

global.BroadcastChannel = function(...args) {
  this._initArgs = args;
}

// require the module that needs the global after the needed global is defined
var {anExportedFunctionToTest} = require('../js/module-that-uses-the-broadcast-channel');

groovecoder added a commit that referenced this issue Aug 1, 2016
for #26: refactor (some) filterRequest code into modules and test
groovecoder added a commit that referenced this issue Aug 11, 2016
Also, tests and coverage reporting!
groovecoder added a commit that referenced this issue Aug 11, 2016
Also, tests and coverage reporting!
groovecoder added a commit that referenced this issue Aug 15, 2016
Return entityName: null if not found
groovecoder added a commit that referenced this issue Aug 15, 2016
groovecoder added a commit that referenced this issue Aug 18, 2016
Also, tests and coverage reporting!
groovecoder added a commit that referenced this issue Aug 18, 2016
Return entityName: null if not found
groovecoder added a commit that referenced this issue Aug 18, 2016
groovecoder added a commit that referenced this issue Aug 18, 2016
groovecoder added a commit that referenced this issue Aug 18, 2016
for #26: refactor: new getRequestEntity function
@groovecoder
Copy link
Member Author

Closing this. More refactoring/break-out can happen with follow-up issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants