carbon-design-system / carbon-spec

[WIP] Specification for the Carbon Design System
Apache License 2.0
7 stars 6 forks source link

Feat/test parser #11

Closed scottnath closed 1 year ago

scottnath commented 5 years ago

Changelog

New

What is this?

This is the parser which parses the exportable tests.

This parser, with our exportable-test structure, is now confirmed to work with Jest (this repo) and Mocha. The exportable tests have been confirmed to work in Angular CLI environments.

Exportable test parser

This test parser is meant to create describe/it/expect test structures. If it's output was being printed out, it would look like any other describe/it tests:

describe('Runs fixture requirement tests' () =>{
  describe('Div is understandable and unique', () => {
    it('Standard div', () => {
      expect(actual.html, "I find said div's content").to.not.be.empty;
      expect(actual.content, 'said content includes text').to.not.be.empty;
      expect(actual.content, "said div's content is meaningful").to.not.equal(defaults.content.text);
    });
  });
});

Exportable test structure

Inside src/test-parser.js is the breakdown of an exportable test object's available properties - documented in the scenario-test-object typedef JSDoc block.

The example in this repo via the fixture (see below) is a very basic example of a test.

Test fixtures

PR includes fixtures for the tests which are:

How Jest runs the tests

  1. Running yarn test triggers the tests inside src/__tests__/test-parser-test.js
  2. Grabs HTML from div--variant-one.html
  3. Converts HTML into a DOM fragment for testing
  4. Creates tests using TestParser (the test parsing func) using document - which contains the DOM fragment
  5. Runs tests after it creates them

Next steps

Real-world example

This PR only includes testing of a basic example-fixture.

@elizabethsjudd is working on an actual test for the accordion component which will include separate tests per user type. Her tests will show how to test changes to the DOM using this exportable test format.

Carbon POC

While we can get these tests running in this environment, we should also test that they could work within one of carbon-components-react/angular/vue.

Chai assertions / assertion library selection

The second parameter allows us to tie the expect statements to a specific scenario-requirement. But we don't want to mix the assertion types. The assertion library for these exportable tests should be something that would work in at least all four framework test environments, plus Selenium.

Confirming all requirements are met

We have tests which reads the Gherkin and the exportable tests and determines if there is a test for every requirement. I didn't want to include that in this PR so that we can focus on the exportable test structure

joshblack commented 5 years ago

Thanks for submitting this @scottnath! Had a couple of questions going through it initially:

Also, it seems like chai may be overriding the Jest assertions in that:

      expect(TestParser).to.exist;
      expect(TestParser).to.be.a('function');
      expect(Itter).to.exist;
      expect(Itter).to.be.a('function');
      expect(GetDomFragment).to.exist;
      expect(GetDomFragment).to.be.a('function');

Would be written like this in Jest (I think):

expect(TestParser).toBeDefined();
expect(TestParser).toEqual(expect.any(Function));