samedi 6 janvier 2018

How to integrate pretender into selenium functional tests of an Ember App?

I have an Ember application that our team built and we have written many automated selenium functional tests. Some of these tests cannot be currently automated because they require failures that are very hard to replicate consistently (such as device failure codes, etc). For these we would like to add fixture data returned with the correct error codes to test the UX display.

I added fetch-pretender and created a serveFixtures call:

import fixtures from './all';
const Pretender = require('fetch-pretender');

let server = null;

export default {
  serveFixtures(options) {
    console.log('serveFixtures called');
    server = new Pretender();

    fixtures.serve(server, options);
    server.get('/l18n/:file', server.passthrough);
    server.get('config/app.json', server.passthrough);

    // Add all other routes as passthrough by default
    server.get('/**', server.passthrough);
    //server.post('/**', server.passthrough);
    server.put('/**', server.passthrough);

    server.unhandledRequest = (verb, path, request) => {
      console.log(`--- Pretender unhandled request - ${verb} ${path} ${request}`);
    };

    server.passthroughRequest = (verb, path, request) => {
      console.log(`--- Pretender passthrough request - ${verb} ${path} ${request}`);
    };

    // console.log(server);
    return server;
  },
};

Basically I pass in the options for the error code that I want to return and it adds that fixture data to the return endpoint.

I can see in the tests that the server is set up correctly when the tests run but it never returns any fixture data and it also never hits any of the passthroughRequest code either.

My best guess is that the server exists in the code but is not actually present in the application itself. I have no idea on how to bridge that gap so I am hoping someone has done this before.

Please note that we do not use the Ember test frame work for our function tests but we do use it for unit tests and integration tests but for that we use a Sinon sandbox stub out and return fixture data or fetch-mock to mock the calls and return fixture data.

Our selenium set up uses the selenium standalone server. When we do component testing of other components, those teams can use a dummy app with pretender to mock calls which is why we want to reuse pretender if possible. However this is the main app that includes these components and we don't really want to add pretender to the builds if possible.




Aucun commentaire:

Enregistrer un commentaire