![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
apigeek-dialect
Advanced tools
Use naturual language to write executable Epics and easily re-use them across different projects.
Since Epics are written in "executable natural language" - every stakeholder can make sense of them.
Including the CIO :-)
In a nutshell, Apigeek-Dialect is an automation tool to describe executable process and governance.
Behaviour Driven Development (BDD) is an emerging best practice for architecting software.
When using Dialect, an Epic is known as a "Feature" and a Story is called a "Scenario".
A Feature collects together related Scenarios.
Each Scenario describes the expected behavior and outcomes in a way that is both human and machine friendly.
Each scenario is described using the Gherkin syntax: GIVEN -> WHEN -> THEN
Dialect will execute every scenario that is grouped together into a set of "features".
Scenario: Test Google's homepage
Given I enable redirects
When I GET http://google.com/
Then response code should be 200
Gherkin is human and machine readable - business analysts, testers, developers and robots can collaborate.
New features can be created using any simple text editor.
They are invoked elegantly from an API, the command line, Mocha, your IDE or your DevOps workflow.
The results are nicely formatted to help debug, showcase and socialise.
The general BDD pattern to describe a scenario is:
GIVEN some pre-condition
WHEN an action is performed
THEN an outcome is expected
This notation is commonly called "Gherkin". To improve readability, the keyword AND can be used instead in place of the verbs above.
The text following the keyword (GIVEN | WHEN | THEN) needs to match a pattern that is understood by Apigeek-Dialect.
The supported patterns can be found in the Dialect Vocabulary
Apigeek Dialect is built using NodeJS. If you're new to node, pre-read Getting Started.
You install Dialect as a system-wide CLI command:
$ npm install apigeek-dialect -g
To run it simply type:
$ dialect
However, It won't do much until we provide some test scenarios.
A scenario describes a Story - essentially it's a list of instructions and expectations.
The framework interprets each step in the scenario using the Gherkin Vocabulary.
Let's expand our initial example, into a hypothetical scenario.
Scenario: Trivial Test
Given I am testing the story
When debug test story works
And log test story works
And error test story works
Then I assert this.name == "story"
Dialect reads the GIVEN | WHEN | THEN sentences to build up a test suite that initializes, executes tests and make assertions.
Note: The example deliberately contravenes best practice to showcase a few concepts.
A group of related scenarios is called a "feature" Epic. An Epic is identified by the ".feature" file extension.
For example: the "hello world.feature" file might look like this:
Feature: Verify that variables are working
Scenario: Test Variable Assignment
Given I set test to hello
Then variable test should match hello
By default, dialect looks in the "./features" sub-directory.
If your tests are in a different location, you can use the "--tests" or "--feature" option to locate them.
We can inject the "protocol", "hostname", "port" and "basePath" parameters from CLI options or a configuration file.
So, our example Scenario can be re-written to specify the resource only:
When I GET /
Then for each environment - we'd want to change the parameters.
By default:
{
"protocol": "http",
"hostname": "localhost",
"port": "80"
}
When constructing URLs for HTTP commands, we use "{{protocol}}://{{hostname}}:{{port}}/{{basePath}}{{resource}}" as a URL template.
If we wanted to define "https://google.com:443" as our endpoint, we'd use a JSON config file that looks like this:
{
"protocol": "https",
"hostname": "google.com",
"port": "443"
}
Apigeek-Dialect was designed to support a declarative style so that tests are portable between dev, test and production environments.
To achieve portability, environment-specific properties can be declared in a "config" file.
By default, dialect will try to load a configuration file called "apigeek.json" from your current directory.
If no file is found, then sensible default values are defined.
You can change the name of the file using the "--config <file" option.
In this way, your BDD tests are neatly abstracted from your runtime configuration.
To specify a custom configuration, use:
dialect --config config.json
If you omit the --config option, then the "apigeek.json" file in the current folder will be used.
Supplying a different "config" file for each environment allows Feature tests to be re-used across multiple environments.
The config file supports setting the following:
A default target - hostname and port. Multiple target sets are supported.
A default user agent - credentials for multiple named agents can be supplied.
client certificates - multiple named certificates are supported for example: valid, expired, invalid.
Webhooks - asynchronous notifications sent to Slack when tests start, finish and fail.
A feature test may contain a background that are prepended to each scenario. Backgrounds are similar to scenarios, except they do not support annotations.
Background: Authenticate
GIVEN I login
AND I use a valid client certificate
Dialect can send you a web hook notifications via Slack.
To confirm it simply add a section to your JSON config file:
{
"webhooks": {
"slack": {
"username": "dialect-bot",
"channel": "#testing",
"url": "https://hooks.slack.com/services/XXXXXXXXX/YYYYYYYY/ZZZZZZZZ"
}
}
}
Once you have an active Slack account then obtain a new Slack webhook URL
You will receive events when scenarios start, finish successfully or fail.
Most teams have multiple target environments such as "dev", "test" and "prod".
The config file supports a "target" definition that supports named environments.
An example that supports multiple targets, user agents and certificates:
{
"protocol": "http",
"hostname": "google.com",
"port": "80",
"target": {
"google": {
"protocol": "http",
"hostname": "google.com",
"port": "80"
},
"secure-google": {
"protocol": "https",
"hostname": "google.com",
"port": "443"
}
},
}
You can switch to different targets using the command line options "--target "
{
"protocol": "http",
"hostname": "google.com",
"port": "80",
"target": {
"secure": {
"protocol": "https",
"hostname": "example.com",
"port": "443",
"agent": {
"default": {
"username": "my-test-robot@example.com",
"password": "TEST1234"
}
},
"certificate": {
"valid": {
"key": "../etc/certs2/client/app-client.key.pem",
"cert": "../etc/certs2/client/app-client.crt.pem",
"ca": "../etc/certs2/ca/root-ca.crt.pem",
"passphrase": "test"
}
}
},
},
This software is licensed under the Apache 2 license, quoted below.
Copyright 2016 Lee Curtis lcurtis@apigeek.me
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
[http://www.apache.org/licenses/LICENSE-2.0]
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
FAQs
A Gherkin-based micro-framework
The npm package apigeek-dialect receives a total of 2 weekly downloads. As such, apigeek-dialect popularity was classified as not popular.
We found that apigeek-dialect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.