-
Notifications
You must be signed in to change notification settings - Fork 24
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
Fix failing tests across browsers #9
Conversation
I moved the test file into a separate folder, and I'm trying to adapt the scripts in |
Everything else is ready. |
1bc4667
to
dceaeda
Compare
@kof I did some changes in the last hour, in case you were already checking out this PR. |
@@ -0,0 +1,15 @@ | |||
import * as bowser from 'bowser' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Started to use https://github.com/cssinjs/jss-vendor-prefixer/blob/master/package.json#L52 for this, is bowser better, should we have one consistent dep for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at both projects, bowser looks more mature, well tested, and actively maintained. I would change to bowser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -1,2 +1,2 @@ | |||
const context = require.context('./src', true, /\.test\.js$/) | |||
const context = require.context('./test', true, /\.test\.js$/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it was fine before, "test" dir dosn't exist how can this work?
The "tests" dir is generated in order to run tests from the main repo, as we probably not going to do this for this repo, we can remove build:tests:lib and build:tests and just rename build:tests:local to build:tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved src/index.test.js
to test/integration.test.js
and added a helper file test/utils.js
.
What is the purpose of build:tests:local
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, lets keep index.test in /src and add /test/utils.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build:tests:local is to run it via tests.html in the browser, sometimes you need that for better debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok got it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you want to keep the file in src/index.test.js
? For me this indicates that it is an unit test
only for the index file
, but it is an integration test
for the whole project. For me that's a bit confusing. What if you were to add unit tests in the future?
if (prop !== 'animation') { | ||
expect(prop).to.be(`${prefix.css}animation`) | ||
} | ||
browser("requires prefix for transform property", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think this way is sort of a hack. A real good solution would be to compare results in every browser with already known predefined results from caniuse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a hack? I used the values from caniuse as they are static and won't ever change, there is no need to query the api and introduce another dependency that could break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You take specific browsers, where you know the outcome and you do an assertion with expected output. You selectively run an assertion. Not really a hack, but could be better: we run always the assertion and compare the results with the result expected in a certain browser. Without maintaining the versions etc. Just get the result for the current browser from caniuse (not http api, there is a static version) and then compare it with what we got from the browser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean. I'll checkout how complicated it is to use the api directly.
dceaeda
to
00e75b2
Compare
cc3eacb
to
ad88c0d
Compare
I'm finally done. This one was really tricky. Currently mocha report suffers from this issue: litixsoft/karma-mocha-reporter#84. |
I think I saw that bug as well, but didn't dig to understand whats going on there. |
06b1284
to
11d6055
Compare
I just fixed some remaining linter errors. |
* @param {String} feature - see full list https://github.com/Fyrd/caniuse/tree/master/features-json | ||
* @returns {{level: 'unknown' | 'none' | 'partial' | 'full', needPrefix: boolean}} | ||
*/ | ||
export function getSupport(feature) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, that sounds complex, I wonder why nobody did this logic before ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This library you mentioned earlier doesn't work in the browser: https://github.com/Nyalab/caniuse-api and there was no other library around. Had to do it myself ^^
* @param {String} feature - see full list https://github.com/Fyrd/caniuse/tree/master/features-json | ||
* @returns {{level: 'unknown' | 'none' | 'partial' | 'full', needPrefix: boolean}} | ||
*/ | ||
export function getSupport(feature) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wondering how we can reuse that logic across projects, for e.g. I know for sure it is needed in jss-vendor-prefixer as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we release a separate package, which will wrap caniuse db and provide the api we need for this sort of testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea. I'll setup a separate package tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, lets wait with the merge then.
Well we can refactor file names any time, its easy. For now I started to use that fileName.test.js convention in all plugins where we don't separate integration and unit tests. Also if they are small integration and unit tests can be all in the same file, normally people separate them in large projects when speed of running tests becomes a problem.
|
I see, I was just curious for the reason. |
11d6055
to
d1b0f65
Compare
Almost done. Waiting for some free slots on your browserstack account to fix remaining issues if any. |
Everything passed! 👍 Check out the new package at https://github.com/wikiwi/caniuse-support. |
d1b0f65
to
d16a568
Compare
Awesome |
}) | ||
|
||
config.browserStack = { | ||
username: browserStackUserName, | ||
accessKey: browserStackAccessKey, | ||
captureTimeout: 10000 | ||
captureTimeout: 3e5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is 300000ms, tests may stuck for a long time with such a timeout, the values I had there was what I tried is the best considered browserstack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See this issue: karma-runner/karma-browserstack-launcher#61.
I had issues with testing on the mobile android device which got restarted on every run and then got stuck forever. I had to kill the worker on each run manually in order to free the slot again. I took the values from the issue above, which are supposed to be timeout values given by the browserstack support.
|
||
import {prefix, supportedProperty, supportedValue} from './index' | ||
|
||
console.log(`Detected browser: ${currentBrowser.id} ${currentBrowser.version}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe disbable eslint just for this line, because its very likely that we forget console.log statements after debugging and now lint won't warn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do that.
if (prop !== 'animation') { | ||
expect(prop).to.be(`${prefix.css}animation`) | ||
} | ||
it('should prefix if needed', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason why you prefer to have "function" here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I see, you need this.skip
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise I cannot call this.skip()
.
Hmmm ok then.
|
Looks good. We can merge it. One more idea would be to generate tests for every known property and do those checks. This way we know if anything else goes wrong. |
d16a568
to
4850e5d
Compare
What we can do is to map property names to the appropriate caniuse feature name, and use this to run our prefix test. Here is a list we could rely on for which properties to test: http://shouldiprefix.com/ Let's leave this up to a following PR, and merge this first. Suggestions have been applied. |
merged |
Just looking at the travis build, I noticed that currently |
u sure? It should only do install which runs the tests
yes, but only if you are installing it in a cloned repository, not if it is a dependency, so it is only for css-vendor developers the case |
I think npm recently fixed that by adding a separate hook for what we need, the intend was always to test before publishing, not all the other cases. Also there is a separate package which solves this problem. Need to do that for all repos though. |
Travis just ran test twice during |
hmm, where does install and test come from, it should be just install |
Alternatively you can think about publishing using travis.
|
That's the default travis behavior. |
Shit))) we need to fix that, running tests twice on jss repo as well then. And yes, seems to be a good idea to publish the package over travis. |
Oh actually we may be able to say what to run in travis.yaml. |
Yes, if you define the |
yeah, so we need either this or publish over travis. I tend to publish over travis and remove the prepublish thing then. |
I recommend publishing over travis too 👍 |
My mistake before: I wrote E.g. in this project I just run |
Related cssinjs/jss#89