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

Modernize & cleanup #72

Merged
merged 4 commits into from
Sep 6, 2017
Merged

Conversation

gmaclennan
Copy link
Contributor

Should fix #40 #41 #42 #54 #59 #65 #68

This is based upon the original source code and api from v1.2.5. This is the same code that is published in the latest v1.3.8.

I don't know webpack, but this should work fine webpack if you use that, would be great if someone could test it.

I have kept the API from v1.2.5 and code logic is largely the same, the changes are mainly to restructure the code as commonJS modules, and update code formatting (to match the latest .eslintrc in the project (with changes to work with the latest eslint v3.9.1). The code changes are:

  • client fingerprints (browser and server) are cached rather than calculated each time, since they do not change.
  • Should work in WebWorkers and ServiceWorkers now - it uses self if window is undefined.
  • Very simple fix for react-native which apparently does not have userAgent or mimeTypes defined. This id does not probably change much between clients, so we should have something with better entropy.

I threw away many of the changes in master, which used ES2016 and required a complicated build process with transforms etc. The project should now be a lot simpler.

Browser builds rely on the browser field in package.json which is supported by both browserify and webpack.

Standalone UMD builds are created in dist which is excluded from the git repo but included in npm, so that they will be available from https://unpkg.com/cuid/dist/cuid.js https://unpkg.com/cuid/dist/cuid.min.js once this package is published to npm. The build script runs as a prepublish script, so it should require nothing more than npm publish.

Tests are running and passing locally and on saucelabs. Hopefully travis-ci should just work.

Finally, sorry about the lack of commit messages, but the repo seemed to have drifted a lot from the last published version and there was no logical step-by-step development from the current master.

@gmaclennan gmaclennan mentioned this pull request Nov 10, 2016
@gmaclennan
Copy link
Contributor Author

Looks like saucelabs credentials need updated in .travis.yml.

export SAUCE_USERNAME=username
export SAUCE_ACCESS_KEY=key
sauce_username: my_awesome_username
sauce_key: 550e8400-e29b-41d4-a716-446655440000
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't a real key, is it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If the key comes from .zuulrc, which is not included in the repo, and not encrypted - how do we run the sauce labs tests on Travis?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't a real key, is it?

Nope. Just a random number. I should make that more clear. Copied and pasted from the Zuul wiki.

If the key comes from .zuulrc, which is not included in the repo, and not encrypted - how do we run the sauce labs tests on Travis?

.zuulrc is for contributors who want to run the tests in their own saucelabs account.

For running tests from travis you should store encrypted environment variables following these instructions: https://github.com/defunctzombie/zuul/wiki/Travis-ci

I had assumed the current encrypted env variables in the .travis.yml were for Saucelabs, but seems like they are no longer valid. If you like I could try and set up a saucelabs account for this, unless you already have one. Saucelabs requires a separate account for each opensource project for their free tier.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a Sauce Labs account for this, but as I mentioned in the notes below, it doesn't work for forked PRs.

@@ -0,0 +1,12 @@
var pad = require('./pad.js');

var env = typeof window === 'object' ? window : self;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is self?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

self is a reference to the global scope (equivalent to window) in WebWorkers and ServiceWorkers: https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/self

I looked at a couple of modules designed to work in both a browser context and in WebWorkers and this was the pattern they use.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting. TIL.

Can you add tests for Web Workers and Service Workers?

Copy link

@zargold zargold May 8, 2018

Choose a reason for hiding this comment

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

what about node?

node
> self
ReferenceError: self is not defined
> window
ReferenceError: window is not defined
> global
...

Choose a reason for hiding this comment

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

What about this point? Was this resolved? I get a

var env = typeof window === 'object' ? window : self;
                                                ^

ReferenceError: self is not defined

in node; any suggestions??

@ericelliott
Copy link
Collaborator

ericelliott commented Nov 10, 2016

@gmaclennan
Copy link
Contributor Author

https://docs.travis-ci.com/user/pull-requests#Pull-Requests-and-Security-Restrictions

Just reading through this. It's likely that the encrypted variables in the current .travis.yml are valid saucelabs credentials, it's just that they are not accessible to travis from my PR because it is from a different repo. Hopefully when this is merged to master (or another branch) these tests should just run with those existing credentials.

@ericelliott
Copy link
Collaborator

Any chance we can get a zuul test for the Web Worker/Service Worker fix?

@gmaclennan
Copy link
Contributor Author

I'm not sure this test actually works. I'm not sure whether the TAP output from the worker thread gets back to zuul so that it can confirm the tests are run. This does run the test in a worker, I'm just not sure about how to handle output. I've never run tests in a worker before.

@gmaclennan
Copy link
Contributor Author

A little further info:

When I run zuul locally and run zuul --local 8080 --ui tape -- test/test-worker.js it seems like the test passes, but if I run them both together with a glob it seems to fail: zuul --local 8080 --ui tape -- test/**/*.js

@ericelliott
Copy link
Collaborator

What do we need to do to get these checks passing so we can close all those open issues?

@gmaclennan
Copy link
Contributor Author

Thanks for following up on this.

The tests are currently failing because of failing saucelab credentials, because this is a PR from a different repo. The only way to fix this it to merge this PR into this repo so that the tests can run with the correct credentials.

I suggest merging this PR into a new branch here, checking the tests pass, then merging into master.

The one thing missing is that I don't think the tests for this working in a webworker are actually working - i.e. if the tests fail in a webworker I don't think this currently cause the test output to show failure. However, this PR has better test coverage than the current version even without this.

@nealoke
Copy link

nealoke commented Apr 18, 2017

@ericelliott any update on this? :)

@ericelliott
Copy link
Collaborator

@nealoke @gmaclennan I've invited both of you as collaborators. Feel free to do what you need to do in order to get the tests passing on the main repo.

@nealoke
Copy link

nealoke commented Apr 20, 2017

@ericelliott thanks but i'm not really familiar with the CI tools :( When I have time i'll dive into this!

@ericelliott ericelliott mentioned this pull request Aug 29, 2017
@MarkHerhold
Copy link
Contributor

I put a few hours into trying to get this to work with SauceLabs and have not been able to get consistent results. Would it suffice to run the Karma tests on Chrome Headless (v60) and forget the other browsers? Or perhaps try a different testing service?

These are the errors I am seeing:

31 08 2017 21:00:10.117:WARN [IE 11.0.0 (Windows 8.1 0.0.0)]: Disconnected (1 times), because no message in 10000 ms.
IE 11.0.0 (Windows 8.1 0.0.0) ERROR
  Disconnected, because no message in 10000 ms.

@ericelliott
Copy link
Collaborator

@MarkHerhold I believe you can adjust the timeout. I'd prefer to make sure it works in IE11, because it currently still holds about 13% market share...

@ericelliott
Copy link
Collaborator

I think I'd be OK with running the tests in Chrome headless for now just to get this back on track. We could release it as a breaking change, just to be on the safe side. However, I'd want somebody to test it in IE11 and at least spot check it for us... Do you happen to have IE11 available?

@MarkHerhold
Copy link
Contributor

MarkHerhold commented Sep 1, 2017

@ericelliott I've increased the timeout to 120 seconds (see this commit on my fork) and set retries to two and still have flaky results.

Everyone can download an IE11 VM (and other versions) here.

I checked IE11 manually and the build does indeed work (tested cuid.js).

image

I will work on getting Chrome Headless working on Travis CI.

@ericelliott
Copy link
Collaborator

Looking great. Thanks!

@ericelliott ericelliott merged commit c0c4ed1 into paralleldrive:master Sep 6, 2017
ericelliott added a commit that referenced this pull request Sep 6, 2017
@Flet Flet mentioned this pull request Jan 3, 2018
2 tasks
@ericelliott
Copy link
Collaborator

Published as v2.0.1

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.

navigator is not defined
6 participants