-
Notifications
You must be signed in to change notification settings - Fork 143
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
Serialize in mocha #180
base: main
Are you sure you want to change the base?
Serialize in mocha #180
Conversation
The first 8 tests has been ported. The reference and source files has been moved into sample_files folder
7433fe0
to
5353a06
Compare
The converter for json+ld files is async and require a callback a function to work. Luckily we just needed to work around it with promises in the test.helper. T11, 12, 13 have problems with BlankNodes ids. This was related to async code not being inside "it"s
Don't place anything outside "it" in asynchronous testing, or it will be all jammed together with unpredictable consequences. Place all your code inside its. trying to solve test 13 Fixed linux testing Fixed t13
Removed all typescript dependencies. Parallelized all tests. Tidied up the serializaton test folder. Introduced and setted eslint with config file. Uri should now be consistent in windows and Linux. You can still add "wrong" uris, but you don't have to to make xhr work under windows.
5353a06
to
2eb096a
Compare
@Neur0mante thank you! Tell us more about the |
package.json
Outdated
"n3": "^0.4.1", | ||
"xmldom": "^0.1.22", | ||
"xmlhttprequest": "^1.7.0" | ||
"xmlhttprequest": "1.8.0", | ||
"bluebird": "3.5.0" |
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 the usage of Bluebird, instead of native promises?
package.json
Outdated
@@ -30,9 +30,11 @@ | |||
"dependencies": { | |||
"async": "^0.9.x", | |||
"jsonld": "^0.4.5", | |||
"mz": "^2.6.0", |
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.
Since you're only using mz
in tests, this should go in devDependencies. Also, I'd prefer it if you used fs-extra
instead.
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'm using mz for the promisified version of the load and write. We could promisify fs-extra by:
const Promise = require('bluebird')
const fs = Promise.promisifyAll(require('fs-extra'))
(which I think was probably the reason why I started to use bluebird promises in the first place)
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.
Yeah, I do hate that fs-extra
doesn't offer a native promise-based interface (and instead outsources that to promisify). :(
Ok, so, might as well keep mz
(though move it to devDependencies), and remove the Bluebird dep.
package.json
Outdated
"diff": "^3.2.0", | ||
"eslint": "^3.18.0", |
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 are these for? The standard
dep pulls these in, usually.
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 wasn't sure if you could define .eslintrc files by using the standard
rep so I was doing it backwards by extending the standard-plugin, but yeah I can reverse that.
tests/serialize/sample_files/diff.js
Outdated
|
||
data1 = data1.replace(/\r\n?/g, '\n') | ||
data2 = data2.replace(/\r\n?/g, '\n') | ||
console.log(data1) |
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.
Stray console.log()?
src/fetcher.js
Outdated
@@ -585,17 +585,18 @@ var Fetcher = function Fetcher (store, timeout, async) { | |||
// Returns promise of XHR | |||
// | |||
// Writes back to the web what we have in the store for this uri | |||
this.putBack = function (uri, options = {}) { |
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 the removal of default arguments here and on line 597?
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 thought this came from a linter warning but it actually probably just came from a diff with an older version of the fetcher.
I'll break down the .eslintrc here Of these only mocha is actually necessary: These are for the tabulator plugin for firefox that pop out here and there:
is it still supported by the way? Otherwise we could remove all those checks. rules": {
There are so many variable/classes that are not camelcased that this is mostly an annyoiance. Same thing with unused vars. |
@Neur0mante re |
Sorry I'm used to ctrl+enter to insert a new line from everywhere I wasn't actually done breaking it down |
es6 is also needed, I'm testing without it and it's complaining about const, import etc... |
What's complaining about |
nevermind. It was because I removed the extends="standard" from the .eslintrc |
This should do
|
Walk me through it, though. What is the .eslintrc for, over out of the box standard? |
Without the mocha env Same problem here, these are for the tabulator plugin for firefox that pops out here and there:
is it still supported by the way? Otherwise we could remove all those checks.
There are so many variable/classes that are not camelcased that this is mostly an annyoiance. Same thing with unused vars.
|
The mocha env part and the warnings about the globals are handled in the standard: globals section of In the case of 👎 to enforcing array spacing, or silencing unused warnings. |
To clarify, you should instead add "it" and "describe" to the standard: globals: section of package.json. |
(I see what you mean about camelcasing warnings, there are a bunch of snake-cased variables in this library due to it being transpiled from Python.) |
for latest sdandardjs & chai see: standard/standard#690 (comment) I ended up using it this way // expect.js
import chai from 'chai'
import dirtyChai from 'dirty-chai'
chai.use(dirtyChai)
export default chai.expect // fooTest.js
import expect from './expect' |
That looks good, turning all those calls into actual functions makes more sense. With should it plugs in automatically with chai.should() right? It seems to be working. "no-unused-vars": "warn" was just turning those from errors to warning, but it's not a big issue. |
It should be fine now. |
@Neur0mante I think the correction is fine, yes (re triple equals) |
I wanted to convert the serialize tests to mocha, and while doing that I had to perform some fixes here and there so this ended up as quite a wide PR.
List of modifications:
Added a .eslintrc configuration file extending standard. I've tried to specify the rules so it would have the least impact with existing code. I think it would be a good idea to have this shared in the github.
Moved all the files we are using for the serialization tests in sample_files folder for cleanliness.
There are a few changes to the fetcher. Most were brought up by the linter.
There were various instances of
I don't think the triple equal is intended am I missing something?
I added a check for windows so that we feed the xhr with two slashes URIs while keeping three slashes in the kb. It's still possible to insert file URIs with two slashes, but it's no longer necessary to make it work correctly under windows.
I've written a test helper which incorporates the functionalities from data.js operating mostly using promises so it can be used asynchronously under mocha.
I've converted all the current serialization tests into mocha. They are all under the serialization.spec.js file. They work under win and Linux, they will show diffing in case of errors, they will exit with error in case of a mismatch.
This is a pretty bare conversion but there are some more accurate testing for the loaded files in it.
chai-as-promised allow to work seeminglessly with promises so it's pretty clean and it should all run asynchronously so the suite is relatively fast overall.
I made the 9th test work through promises since the json+ld converter is async