Code Monkey home page Code Monkey logo

jsgiven's Introduction

Build Status Coverage Status Code Climate styled with prettier

GitHub license npm version Quality

JsGiven aims to bring BDD (Behavior-Driven Development) to plain (or typed) JavaScript.

It is a developer-friendly and pragmatic BDD tool for JavaScript.

Developers write scenarios in plain JavaScript using a fluent, domain-specific API, JsGiven generates reports that are readable by domain experts.

It's a JavaScript port of JGiven (written in Java). JsGiven keeps the JGiven philosophy, concepts and uses its html5 reporting tool.

You can have a look at JSGiven's own report

scenarios('recipes', RecipesStage, ({ given, when, then }) => ({
  a_pancake_can_be_fried_out_of_an_egg_milk_and_flour: scenario({}, () => {
    given()
      .an_egg()
      .and()
      .some_milk()
      .and()
      .the_ingredient('flour');

    when()
      .the_cook_mangles_everything_to_a_dough()
      .and()
      .the_cook_fries_the_dough_in_a_pan();

    then().the_resulting_meal_is_a_pan_cake();
  }),
}));

It can be used with any javascript test runner (like Jest, Ava, Mocha, Jasmine, or Protractor).

It can be used with your favorite assertion library (like ChaiJS, Jasmine), or your framework's assertion library.

It aims to provide the most comfortable developer experience with ES6 class syntax, and optional FlowType or TypeScript typings.

Some features are missing, but the folks at https://www.fluo.com are already using it daily.

Don't hesitate to give any feedback and to open a GitHub issue https://github.com/jsGiven/jsGiven/issues

Getting started

You can start using JsGiven with the user guide https://jsgiven.org/user-guide.html Don't hesitate to give any feedback and to open a GitHub issue https://github.com/jsGiven/jsGiven/issues

jsgiven's People

Contributors

abalhier avatar flegall avatar greenkeeperio-bot avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jsgiven's Issues

Support ES6 (non-transpiled) stage classes

Looks like I'm doing something wrong. Could you provide a simple example to run the tests against Protractor with Typescript. I've could not run the example from guide.

The code

import { scenario, scenarios, setupForRspec, Stage } from 'js-given';

function sum(a: number, b: number): number {
    return a + b;
}

setupForRspec(describe, it);

class SumStage extends Stage {
    number1: number;
    number2: number;
    result: number;

    a_number(value) {
        this.number1 = value;
        return this;
    }

    another_number(value) {
        this.number2 = value;
        return this;
    }

    they_are_summed() {
        this.result = this.number1 + this.number2;
        return this;
    }

    the_result_is(expectedResult) {
        expect(this.result).toEqual(expectedResult);
        return this;
    }
}

scenarios('sum', SumStage, ({ given, when, then }) => {
    return {
        two_numbers_can_be_added: scenario({}, () => {
            given()
                .a_number(1)
                .and()
                .another_number(2);

            when().they_are_summed();

            then().the_result_is(3);
        }),
    };
});

produces the error below

Failed: Class constructor SumStage cannot be invoked without 'new'
TypeError: Class constructor SumStage cannot be invoked without 'new'
    at new extendedClass (D:\Dev\Projects\csos-ui-test-automation\node_modules\js-given\index.js:1278:126)
    at ScenarioRunner.buildStage (D:\Dev\Projects\csos-ui-test-automation\node_modules\js-given\index.js:1288:28)
    at stageBuilder (D:\Dev\Projects\csos-ui-test-automation\node_modules\js-given\index.js:921:44)
    at UserContext.<anonymous> (D:\Dev\Projects\csos-ui-test-automation\node_modules\js-given\index.js:1072:45)
    at D:\Dev\Projects\csos-ui-test-automation\node_modules\jasminewd2\index.js:112:25
    at new ManagedPromise (D:\Dev\Projects\csos-ui-test-automation\node_modules\selenium-webdriver\lib\promise.js:1077:7)
    at ControlFlow.promise (D:\Dev\Projects\csos-ui-test-automation\node_modules\selenium-webdriver\lib\promise.js:2505:12)
    at schedulerExecute (D:\Dev\Projects\csos-ui-test-automation\node_modules\jasminewd2\index.js:95:18)
    at TaskQueue.execute_ (D:\Dev\Projects\csos-ui-test-automation\node_modules\selenium-webdriver\lib\promise.js:3084:14)
    at TaskQueue.executeNext_ (D:\Dev\Projects\csos-ui-test-automation\node_modules\selenium-webdriver\lib\promise.js:3067:27)
From: Task: Run it("Two numbers can be added") in control flow
    at UserContext.<anonymous> (D:\Dev\Projects\csos-ui-test-automation\node_modules\jasminewd2\index.js:94:19)
    at attempt (D:\Dev\Projects\csos-ui-test-automation\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:4297:26)
    at QueueRunner.run (D:\Dev\Projects\csos-ui-test-automation\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:4217:20)
    at QueueRunner.execute (D:\Dev\Projects\csos-ui-test-automation\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:4199:10)
    at Spec.queueRunnerFactory (D:\Dev\Projects\csos-ui-test-automation\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:909:35)
    at Spec.execute (D:\Dev\Projects\csos-ui-test-automation\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:526:10)
    at UserContext.fn (D:\Dev\Projects\csos-ui-test-automation\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:5340:37)
    at attempt (D:\Dev\Projects\csos-ui-test-automation\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:4297:26)
    at QueueRunner.run (D:\Dev\Projects\csos-ui-test-automation\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:4217:20)
    at QueueRunner.execute (D:\Dev\Projects\csos-ui-test-automation\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:4199:10)
From asynchronous test: 
Error
    at ScenarioRunner.testFunc (D:\Dev\Projects\csos-ui-test-automation\node_modules\js-given\index.js:1426:9)
    at D:\Dev\Projects\csos-ui-test-automation\node_modules\js-given\index.js:969:31
    at Array.forEach (<anonymous>)
    at D:\Dev\Projects\csos-ui-test-automation\node_modules\js-given\index.js:964:27
    at Array.forEach (<anonymous>)
    at Suite.<anonymous> (D:\Dev\Projects\csos-ui-test-automation\node_modules\js-given\index.js:955:41)
    at addSpecsToSuite (D:\Dev\Projects\csos-ui-test-automation\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:1107:25)
    at Env.describe (D:\Dev\Projects\csos-ui-test-automation\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:1074:7)
    at describe (D:\Dev\Projects\csos-ui-test-automation\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:4399:18)

Support Karma test runner

Karma is a bit different from other test runners, the tests are actually run within a browser in which there is no possibility of writing a report file.
Therefore the scenario reports must be returned through the network or the karma API.

Provide an alternative to @State decorators

Decorators are nice, I like them for @State properties but not everyone is fine with using them, especially they are not part of the standard and require an additional babel configuration.

It would be nice to introduce State.addProperty(class, property) static method to declare state properties.

The same could be used for parameter formatting and other Stage related decorations

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Rate Limited

These updates are currently rate limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency chai to v4.3.6
  • chore(deps): update dependency eslint-plugin-import to v2.26.0
  • chore(deps): update dependency flow-bin to v0.177.0
  • chore(deps): update dependency glob to v7.2.0
  • chore(deps): update dependency jasmine to v3.99.0
  • chore(deps): update dependency ava to v4
  • chore(deps): update dependency chalk to v5
  • chore(deps): update dependency eslint to v8
  • chore(deps): update dependency eslint-config-standard to v17
  • chore(deps): update dependency eslint-plugin-flowtype to v8
  • chore(deps): update dependency eslint-plugin-promise to v6
  • chore(deps): update dependency glob to v8
  • chore(deps): update dependency jasmine to v4
  • chore(deps): update dependency mocha to v10
  • chore(deps): update dependency protractor to v7
  • chore(deps): update dependency sinon to v13
  • chore(deps): update dependency sleep-promise to v9
  • fix(deps): update dependency fs-extra to v10
  • fix(deps): update dependency jgiven-html-app to v1
  • fix(deps): update dependency rimraf to v3
  • fix(deps): update dependency strip-ansi to v7
  • fix(deps): update dependency yargs to v17

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.


  • Check this box to trigger a request for Renovate to run again on this repository

Interpolate parametrized scenarios

The $ in Stages method allows you to get variable tests output. It could be nice if we can have the same thing in parametrized Scenarios. For now we have in the console output :

Should be a parametrized test # 1
Should be a parametrized test # 2
Should be a parametrized test # 3
...

Using $ in Scenarios method, we could get :

Should be a parametrized test toto
Should be a parametrized test tata
Should be a parametrized test titi
...

Inject the test framework assertions

For now I've been using chai assertions DSL, but most people don't use Chai assertions, and rather use the test framework assertions DSL.

Using Jasmine (used by Jest) assertions is straightforward, as they are global functions.
For Ava or Tape, it's a bit more complex as they are injected as the test method parameters.

Integrate with watch mode of test frameworks

Currently jsGiven report is generated as a 'posttest' npm script. This is not satisfactory as we would like the reports to be generated right after running a batch of tests.

Use jgiven-html-app

Use jgiven-html-app nodejs dependency instead of the java version fetching it from maven-central.

"jsgiven report --fail" does not fail if no reports present

Currently, if a JsGiven test fails with an error in a way that no reports are written to the .jsGiven-reports, the command "jsgiven report --fail" will return with exit code 0.

Some more detail: I'm running "jest || jsgiven report --fail" as described in the jsGiven-docs. A scenario fails, no report is written (I will open a separate issue for this), jest returns exit code 1, but then "jsgiven report --fail" returns 0 and the build succeeds when it shouldn't.

Expected behaviour: return with exit code != 0.

See generateJGivenReport.js line 16, in the if block the fail parameter is not evaluated.

Formatters are not applied in parametrized tests

This one is a bit tricky to fix, it's actually not implemented at all :)

An idea to implement it is to collect used arguments and their formatter during the steps collection pass.

When an argument is used multiple times in the scenario with different formatters, I think that throwing an Error is appropriate.

Implement JGiven report generation

  • Install JGiven app artefact from maven
  • Convert jsGiven internal reports to JGiven json report format
  • Zip & Base64 encode the JGiven report

Implement error handling

In particular, if one step method fails, the rest of the scenario should still appear in the report,

Handle async tests

Currently jsGiven does not handle async tests, these tests become more or less necessary when it comes to integrations tests or end-to-end tests.

I don't think the scenarios is the place where asynchronicity should take place.
The scenarios have to remain readable, even if the .then() calls or await keywords will not appear in the report, I don't think they should appear in the scenarios code.

I would rather see them in the stages methods.
The main problem is that if the scenario remains synchronous, the stage methods should also be.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.