setTimeout(() => {
   assert.match(printed[0], /error/);
   console.error = oldError;
   done();
 }, 10);
 it("does not add the bot user", () => {
     const handler = new PresenceHandler(bot as DiscordBot);
     handler.EnqueueUser(new MockUser("1234", "def") as any);
     Chai.assert.equal(handler.QueueCount, 0);
 });
 it('match #3: should correctly append custom node into the obfuscated code', () => {
     assert.match(obfuscatedCode, consoleWarnRegExp);
 });
 it("should not do anything if same order given (same object, shallow equality)", ()=>{
     const order = "0,1,2,3,4".split(",");
     transitionSortConfig({sortConfig:{order}},{sortConfig:{order}}, oncoprint);
     assert.equal(oncoprint.setSortConfig.callCount, 0);
 });
 it("should not do anything if heatmap index specified, same heatmap index specified before", ()=>{
     transitionSortConfig({sortConfig:{clusterHeatmapTrackGroupIndex:2}}, {sortConfig:{clusterHeatmapTrackGroupIndex:2}}, oncoprint);
     assert.equal(oncoprint.setSortConfig.callCount, 0);
 });
 it("should return 2 for one empty input and one with two (both added/deleted)", ()=>{
     assert.equal(numTracksWhoseDataChanged([{key:"a", data:[]},{key:"b", data:[]}], []), 2, "tracks added");
     assert.equal(numTracksWhoseDataChanged([], [{key:"a", data:[]},{key:"b", data:[]}]), 2, "tracks deleted");
 });
 it("should not do anything if no sortConfig specified", ()=>{
     transitionSortConfig({}, {}, oncoprint);
     assert.equal(oncoprint.setSortConfig.callCount, 0);
 });
            it('accepts a single argument of the name', () => {

                var annotation = new annotations.FieldAnnotation("test");
                assert.equal(annotation.name, "test");
                assert.isUndefined(annotation.nullable);
            });
Example #9
0
 it("handles no failures", () => {
     const result = JSON.parse(formatter.format([]));
     assert.deepEqual(result, []);
 });
 }).then((result) => {
   assert.deepEqual(result.data, data);
 });
            it('accepts an object that can include the name and nullable properties', () => {

                var annotation = new annotations.FieldAnnotation({ name: "test2", nullable: true });
                assert.equal(annotation.name, "test2");
                assert.isTrue(annotation.nullable);
            });
 return handle.result().then((result) => {
   assert.equal(result.data['luke'].name, 'Luke Skywalker');
   assert.notProperty(result.data, 'vader');
 });
  it('allows you to refetch queries with new variables', (done) => {
    const query = gql`
      {
        people_one(id: 1) {
          name
        }
      }
    `;

    const data1 = {
      people_one: {
        name: 'Luke Skywalker',
      },
    };

    const data2 = {
      people_one: {
        name: 'Luke Skywalker has a new name',
      },
    };

    const data3 = {
      people_one: {
        name: 'Luke Skywalker has a new name',
      },
    };

    const variables = {
      test: 'I am your father',
    };

    const networkInterface = mockNetworkInterface(
      {
        request: { query: query },
        result: { data: data1 },
      },
      {
        request: { query: query },
        result: { data: data2 },
      },
      {
        request: { query: query, variables },
        result: { data: data2 },
      }
    );

    const queryManager = new QueryManager({
      networkInterface,
      store: createApolloStore(),
      reduxRootKey: 'apollo',
    });

    let handleCount = 0;

    const handle = queryManager.watchQuery({
      query: query,
    });

    const subscription = handle.subscribe({
      next(result) {
        handleCount++;

        if (handleCount === 1) {
          assert.deepEqual(result.data, data1);
          subscription.refetch();
        } else if (handleCount === 2) {
          assert.deepEqual(result.data, data2);
          subscription.refetch(variables);
        } else if (handleCount === 3) {
          assert.deepEqual(result.data, data3);
          done();
        }
      },
    });
  });
 subscription.refetch().then((result) => {
   assert.deepEqual(result.data, data2);
   done();
 });
    it("rejects angular properties if syntax disabled", () => {
        parser.angularSyntax = false;
        parser.parse("<TextField [text]='somevalue' />");

        assert.isFalse(last_attrs);
    });
Example #16
0
    it("formats failures", () => {
        const maxPosition = sourceFile.getFullWidth();

        const failures = [
            createFailure(sourceFile, 0, 1, "first failure", "first-name", undefined, "error"),
            createFailure(sourceFile, maxPosition - 1, maxPosition, "last failure", "last-name", undefined, "error"),
            createFailure(
                sourceFile, 0, maxPosition, "full failure", "full-name",
                new Replacement(0, 0, ""),
                "error"),
        ];

        /* tslint:disable:object-literal-sort-keys */
        const expectedResult: IRuleFailureJson[] = [
            {
                name: TEST_FILE,
                failure: "first failure",
                startPosition: {
                    position: 0,
                    line: 0,
                    character: 0,
                },
                endPosition: {
                    position: 1,
                    line: 0,
                    character: 1,
                },
                ruleName: "first-name",
                ruleSeverity: "ERROR",
            },
            {
                name: TEST_FILE,
                failure: "last failure",
                startPosition: {
                    position: maxPosition - 1,
                    line: 5,
                    character: 2,
                },
                endPosition: {
                    position: maxPosition,
                    line: 6,
                    character: 0,
                },
                ruleName: "last-name",
                ruleSeverity: "ERROR",
            },
            {
                name: TEST_FILE,
                failure: "full failure",
                fix: {
                    innerLength: 0,
                    innerStart: 0,
                    innerText: "",
                },
                startPosition: {
                    position: 0,
                    line: 0,
                    character: 0,
                },
                endPosition: {
                    position: maxPosition,
                    line: 6,
                    character: 0,
                },
                ruleName: "full-name",
                ruleSeverity: "ERROR",
            },
        ];
        /* tslint:enable:object-literal-sort-keys */

        const actualResult = JSON.parse(formatter.format(failures));
        assert.deepEqual(actualResult, expectedResult);
    });
 it("should return 0 for empty inputs", ()=>{
     assert.equal(numTracksWhoseDataChanged([], []), 0);
 });
    it("parses [property] binding", () => {
        parser.parse("<TextField [text]='somevar' />");

        assert.equal('TextField', last_element);
        assert.equal(last_attrs['[text]'], 'somevar');
    });
 it("should return 3 for one track deleted, one track added, one track changed", ()=>{
     let state1 = [{key:"a", data:[]}, {key:"b", data:[]}];
     let state2 = [{key:"b", data:[1]}, {key:"c", data:[]}];
     assert.equal(numTracksWhoseDataChanged(state1, state2), 3, "test one direction");
     assert.equal(numTracksWhoseDataChanged(state2, state1), 3, "test other direction");
 });
    it("parses (^event) binding", () => {
        parser.parse("<TextField (^tap)='onTap(blah)' />");

        assert.equal('TextField', last_element);
        assert.equal(last_attrs['(^tap)'], 'onTap(blah)');
    });
 it("should set the config to new order if order is specified, different order specified before", ()=>{
     transitionSortConfig({sortConfig:{order:["6","4","0","2"]}},{sortConfig:{order:["1"]}}, oncoprint);
     assert.equal(oncoprint.setSortConfig.callCount, 1, "called once");
     assert.deepEqual(oncoprint.setSortConfig.args[0][0], {type:"order", order:["6","4","0","2"]}, "correct sort config used");
 });
    it("parses #id attribute", () => {
        parser.parse("<TextField #firstName />");

        assert.equal('TextField', last_element);
        assert.equal(last_attrs['#firstName'], '');
    });
 it("should set the config to heatmap if heatmap index specified, different heatmap index specified before", ()=>{
     transitionSortConfig({sortConfig:{clusterHeatmapTrackGroupIndex:5}}, {sortConfig:{clusterHeatmapTrackGroupIndex:2}}, oncoprint);
     assert.equal(oncoprint.setSortConfig.callCount, 1, "called once");
     assert.deepEqual(oncoprint.setSortConfig.args[0][0], {type:"cluster", track_group_index:5, clusterValueFn: heatmapClusterValueFn}, "correct sort config used");
 });
    it("detects equals without value", () => {
        parser.parse("<TextField brokenTag= />");

        assert.isFalse(last_attrs);
    });
 it("does not add duplicate users", () => {
     const handler = new PresenceHandler(bot as DiscordBot);
     handler.EnqueueUser(new MockUser("abc", "def") as any);
     handler.EnqueueUser(new MockUser("abc", "def") as any);
     Chai.assert.equal(handler.QueueCount, 1);
 });
    it("detects no equals with quoted value", () => {
        parser.parse("<TextField noEquals 'value' />");

        assert.isFalse(last_attrs);
    });
Example #27
0
  // Given the URL of a server serving out Polymer shop, opens a Chrome tab
  // and pokes around to test that Shop is working there.
  async function assertThatShopWorks(baseUrl: string) {
    let browser: puppeteer.Browser;
    if (debugging) {
      browser = await puppeteer.launch({headless: false, slowMo: 250});
    } else {
      // TODO(usergenic): For some unknown reason, tests failed in headless
      // Chrome involving the `/cart` route for the Polymer/shop lit-element
      // branch only.  Remove the `{headless: false}` when this problem is
      // fixed.
      browser = await puppeteer.launch({headless: false});
    }
    disposables.push(() => browser.close());
    const page = await browser.newPage();
    page.on('pageerror', (e) => (error = error || e));
    // Evaluate an expression as a string in the browser.
    const evaluate = async (expression: string) => {
      try {
        return await page.evaluate(expression);
      } catch (e) {
        throw new Error(`Failed evaluating expression \`${
            expression} in the browser. Error: ${e}`);
      }
    };
    // Assert on an expression's result in the browser.
    const assertTrueInPage = async (expression: string) => {
      assert(
          await evaluate(expression),
          `Expected \`${expression}\` to evaluate to true in the browser`);
    };
    const waitFor =
        async (name: string, expression: string, timeout?: number) => {
      try {
        await page.waitForFunction(expression, {timeout});
      } catch (e) {
        throw new Error(`Error waiting for ${name} in the browser`);
      }
    };

    await gotoOrDie(page, `${baseUrl}/`);
    assert.deepEqual(`${baseUrl}/`, page.url());
    await waitFor(
        'shop-app to be defined',
        `this.customElements.get('shop-app') !== undefined`);
    await waitFor(
        'shop-app children to exist', `this.document.querySelector('shop-app')
            .shadowRoot.querySelector('a[href="/cart"], shop-cart-button')`);
    const isLitElement =
        await evaluate(`!!this.document.querySelector('shop-app')
            .shadowRoot.querySelector('shop-cart-button')`);
    if (isLitElement) {
      // Wait a few more rAFs for the button to definitely be there.
      for (let i = 0; i < 10; i++) {
        await requestAnimationFrame(page);
      }
      await page.waitForFunction(`!!(
          document.querySelector('shop-app').shadowRoot
            .querySelector('shop-cart-button').shadowRoot)`);
    }

    // The cart shouldn't be registered yet, because we've only loaded the
    // main page.
    await assertTrueInPage(`customElements.get('shop-cart') === undefined`);
    // Click the shopping cart button.
    await evaluate(`
        (
          // shop 3.0
          document.querySelector('shop-app').shadowRoot
              .querySelector('a[href="/cart"]')
          ||
          // shop lit
          document.querySelector('shop-app').shadowRoot
              .querySelector('shop-cart-button').shadowRoot
                  .querySelector('a[href="/cart"]')
        ).click()`);
    // The url changes immediately
    assert.deepEqual(`${baseUrl}/cart`, page.url());
    // We'll lazy load the code for shop-cart. We'll know that it worked
    // when the element is registered. If this resolves, it loaded
    // successfully!
    await waitFor(
        'shop-cart to be defined',
        `this.customElements.get('shop-cart') !== undefined`,
        3 * 60 * 1000);
  }
    it("detects unclosed tag after no value attribute", () => {
        parser.parse("<TextField #myId");

        assert.isFalse(last_attrs);
    });
 it('match #3: shouldn\'t append custom node into the obfuscated code', () => {
     assert.notMatch(obfuscatedCode, consoleWarnRegExp);
 });
 error: (error) => {
   assert.equal(error.message, 'Network error');
   done();
 },