diff --git a/CHANGELOG.md b/CHANGELOG.md index 84d8253..16b7899 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,4 +5,4 @@ ### Added - Add code to apply preprocessing rules to Gherkin feature files ([#1](https://github.com/judit-nahaj/gherkin-precompiler/issues/1)) -- Add predefined preprocessors: replacer ([#2](https://github.com/judit-nahaj/gherkin-precompiler/issues/2)) +- Add predefined precompilers: replacer ([#2](https://github.com/judit-nahaj/gherkin-precompiler/issues/2)) diff --git a/README.md b/README.md index e9646af..b5f07b0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/judit-nahaj/gherkin-precompiler.svg?branch=master)](https://travis-ci.org/judit-nahaj/gherkin-precompiler) [![dependency Status](https://david-dm.org/judit-nahaj/gherkin-precompiler.svg)](https://david-dm.org/judit-nahaj/gherkin-precompiler) [![devDependency Status](https://david-dm.org/judit-nahaj/gherkin-precompiler/dev-status.svg)](https://david-dm.org/judit-nahaj/gherkin-precompiler#info=devDependencies) [![Coverage Status](https://coveralls.io/repos/github/judit-nahaj/gherkin-precompiler/badge.svg?branch=master)](https://coveralls.io/github/judit-nahaj/gherkin-precompiler?branch=master) -Simple pre-processor for Gherkin feature files. +Simple pre-compiler for Gherkin feature files. It is based on the AST what is provided by [gherkin-assembler](https://www.npmjs.com/package/gherkin-assembler). @@ -10,21 +10,21 @@ It is based on the AST what is provided by [gherkin-assembler](https://www.npmjs ```javascript 'use strict'; -const processor = require('gherkin-precompiler'); +const compiler = require('gherkin-precompiler'); -let ast = processor.load('./features/src/login.feature'); -ast = processor.process( +let ast = compiler.load('./features/src/login.feature'); +ast = compiler.process( ast, - new processor.builtIn.Replacer({ + new compiler.builtIn.Replacer({ name: 'Hello' }) ); -processor.save('./features/dist/login.feature', ast, { +compiler.save('./features/dist/login.feature', ast, { lineBreak: '\r\n' }); ``` -### Built-in pre processors +### Built-in pre compilers * [Replacer](lib/builtIn/Replacer.md) @@ -55,12 +55,12 @@ Saves the given AST ast feature file to the given path. ### `process` -Applies the given pre-processors to the given AST. +Applies the given pre-compilers to the given AST. **Params:** * `{GherkinDocument} ast` - the AST needs to be processed - * `{...DefaultConfig|Object} pre-processors` - the pre-processors needs to be applied to the given AST + * `{...DefaultConfig|Object} pre-compilers` - the pre-compilers needs to be applied to the given AST **Returns:** `{GherkinDocument}` the processed AST @@ -71,7 +71,7 @@ Formats the given `GherkinDocument` to text. ### Configuration -If you want to create own pre-processor, you only have to extends the `Default` class and override the filter and/or event methods, that you want to use; or create and object with the desired methods. +If you want to create own pre-compiler, you only have to extends the `Default` class and override the filter and/or event methods, that you want to use; or create and object with the desired methods. #### Event methods diff --git a/lib/DefaultConfig.js b/lib/DefaultConfig.js index 36ac626..fa94c0b 100644 --- a/lib/DefaultConfig.js +++ b/lib/DefaultConfig.js @@ -1,6 +1,6 @@ 'use strict'; /** - * Base class to create Gherkin feature file pre-processors. + * Base class to create Gherkin feature file pre-compilers. * @class */ class DefaultConfig { diff --git a/lib/PreCompiler.js b/lib/PreCompiler.js index 14ccffe..7bd33b0 100644 --- a/lib/PreCompiler.js +++ b/lib/PreCompiler.js @@ -39,7 +39,7 @@ const METHODS = { }; /** - * Gherkin feature file pre-processors. + * Gherkin feature file pre-compilers. * @class */ class PreCompiler { @@ -52,7 +52,7 @@ class PreCompiler { } /** - * Applies the pre-processor to the given AST. + * Applies the pre-compiler to the given AST. * * @param {GherkinDocument} ast * @returns {GherkinDocument} diff --git a/lib/builtIn/Replacer.md b/lib/builtIn/Replacer.md index 5ef1b50..9ade05c 100644 --- a/lib/builtIn/Replacer.md +++ b/lib/builtIn/Replacer.md @@ -1,4 +1,4 @@ -### Replacer for Gherkin preprocessor +### Replacer for Gherkin precompiler This Replacer is responsible for exchanging predefined strings in the feature files. It inserts the provided text in the place held for them. diff --git a/lib/index.js b/lib/index.js index 6e6ec3d..7e74ac5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -22,7 +22,7 @@ API.load = pathToFile => { const PreCompiler = require('./PreCompiler'); /** - * Applies the given pre-processors to the given AST. + * Applies the given pre-compilers to the given AST. * * @param {GherkinDocument} ast * @param {...DefaultConfig|Object} configs @@ -30,8 +30,8 @@ const PreCompiler = require('./PreCompiler'); */ API.process = (ast, ...configs) => { configs.forEach(config => { - const processor = new PreCompiler(config); - ast = processor.applyToAST(ast); + const compiler = new PreCompiler(config); + ast = compiler.applyToAST(ast); }); return ast; }; @@ -57,7 +57,7 @@ API.save = (pathToFile, ast, options) => { }; /** - * Built-in pre-processors. + * Built-in pre-compilers. * @type {Object.} */ API.builtIn = {}; diff --git a/package.json b/package.json index 72fcf01..b0b576c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gherkin-precompiler", "version": "1.0.0", - "description": "Simple pre-processor for Gherkin feature files", + "description": "Simple pre-compiler for Gherkin feature files", "main": "lib/index.js", "scripts": { "test": "mocha ./test/*.spec.js ./test/builtIn/*.spec.js", diff --git a/test/index.spec.js b/test/index.spec.js index 82e417e..39b1460 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -39,7 +39,7 @@ describe('API', () => { }); describe('.process()', () => { - it('should not do anything if no pre-processor provided', () => { + it('should not do anything if no pre-compiler provided', () => { expect(API.process(ast)).to.equal(ast); }); @@ -53,21 +53,21 @@ describe('API', () => { describe('PreCompiler', () => { describe('processing events', () => { it('should support Feature processing', () => { - class FeatureProcessor extends API.DefaultConfig { + class Featurecompiler extends API.DefaultConfig { onFeature(feature) { feature.name = 'test'; feature.description = 'test'; } } - const processed = API.process(ast, new FeatureProcessor()); + const processed = API.process(ast, new Featurecompiler()); expect(processed).to.not.eql(ast); expect(processed.feature.name).to.equal('test'); expect(processed.feature.description).to.equal('test'); }); it('should support Background processing', () => { - class BackgroundProcessor extends API.DefaultConfig { + class Backgroundcompiler extends API.DefaultConfig { onBackground(background, feature) { feature.name = 'test'; feature.description = 'test'; @@ -76,7 +76,7 @@ describe('API', () => { } } - const processed = API.process(ast, new BackgroundProcessor()); + const processed = API.process(ast, new Backgroundcompiler()); expect(processed).to.not.eql(ast); expect(processed.feature.name).to.equal('test'); expect(processed.feature.description).to.equal('test'); @@ -85,7 +85,7 @@ describe('API', () => { }); it('should support Scenario processing', () => { - class ScenarioProcessor extends API.DefaultConfig { + class Scenariocompiler extends API.DefaultConfig { onScenario(scenario, feature) { feature.name = 'test'; feature.description = 'test'; @@ -94,7 +94,7 @@ describe('API', () => { } } - const processed = API.process(ast, new ScenarioProcessor()); + const processed = API.process(ast, new Scenariocompiler()); expect(processed).to.not.eql(ast); expect(processed.feature.name).to.equal('test'); expect(processed.feature.description).to.equal('test'); @@ -103,7 +103,7 @@ describe('API', () => { }); it('should support ScenarioOutline processing', () => { - class ScenarioOutlineProcessor extends API.DefaultConfig { + class ScenarioOutlinecompiler extends API.DefaultConfig { onScenarioOutline(scenario, feature) { feature.name = 'test'; feature.description = 'test'; @@ -112,7 +112,7 @@ describe('API', () => { } } - const processed = API.process(ast, new ScenarioOutlineProcessor()); + const processed = API.process(ast, new ScenarioOutlinecompiler()); expect(processed).to.not.eql(ast); expect(processed.feature.name).to.equal('test'); expect(processed.feature.description).to.equal('test'); @@ -121,7 +121,7 @@ describe('API', () => { }); it('should support Step processing', () => { - class StepProcessor extends API.DefaultConfig { + class Stepcompiler extends API.DefaultConfig { onStep(step, parent) { parent.name = 'test'; parent.description = 'test'; @@ -129,7 +129,7 @@ describe('API', () => { } } - const processed = API.process(ast, new StepProcessor()); + const processed = API.process(ast, new Stepcompiler()); expect(processed).to.not.eql(ast); processed.feature.elements.forEach(element => { expect(element.name).to.equal('test'); @@ -141,7 +141,7 @@ describe('API', () => { }); it('should support Tag processing', () => { - class TagProcessor extends API.DefaultConfig { + class Tagcompiler extends API.DefaultConfig { onTag(tag, parent) { parent.name = 'test'; parent.description = 'test'; @@ -149,7 +149,7 @@ describe('API', () => { } } - const processed = API.process(ast, new TagProcessor()); + const processed = API.process(ast, new Tagcompiler()); expect(processed).to.not.eql(ast); expect(processed.feature.elements[0].name).to.not.equal('test'); expect(processed.feature.elements[0].description).to.not.equal('test'); @@ -169,7 +169,7 @@ describe('API', () => { }); it('should support Examples processing', () => { - class ExamplesProcessor extends API.DefaultConfig { + class Examplescompiler extends API.DefaultConfig { onExamples(examples, outline) { outline.name = 'test'; outline.description = 'test'; @@ -177,7 +177,7 @@ describe('API', () => { } } - const processed = API.process(ast, new ExamplesProcessor()); + const processed = API.process(ast, new Examplescompiler()); expect(processed).to.not.eql(ast); expect(processed.feature.elements[2].name).to.equal('test'); expect(processed.feature.elements[2].description).to.equal('test'); @@ -187,14 +187,14 @@ describe('API', () => { }); it('should support Examples header processing', () => { - class ExamplesProcessor extends API.DefaultConfig { + class Examplescompiler extends API.DefaultConfig { onExampleHeader(row, examples) { examples.name = 'test'; row.cells.push(row.cells[0].clone()); } } - const processed = API.process(ast, new ExamplesProcessor()); + const processed = API.process(ast, new Examplescompiler()); expect(processed).to.not.eql(ast); processed.feature.elements[2].examples.forEach(examples => { expect(examples.name).to.equal('test'); @@ -203,14 +203,14 @@ describe('API', () => { }); it('should support Examples row processing', () => { - class ExamplesProcessor extends API.DefaultConfig { + class Examplescompiler extends API.DefaultConfig { onExampleRow(row, examples) { examples.name = 'test'; row.cells.push(row.cells[0].clone()); } } - const processed = API.process(ast, new ExamplesProcessor()); + const processed = API.process(ast, new Examplescompiler()); expect(processed).to.not.eql(ast); processed.feature.elements[2].examples.forEach(examples => { expect(examples.name).to.equal('test'); @@ -221,14 +221,14 @@ describe('API', () => { }); it('should support DocString processing', () => { - class DocStringProcessor extends API.DefaultConfig { + class DocStringcompiler extends API.DefaultConfig { onDocString(docString, step) { step.text = 'test'; docString.content = 'test'; } } - const processed = API.process(ast, new DocStringProcessor()); + const processed = API.process(ast, new DocStringcompiler()); expect(processed).to.not.eql(ast); const step = processed.feature.elements[1].steps[4]; expect(step.text).to.equal('test'); @@ -236,14 +236,14 @@ describe('API', () => { }); it('should support DataTable processing', () => { - class DataTableProcessor extends API.DefaultConfig { + class DataTablecompiler extends API.DefaultConfig { onDataTable(dataTable, step) { step.text = 'test'; dataTable.rows.push(dataTable.rows[0].clone()); } } - const processed = API.process(ast, new DataTableProcessor()); + const processed = API.process(ast, new DataTablecompiler()); expect(processed).to.not.eql(ast); const step = processed.feature.elements[1].steps[3]; expect(step.text).to.equal('test'); @@ -251,7 +251,7 @@ describe('API', () => { }); it('should support replacing simple values', () => { - class DocStringProcessor extends API.DefaultConfig { + class DocStringcompiler extends API.DefaultConfig { onDocString(docString) { const newDocString = docString.clone(); newDocString.content = 'test'; @@ -259,14 +259,14 @@ describe('API', () => { } } - const processed = API.process(ast, new DocStringProcessor()); + const processed = API.process(ast, new DocStringcompiler()); expect(processed).to.not.eql(ast); const step = processed.feature.elements[1].steps[4]; expect(step.argument.content).to.equal('test'); }); it('should support replacing list values', () => { - class ScenarioProcessor extends API.DefaultConfig { + class Scenariocompiler extends API.DefaultConfig { onScenario(scenario) { const newScenario = scenario.clone(); newScenario.name = 'test'; @@ -275,20 +275,20 @@ describe('API', () => { } } - const processed = API.process(ast, new ScenarioProcessor()); + const processed = API.process(ast, new Scenariocompiler()); expect(processed).to.not.eql(ast); expect(processed.feature.elements[1].name).to.equal('test'); expect(processed.feature.elements[1].description).to.equal('test'); }); it('should support deleting list values', () => { - class ScenarioProcessor extends API.DefaultConfig { + class Scenariocompiler extends API.DefaultConfig { onScenario(scenario) { return null; } } - const processed = API.process(ast, new ScenarioProcessor()); + const processed = API.process(ast, new Scenariocompiler()); expect(processed).to.not.eql(ast); expect(processed.feature.elements.length).to.equal(2); }); @@ -296,7 +296,7 @@ describe('API', () => { describe('filters', () => { it('should support filtering of Tags', () => { - class TagProcessor extends API.DefaultConfig { + class Tagcompiler extends API.DefaultConfig { preFilterTag(tag) { return /2$/.test(tag.name); } @@ -315,7 +315,7 @@ describe('API', () => { } } - const processed = API.process(ast, new TagProcessor()); + const processed = API.process(ast, new Tagcompiler()); expect(processed.feature.tags.length).to.equal(3); processed.feature.elements.slice(1).forEach(element => { @@ -333,7 +333,7 @@ describe('API', () => { }); it('should support filtering Scenario-like elements', () => { - class ScenarioProcessor extends API.DefaultConfig { + class Scenariocompiler extends API.DefaultConfig { preFilterScenario(scenario) { return scenario.constructor.name !== 'ScenarioOutline'; } @@ -342,13 +342,13 @@ describe('API', () => { } } - const processed = API.process(ast, new ScenarioProcessor()); + const processed = API.process(ast, new Scenariocompiler()); expect(processed.feature.elements.length).to.equal(1); expect(processed.feature.elements[0]).to.be.instanceOf(assembler.AST.Background); }); it('should support filtering Steps', () => { - class StepProcessor extends API.DefaultConfig { + class Stepcompiler extends API.DefaultConfig { preFilterStep(step, _, i) { step.text = '1'; return i < 2; @@ -360,7 +360,7 @@ describe('API', () => { } } - const processed = API.process(ast, new StepProcessor()); + const processed = API.process(ast, new Stepcompiler()); processed.feature.elements.forEach(element => { expect(element.steps.length).to.equal(1); expect(element.steps[0].text).to.equal('12'); @@ -368,7 +368,7 @@ describe('API', () => { }); it('should support filtering Rows of dataTables of examples', () => { - class RowProcessor extends API.DefaultConfig { + class Rowcompiler extends API.DefaultConfig { preFilterRow(row, _, i) { row.cells = row.cells.slice(0, 1); row.cells[0].value = '1'; @@ -381,7 +381,7 @@ describe('API', () => { } } - const processed = API.process(ast, new RowProcessor()); + const processed = API.process(ast, new Rowcompiler()); processed.feature.elements[1].steps.slice(2, 4).forEach(step => { expect(step.argument.rows.length).to.equal(1); expect(step.argument.rows[0].cells[0].value).to.equal('12'); @@ -393,7 +393,7 @@ describe('API', () => { }); it('should support filtering Examples', () => { - class ExamplesProcessor extends API.DefaultConfig { + class Examplescompiler extends API.DefaultConfig { preFilterExamples(examples) { return examples.tags[0].name === '@tagE1'; } @@ -403,20 +403,20 @@ describe('API', () => { } } - const processed = API.process(ast, new ExamplesProcessor()); + const processed = API.process(ast, new Examplescompiler()); expect(processed.feature.elements[2].examples.length).to.equal(0); }); }); it('should support Object configuration', () => { - const featureProcessor = { + const featurecompiler = { onFeature(feature) { feature.name = 'test'; feature.description = 'test'; } }; - const processed = API.process(ast, featureProcessor); + const processed = API.process(ast, featurecompiler); expect(processed).to.not.eql(ast); expect(processed.feature.name).to.equal('test'); expect(processed.feature.description).to.equal('test');