Beispiel #1
0
 def configure(self, options, conf):
     super(JSTests, self).configure(options, conf)
     if not self.enabled:
         return
     self.options = options
     if not self.options.jstests_server:
         self.parser.error("Missing --jstests-server")
     if not self.options.jstests_suite:
         self.parser.error("Missing --jstests-suite")
     if not self.options.jstests_browsers:
         self.parser.error("Missing --jstests-browsers")
     if not self.options.jstests_token:
         self.parser.error("Missing --jstests-token")
     self.started = False
     self.conn = Connection(self.options.jstests_server)
Beispiel #2
0
class JSTests(Plugin):
    """Run JavaScript tests using a JS TestNet server."""
    name = 'jstests'

    def options(self, parser, env=os.environ):
        super(JSTests, self).options(parser, env=env)
        parser.add_option('--jstests-server', action="store",
                          help='http://jstestnet-server/')
        parser.add_option('--jstests-suite', action="store",
                          help='Name of test suite to run')
        parser.add_option('--jstests-url', action="store",
                          help='URL of the QUnit test suite')
        parser.add_option('--jstests-token', action="store",
                          help='Security token to start this test suite')
        parser.add_option('--jstests-browsers', action="store",
                          help=('Comma separated list of browsers to run '
                                'tests against, see JS TestNet docs for '
                                'details. Example: '
                                'firefox=~3,firefox=~4,chrome'))
        parser.add_option('--jstests-restart', action="store_true",
                          help=('Restarts all browser workers '
                                'before running tests.'))
        self.parser = parser

    def configure(self, options, conf):
        super(JSTests, self).configure(options, conf)
        if not self.enabled:
            return
        self.options = options
        if not self.options.jstests_server:
            self.parser.error("Missing --jstests-server")
        if not self.options.jstests_suite:
            self.parser.error("Missing --jstests-suite")
        if not self.options.jstests_browsers:
            self.parser.error("Missing --jstests-browsers")
        if not self.options.jstests_token:
            self.parser.error("Missing --jstests-token")
        self.started = False
        self.conn = Connection(self.options.jstests_server)

    def loadTestsFromDir(self, directory):
        if self.started:
            # hijacking loadTestsFromDir to run tests once
            # and only once.
            return
        self.started = True
        if self.options.jstests_restart:
            resp = self.conn.get('/restart_workers')
            log.debug('Restarted %s worker(s)' % resp['workers_restarted'])
        log.debug('Starting %r [%s] %s' % (self.options.jstests_suite,
                                           self.options.jstests_server,
                                           self.options.jstests_browsers))

        tests = self.conn.run_tests(self.options.jstests_suite,
                                    self.options.jstests_token,
                                    self.options.jstests_browsers,
                                    self.options.jstests_url)
        for test in tests['results']:
            successful = True
            # TODO(Kumar) find a way to not parse results twice.
            for assertion in test['assertions']:
                if not assertion['result']:
                    successful = False
                    break
            yield JSTestCase(test)
            if self.result.shouldStop and not successful:
                break

    def prepareTestResult(self, result):
        self.result = result