web-platform-tests / wpt

Test suites for Web platform specs — including WHATWG, W3C, and others
https://web-platform-tests.org/
Other
4.91k stars 3.07k forks source link

Isolating tests from HTML #3218

Closed brettz9 closed 8 years ago

brettz9 commented 8 years ago

Some of the web APIs are also very convenient for use in Node.js or elsewhere.

I'm personally interested in IndexedDB (I'm currently working with IndexedDBShim) and would like to have a means of importing the tests without needing to do HTML parsing to extract out the tests and adapt them for Node usage.

If the tests can be structured independently of HTML, it is more likely those of us working on server APIs can contribute back to the tests, as well as to even potentially popularize the use of the web-based APIs in the browser by facilitating code reuse from the server to browser.

Thanks!

dumbmatter commented 8 years ago

FWIW, I did that for the IndexedDB tests last year for exactly the reason you described (running in Node and in the browser, and testing is way faster and more convenient if it doesn't rely on a browser). So you're not the only one who feels that way.

I'm not sure if it's a common enough use case for many people to care about it, though.

brettz9 commented 8 years ago

Given the ubiquity of client-side JavaScript, and the resulting popularity of server-side JavaScript for code reuse, I think that if critical mass can be reached, there is great potential for IndexedDB APIs become available for various databases.

And FYI, another repo did the same thing you mentioned, perhaps indicating at least some other interest out there (not to mentioned indexeddb-js if not others) but I'd like to avoid the maintenance headache of keeping them in sync... And it's not like two duplicate sets of files would need to be maintained...

dumbmatter commented 8 years ago

I hadn't noticed that other project... but it is actually forked from mine :)

Given the ubiquity of client-side JavaScript, and the resulting popularity of server-side JavaScript for code reuse, I think that if critical mass can be reached, there is great potential for IndexedDB APIs become available for various databases.

I kind of agree, that was one of the reasons for my project. I don't know if it's particularly likely because of how painful the IndexedDB API is to use. But that's what they said about JavaScript itself...

brettz9 commented 8 years ago

And, there is the potential for libraries ala jQuery to make it easier on both ends... db.js, Dexie, etc.

brettz9 commented 8 years ago

I think moving the JavaScript into external files alone would be useful, as one might be able to monkey-patch the rest to work with Node. I also like using the same exact testing framework and support methods. Would there be openness to a PR? If so, I assume just adding them to a "js" child directory would be fine?

brettz9 commented 8 years ago

For now, I'm using cheerio to just extract the script content into their own files and see if I can adapt (monkey-patching where possible) the testing library to run the files in Node.

brettz9 commented 8 years ago

FWIW, I've integrated this stand-off approach into master of IndexedDBShim (in the "test-support" directory with web-platform-tests as a submodule).