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

Viewer: Add tests for fileuploader #1184

Merged
merged 5 commits into from
Jan 6, 2017
Merged

Viewer: Add tests for fileuploader #1184

merged 5 commits into from
Jan 6, 2017

Conversation

ebidel
Copy link
Contributor

@ebidel ebidel commented Dec 20, 2016

R: @brendankenny @patrickhulce

Adds tests for viewer's FileUploader class. Part of #1108.

@brendankenny
Copy link
Member

node 4 and 5 can't do default params, even with the --harmony flag, unfortunately

@ebidel
Copy link
Contributor Author

ebidel commented Dec 20, 2016

What do you think I should do here? We'll have to test against the browserified built files, but that doesn't feel very testable.

@ebidel
Copy link
Contributor Author

ebidel commented Dec 20, 2016

I guess we could also update logger.js to remove default args. That's a shame.

@wardpeet
Copy link
Collaborator

@ebidel you could do it the old way with if statements or just run it against compiled source. Only downsize is that it takes longer because you need compilation and error messages will be a bit more cryptic.

@ebidel ebidel added the viewer label Dec 21, 2016
@ebidel
Copy link
Contributor Author

ebidel commented Dec 21, 2016

PTAL. Travis is 😄 again.

@patrickhulce
Copy link
Collaborator

yay tests! but man you and your yarn diffs haha :)

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

this is looking great, and kudos for handling the oddball tests compared to the rest of our pure-node codebase :)

testHelpers.setupGlobals();
});

it('constructor', () => {
Copy link
Member

Choose a reason for hiding this comment

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

it constructors? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

});

it('document responds to drag and drop events', () => {
// TODO: test drop event on document. Callback is not getting called
Copy link
Member

Choose a reason for hiding this comment

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

you can do it.skip() for this so the test can be written and we can easily turn it on if that ever gets fixed. Will probably need to be separate from below assertions for that, though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


const PAGE = fs.readFileSync(path.join(__dirname, '../app/index.html'), 'utf8');

function setupGlobals() {
Copy link
Member

Choose a reason for hiding this comment

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

is there a way we can better isolate this global setup from other tests? Seems like mocha should have some kind of facility for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@ebidel
Copy link
Contributor Author

ebidel commented Dec 21, 2016

PTAL

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

a few more things

it.skip('document responds to drag and drop events', () => {
new FileUploader(_ => {
assert.ok(true, 'file change callback is called after drop event');
done();
Copy link
Member

@brendankenny brendankenny Dec 21, 2016

Choose a reason for hiding this comment

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

nit: no done callback here

const logger = require('../app/src/logger');

function assertUIReset(uploader) {
assert.ok(!logger.el.classList.contains('show'));
Copy link
Member

Choose a reason for hiding this comment

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

how does this get a reference to the logger instance?

Copy link
Member

Choose a reason for hiding this comment

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

oh god, what did you do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logger module creates a singleton to a DOM node and FileUploader uses logger internally to the module. It's a bit crude, but the intent here is a test that checks the state of the DOM. We don't really have another way to check that UI is working as it should.

Copy link
Member

Choose a reason for hiding this comment

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

doesn't that mean logger retains an element from the original jsdom document created, not a new one each time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fine. It's a singleton. Anyways we're not going to change the impl of logger with a PR that adds tests. Let's be happy there are tests coming in :)


// call before other src imports so DOM code that relies on `document` and
// `window` have them defined.
setupGlobals();
Copy link
Member

Choose a reason for hiding this comment

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

can we do this without side effects? Caller just needs to call helper.setupGlobals() before requiring anything that assumes window and document?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's nice not to have to. I'm going to write 6 more test files and they'll have have to do that.

Copy link
Member

Choose a reason for hiding this comment

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

Side effects from require should be avoided whenever possible, so I'd say definitely delete or write a @fileoverview explaining that requiring the file will set those up so it's not a surprise to others writing tests.

Deleting shouldn't require any other changes, though, since you already testHelpers.setupGlobals(); in beforeEach anyways, right? (and all the other test files will have to do the same)

@ebidel
Copy link
Contributor Author

ebidel commented Dec 22, 2016

PTAL

@ebidel
Copy link
Contributor Author

ebidel commented Dec 29, 2016

@patrickhulce if you're on the clock today, can you PTAL?

@ebidel
Copy link
Contributor Author

ebidel commented Jan 5, 2017

Ping. Let's land these tests so I can write some more!

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

reviewww


// call before other src imports so DOM code that relies on `document` and
// `window` have them defined.
setupGlobals();
Copy link
Member

Choose a reason for hiding this comment

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

Side effects from require should be avoided whenever possible, so I'd say definitely delete or write a @fileoverview explaining that requiring the file will set those up so it's not a surprise to others writing tests.

Deleting shouldn't require any other changes, though, since you already testHelpers.setupGlobals(); in beforeEach anyways, right? (and all the other test files will have to do the same)


const PAGE = fs.readFileSync(path.join(__dirname, '../app/index.html'), 'utf8');

function setupGlobals() {
Copy link
Member

Choose a reason for hiding this comment

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

total nit, but maybe a different name than setupGlobals? setupViewJsDom or something terrible like that would be more clear about what it's doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@ebidel
Copy link
Contributor Author

ebidel commented Jan 6, 2017

PTAL

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

⬆️
📁

@brendankenny brendankenny merged commit cd5015a into master Jan 6, 2017
@brendankenny brendankenny deleted the test branch January 6, 2017 00:42
andrewrota pushed a commit to andrewrota/lighthouse that referenced this pull request Jan 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants