The adapter referenced in the comments means adapting the jQuery deferred constructor to meet the API in the spec. The way to do so might be as follows (taken more or less from here):
var promisesAplusTests = require("promises-aplus-tests");
var jq = require('jquery');
var jsdom = require('jsdom');
jsdom.env('<p></p>', function(err, window) {
if (err != null) {
throw err;
} else {
var $ = jq(window);
var adapter = {};
adapter.deferred = function() {
var deferred = $.Deferred();
return {
promise: deferred.promise(),
resolve: deferred.resolve.bind( deferred ),
reject: deferred.reject.bind( deferred )
};
};
promisesAplusTests(adapter, function (err) {
// All done; output is in the console.
// Or check `err` for number of failures:
if (err) {
console.log(err);
}
});
}
});
At which point you need to install the dependencies via npm and run the file. Note that using jquery requires a proper document (hence the need for jsdom).
Or you could take the easy route:
- git clone the jquery repo
- cd jquery directory
- npm install
- wait forever for it to finish, ignore all warnings
- npm test -which runs the jquery unit tests (including A+ suite)
Running in the browser, despite the glib comment in the spec readme, will involve some of work. You will need to use a commonJS module loader like browserify. Browserify will shim the native node assertion library and I believe filesystem api. Mocha should work fine in the browser. Then the above code should run.
If you want to avoid node.js entirely (and not just for running the tests)
, you'll have more work to do.
Step 1. Find or write a compatible assertion library and include it in a script tag.
Step 2. Include mocha in a script tag.
Step 3. Write your own stubs for require, assert, fs, etc. Each of those is a question in its own right.
Step 4. Use the adapter code.
Whether its worth doing all that or not to avoid node is your call.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…