Git Product home page Git Product logo

gherking / gpc-replacer Goto Github PK

View Code? Open in Web Editor NEW
0.0 5.0 0.0 261 KB

The Replacer precompiler is responsible for exchanging predefined strings in the feature files. It inserts the provided text in the place held for them.

Home Page: https://gherking.github.io/gpc-replacer/

License: MIT License

TypeScript 18.07% Gherkin 81.93%
gherkin gherking feature-file cucumber typescript gpc precompiler hacktoberfest

gpc-replacer's Introduction

gpc-replacer

Downloads Version@npm Version@git CI Docs

This GherKing Precompiler is responsible to replace keys in feature files with given values.

Usage

'use strict';
const compiler = require('gherking');
const { default: Replacer } = require('gpc-replacer');

let ast = await compiler.load('./features/src/login.feature');
ast = compiler.process(
    ast,
    new Replacer({
        // config
        stringToBeReplaced1: "stringToReplaceWith1",
        stringToBeReplaced2: "stringToReplaceWith2",
    })
);
await compiler.save('./features/dist/login.feature', ast, {
    lineBreak: '\r\n'
});
'use strict';
import {load, process, save} from "gherking";
import Replacer, { ReplacerConfig } from "gpc-replacer";

let ast = await load("./features/src/login.feature");
ast = process(
    ast,
    new Replacer({
        // config
        stringToBeReplaced1: "stringToReplaceWith1",
        stringToBeReplaced2: "stringToReplaceWith2",
    })
);
await save('./features/dist/login.feature', ast, {
    lineBreak: '\r\n'
});

This Replacer is responsible for exchanging predefined strings in the feature files. It inserts the provided text in the place held for them.

As an input it needs the feature file to be modified, and a config json file, which contains the words to be replaced, and the words to replace them with. It is a regular json, where the keys are the words need replacing, and their values are the words they will get replaced by. In case the config file is not available, or its format is incorrect the Replacer throws an error.

It replaces strings given in a format ${to_replace} in the input feature.

It can find and replace such strings in the textual parts of a feature file:

  • Document: comments
  • Feature: name, description, comments
  • Rule: name, description, comments
  • Background: name, description, comments
  • Scenario Outline: name, decription, comments
  • Scenario: name, description, comments
  • Step: text, comment
  • Tag: name, value, comments
  • Examples: name, comments
  • Doc String: content, comment
  • Data Table, Table Rows: cell values, comments

See examples for the input files and an output in the test/data folder.

Other

This package uses debug for logging, use gpc:replacer :

DEBUG=gpc:replacer* gherking ...

For detailed documentation see the TypeDocs documentation.

gpc-replacer's People

Contributors

dependabot[bot] avatar gula123 avatar szikszail avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gpc-replacer's Issues

[BUG] gpc-replacer not replacing inside tags

Summary

Gpc-replacer doesn't replace inside tag names.

Steps to Reproduce

Have this tag @loop(${iterationB})
Use this config
{
"path": "gpc-replacer",
"configuration": {
"iterationB": 5
}
}

Expected behavior**

Expected tag after replacing @loop(5).

Actual behavior**

Actual result after replace @loop(${iterationB})

[IMPR] Add built-in, predefined keywords to use

Summary

Add built-in, predefined keywords to use in the replacer, so they can be more easily used instead of setting them in the configuration file.

Use cases

There are two prominent use cases:

  1. Including UUID in certain places
  2. Including environment variables (handled in separate issue)

Example

Input:

Feature: Some feature
  Scenario: Creating a new user
    Given the registration page is opened
    When the username is filled with "user_${UUID}"
    Then the username should contain "user_${UUID}"

Output:

Feature: Some feature
  Scenario: Creating a new user
    Given the registration page is opened
    When the username is filled with "user_9cef15df-d251-4bf4-bd7a-dd2afff2829c"
    Then the username should contain "user_9cef15df-d251-4bf4-bd7a-dd2afff2829c"

Options/Variants

  • Adding different versions: UUID (=UUID4), UUID1, UUID2, UUID3, UUID4, NANOID
  • Adding scoped versions: SCENARIO_UUID, FEATURE_UUID, EXAMPLES_UUID, etc

Additional context

  • The value of UUID* would be unique every time
  • The value of the scoped UUID* would be a unique one per the scope

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.