describe('file reporter', () => {
    var loggedFile;

    function createReporter({sampleId, descriptions, metrics, path}) {
      var bindings = [
        JsonFileReporter.BINDINGS,
        bind(SampleDescription).toValue(new SampleDescription(sampleId, descriptions, metrics)),
        bind(JsonFileReporter.PATH).toValue(path),
        bind(Options.NOW).toValue(() => DateWrapper.fromMillis(1234)),
        bind(Options.WRITE_FILE)
            .toValue((filename, content) => {
              loggedFile = {'filename': filename, 'content': content};
              return PromiseWrapper.resolve(null);
            })
      ];
      return Injector.resolveAndCreate(bindings).get(JsonFileReporter);
    }

    it('should write all data into a file', inject([AsyncTestCompleter], (async) => {
         createReporter({
           sampleId: 'someId',
           descriptions: [{'a': 2}],
           path: 'somePath',
           metrics: {'script': 'script time'}
         })
             .reportSample([mv(0, 0, {'a': 3, 'b': 6})],
                           [mv(0, 0, {'a': 3, 'b': 6}), mv(1, 1, {'a': 5, 'b': 9})]);
         var regExp = RegExpWrapper.create('somePath/someId_\\d+\\.json');
         expect(isPresent(RegExpWrapper.firstMatch(regExp, loggedFile['filename']))).toBe(true);
         var parsedContent = Json.parse(loggedFile['content']);
         expect(parsedContent)
             .toEqual({
               "description":
                   {"id": "someId", "description": {"a": 2}, "metrics": {"script": "script time"}},
               "completeSample": [
                 {
                   "timeStamp": "1970-01-01T00:00:00.000Z",
                   "runIndex": 0,
                   "values": {"a": 3, "b": 6}
                 }
               ],
               "validSample": [
                 {
                   "timeStamp": "1970-01-01T00:00:00.000Z",
                   "runIndex": 0,
                   "values": {"a": 3, "b": 6}
                 },
                 {
                   "timeStamp": "1970-01-01T00:00:00.001Z",
                   "runIndex": 1,
                   "values": {"a": 5, "b": 9}
                 }
               ]
             });
         async.done();
       }));

  });
示例#2
0
 describe('call ProtoViewFactory', () => {
   it('should pass the render protoView', inject([AsyncTestCompleter], (async) => {
     tplResolver.setTemplate(MainComponent, new Template({inline: '<div></div>'}));
     var renderProtoView = createRenderProtoView();
     var expectedProtoView = createProtoView();
     var compiler = createCompiler([renderProtoView], [expectedProtoView]);
     compiler.compile(MainComponent).then((protoView) => {
       var request = protoViewFactory.requests[0];
       expect(request[1]).toBe(renderProtoView);
       async.done();
     });
   }));
   it('should pass the component annotation', inject([AsyncTestCompleter], (async) => {
     tplResolver.setTemplate(MainComponent, new Template({inline: '<div></div>'}));
     var compiler = createCompiler([createRenderProtoView()], [createProtoView()]);
     compiler.compile(MainComponent).then((protoView) => {
       var request = protoViewFactory.requests[0];
       expect(request[0]).toEqual(new Component({selector: 'main-comp'}));
       async.done();
     });
   }));
   it('should pass the directive bindings', inject([AsyncTestCompleter], (async) => {
     tplResolver.setTemplate(MainComponent, new Template({
       inline: '<div></div>',
       directives: [SomeDecoratorDirective]
     }));
     var compiler = createCompiler([createRenderProtoView()], [createProtoView()]);
     compiler.compile(MainComponent).then((protoView) => {
       var request = protoViewFactory.requests[0];
       var binding = request[2][0];
       expect(binding.key.token).toBe(SomeDecoratorDirective);
       async.done();
     });
   }));
   it('should use the protoView of the ProtoViewFactory', inject([AsyncTestCompleter], (async) => {
     tplResolver.setTemplate(MainComponent, new Template({inline: '<div></div>'}));
     var renderProtoView = createRenderProtoView();
     var expectedProtoView = createProtoView();
     var compiler = createCompiler([renderProtoView], [expectedProtoView]);
     compiler.compile(MainComponent).then((protoView) => {
       expect(protoView).toBe(expectedProtoView);
       async.done();
     });
   }));
 });
  describe('WebDriverExtension.bindTo', () => {

    it('should bind the extension that matches the capabilities',
       inject([AsyncTestCompleter], (async) => {
         createExtension(['m1', 'm2', 'm3'], {'browser': 'm2'})
             .then((m) => {
               expect(m.id).toEqual('m2');
               async.done();
             });
       }));

    it('should throw if there is no match', inject([AsyncTestCompleter], (async) => {
         PromiseWrapper.catchError(createExtension(['m1'], {'browser': 'm2'}), (err) => {
           expect(isPresent(err)).toBe(true);
           async.done();
         });
       }));
  });
示例#4
0
  describe('Location', () => {

    var browserLocation, location;

    function makeLocation(baseHref: string = '/my/app', binding: any = CONST_EXPR([])): Location {
      browserLocation = new DummyBrowserLocation();
      browserLocation.internalBaseHref = baseHref;
      let injector = Injector.resolveAndCreate(
          [Location, bind(BrowserLocation).toValue(browserLocation), binding]);
      return location = injector.get(Location);
    }

    beforeEach(makeLocation);

    it('should normalize relative urls on navigate', () => {
      location.go('user/btford');
      expect(browserLocation.path()).toEqual('/my/app/user/btford');
    });

    it('should not prepend urls with starting slash when an empty URL is provided',
       () => { expect(location.normalizeAbsolutely('')).toEqual(browserLocation.getBaseHref()); });

    it('should not prepend path with an extra slash when a baseHref has a trailing slash', () => {
      let location = makeLocation('/my/slashed/app/');
      expect(location.normalizeAbsolutely('/page')).toEqual('/my/slashed/app/page');
    });

    it('should not append urls with leading slash on navigate', () => {
      location.go('/my/app/user/btford');
      expect(browserLocation.path()).toEqual('/my/app/user/btford');
    });

    it('should remove index.html from base href', () => {
      let location = makeLocation('/my/app/index.html');
      location.go('user/btford');
      expect(browserLocation.path()).toEqual('/my/app/user/btford');
    });

    it('should normalize urls on popstate', inject([AsyncTestCompleter], (async) => {
         browserLocation.simulatePopState('/my/app/user/btford');
         location.subscribe((ev) => {
           expect(ev['url']).toEqual('/user/btford');
           async.done();
         })
       }));

    it('should normalize location path', () => {
      browserLocation.internalPath = '/my/app/user/btford';
      expect(location.path()).toEqual('/user/btford');
    });

    it('should use optional base href param', () => {
      let location = makeLocation('/', bind(appBaseHrefToken).toValue('/my/custom/href'));
      location.go('user/btford');
      expect(browserLocation.path()).toEqual('/my/custom/href/user/btford');
    });
  });
示例#5
0
 describe('switch value changes', () => {
   it('should switch amongst when values', inject([TestBed, AsyncTestCompleter], (tb, async) => {
     var template = '<div>' + '<ul [switch]="switchValue">' + '<template [switch-when]="\'a\'"><li>when a</li></template>' + '<template [switch-when]="\'b\'"><li>when b</li></template>' + '</ul></div>';
     tb.createView(TestComponent, {html: template}).then((view) => {
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('');
       view.context.switchValue = 'a';
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when a');
       view.context.switchValue = 'b';
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when b');
       async.done();
     });
   }));
   it('should switch amongst when values with fallback to default', inject([TestBed, AsyncTestCompleter], (tb, async) => {
     var template = '<div>' + '<ul [switch]="switchValue">' + '<li template="switch-when \'a\'">when a</li>' + '<li template="switch-default">when default</li>' + '</ul></div>';
     tb.createView(TestComponent, {html: template}).then((view) => {
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when default');
       view.context.switchValue = 'a';
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when a');
       view.context.switchValue = 'b';
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when default');
       async.done();
     });
   }));
   it('should support multiple whens with the same value', inject([TestBed, AsyncTestCompleter], (tb, async) => {
     var template = '<div>' + '<ul [switch]="switchValue">' + '<template [switch-when]="\'a\'"><li>when a1;</li></template>' + '<template [switch-when]="\'b\'"><li>when b1;</li></template>' + '<template [switch-when]="\'a\'"><li>when a2;</li></template>' + '<template [switch-when]="\'b\'"><li>when b2;</li></template>' + '<template [switch-default]><li>when default1;</li></template>' + '<template [switch-default]><li>when default2;</li></template>' + '</ul></div>';
     tb.createView(TestComponent, {html: template}).then((view) => {
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when default1;when default2;');
       view.context.switchValue = 'a';
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when a1;when a2;');
       view.context.switchValue = 'b';
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when b1;when b2;');
       async.done();
     });
   }));
 });
示例#6
0
 describe("valueChanges", () => {
   var a,
       c1,
       c2;
   beforeEach(() => {
     c1 = new Control("old1");
     c2 = new Control("old2");
     a = new ControlArray([c1, c2]);
   });
   it("should fire an event after the value has been updated", inject([AsyncTestCompleter], (async) => {
     ObservableWrapper.subscribe(a.valueChanges, (value) => {
       expect(a.value).toEqual(['new1', 'old2']);
       expect(value).toEqual(['new1', 'old2']);
       async.done();
     });
     c1.updateValue("new1");
   }));
   it("should fire an event after the control's observable fired an event", inject([AsyncTestCompleter], (async) => {
     var controlCallbackIsCalled = false;
     ObservableWrapper.subscribe(c1.valueChanges, (value) => {
       controlCallbackIsCalled = true;
     });
     ObservableWrapper.subscribe(a.valueChanges, (value) => {
       expect(controlCallbackIsCalled).toBe(true);
       async.done();
     });
     c1.updateValue("new1");
   }));
   it("should fire an event when a control is removed", inject([AsyncTestCompleter], (async) => {
     ObservableWrapper.subscribe(a.valueChanges, (value) => {
       expect(value).toEqual(['old1']);
       async.done();
     });
     a.removeAt(1);
   }));
   it("should fire an event when a control is added", inject([AsyncTestCompleter], (async) => {
     a.removeAt(1);
     ObservableWrapper.subscribe(a.valueChanges, (value) => {
       expect(value).toEqual(['old1', 'old2']);
       async.done();
     });
     a.push(c2);
   }));
 });
示例#7
0
 describe('.head()', () => {
   it('should perform a head request for given url', inject([AsyncTestCompleter], async => {
        ObservableWrapper.subscribe(backend.connections, c => {
          expect(c.request.method).toBe(RequestMethods.HEAD);
          backend.resolveAllConnections();
          async.done();
        });
        ObservableWrapper.subscribe(http.head(url), res => {});
      }));
 });
示例#8
0
 describe('.delete()', () => {
   it('should perform a delete request for given url', inject([AsyncTestCompleter], async => {
        backend.connections.subscribe((c) => {
          expect(c.request.method).toBe(RequestMethods.DELETE);
          backend.resolveAllConnections();
          async.done();
        });
        http.delete(url).subscribe(res => {});
      }));
 });
      describe('frame metrics', () => {
        it('should report ImplThreadRenderingStats as frame event',
           inject([AsyncTestCompleter], (async) => {
             createExtension([
               benchmarkEvents.instant('BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
                                       {'data': {'frame_count': 1}})
             ])
                 .readPerfLog()
                 .then((events) => {
                   expect(events).toEqual([
                     normEvents.create('i', 'frame', 1.1),
                   ]);
                   async.done();
                 });
           }));

        it('should not report ImplThreadRenderingStats with zero frames',
           inject([AsyncTestCompleter], (async) => {
             createExtension([
               benchmarkEvents.instant('BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
                                       {'data': {'frame_count': 0}})
             ])
                 .readPerfLog()
                 .then((events) => {
                   expect(events).toEqual([]);
                   async.done();
                 });
           }));

        it('should throw when ImplThreadRenderingStats contains more than one frame',
           inject([AsyncTestCompleter], (async) => {
             PromiseWrapper.catchError(
                 createExtension([
                   benchmarkEvents.instant('BenchmarkInstrumentation::ImplThreadRenderingStats',
                                           1100, {'data': {'frame_count': 2}})
                 ]).readPerfLog(),
                 (err) => {
                   expect(() => { throw err; })
                       .toThrowError('multi-frame render stats not supported');
                   async.done();
                 });
           }));
      });
示例#10
0
    describe('css', () => {
      it('should load inline styles', inject([AsyncTestCompleter], (async) => {
           var template = new ViewDefinition({template: 'html', styles: ['style 1', 'style 2']});
           loader.load(template).then((el) => {
             expect(DOM.getInnerHTML(el))
                 .toEqual(
                     '<style type="text/css">style 1</style><style type="text/css">style 2</style>html');
             async.done();
           });
         }));

      it('should load templates through XHR', inject([AsyncTestCompleter], (async) => {
           xhr.expect('base/foo.html', 'xhr template');
           xhr.expect('base/foo-1.css', '1');
           xhr.expect('base/foo-2.css', '2');
           var template = new ViewDefinition({
             templateAbsUrl: 'base/foo.html',
             styles: ['i1'],
             styleAbsUrls: ['base/foo-1.css', 'base/foo-2.css']
           });
           loader.load(template).then((el) => {
             expect(DOM.getInnerHTML(el))
                 .toEqual(
                     '<style type="text/css">i1</style><style type="text/css">1</style><style type="text/css">2</style>xhr template');
             async.done();
           });
           xhr.flush();
         }));

      it('should return a rejected Promise when XHR loading fails',
         inject([AsyncTestCompleter], (async) => {
           xhr.expect('base/foo.css', null);
           var template = new ViewDefinition({template: '', styleAbsUrls: ['base/foo.css']});
           PromiseWrapper.then(loader.load(template), function(_) { throw 'Unexpected response'; },
                               function(error) {
                                 expect(error.message)
                                     .toEqual('Failed to fetch url "base/foo.css"');
                                 async.done();
                               });
           xhr.flush();
         }));
    });