Q:

How can you generate a promise in functional teardown if this.async isn't available?

What's the equivalent of calling this.async() in teardown of a function test suite? I'm using this.async() in a test to create a promise that I later resolve and want to move this code into the teardown but it seems that it's not available.
The documentation suggests that the test suite will pause whilst it waits for a promise to be resolved, but I'm not sure how to generate a promise in a teardown that I can call the .resolve() and .reject() functions on.
This is the code I have working in a test:
var dfd = test.async(10000);
var js = "var coverageData = {" +
  "name : name || ''," +
  "lines : $$_l.lines," +
  "runLines : $$_l.runLines," +
  "code : $$_l.code," +
  "allConditions : $$_l.allConditions," +
  "conditions : $$_l.conditions," +
  "allFunctions : $$_l.allFunctions," +
  "runFunctions : $$_l.runFunctions" +
  "};" +
  "return JSON.stringify(coverageData);";
browser.execute(js)
  .then(function(data) {
    console.log("Retrieved coverage data from browser...");
      try {
        var post_options = {
          host: "localhost",
          port: "8082",
          path: "/node-coverage-store",
          method: "POST",
          headers: {
            "Content-Type": "application/json;charset=UTF-8"
          }
        };
        console.log("Posting coverage data...");

        // Set up the request
        var post_req = http.request(post_options, function(res) {
          res.setEncoding("utf8");
          res.on("data", function (data) {
            console.log("Coverage data posted successfully");
            dfd.resolve();
          });
        });
        post_req.on("error", function(e) {
          console.log("Coverage data post failed", e);
          dfd.reject(e);
        });
        post_req.write(data);
        post_req.end();
      }
      catch (e) {
        console.log("An error occurred handling coverage data", e);
      }
    });

How would I instantiate the promise in a teardown?
FYI... I know that Intern includes code coverage capabilities, but they don't meet our specific requirements.

A:

You need to create a promise and return it yourself. You can use your own Promise library, native Promises (if they exist on the platforms you are testing), or you can use 'intern/dojo/Deferred' (but be aware doing this last one will require you to change your tests when the next version is released).

