Core BDD testing package for fflow - Behavior-Driven Development tests in JavaScript
npm install @-fflow/coreCore is the main component of fflow, providing a comprehensive BDD (Behavior-Driven Development) testing framework for JavaScript applications.
- š„ Built on Cucumber.js for industry-standard BDD testing
- ā
Integrated with Chai for powerful assertions
- š Custom World implementation for scenario context management
- š£ Hooks for setup and teardown operations
- š Multiple report formats (JSON, HTML, Progress)
- š§ Easy-to-use API for creating custom step definitions
``bash`
npm install @fflow/core --save-dev
Create a .feature file in your features directory:
`gherkin
Feature: User Authentication
As a user
I want to log in to the system
So that I can access my account
Scenario: Successful login
Given I am on the login page
When I enter valid credentials
Then I should be redirected to the dashboard
`
`javascript
const { Given, When, Then, expect } = require('@fflow/core');
Given('I am on the login page', function() {
// Navigate to login page
this.setContext('currentPage', '/login');
});
When('I enter valid credentials', function() {
// Simulate entering credentials
const credentials = {
username: 'user@example.com',
password: 'password123'
};
this.setContext('credentials', credentials);
});
Then('I should be redirected to the dashboard', function() {
// Verify redirection
const currentPage = this.getContext('currentPage');
expect(currentPage).to.equal('/dashboard');
});
`
`bash`
npm test
`javascript
const { Given, When, Then } = require('@fflow/core');
Given('a precondition', function() {
// Setup code
});
When('an action occurs', function() {
// Action code
});
Then('expect a result', function() {
// Assertion code
});
`
The World provides isolated context for each scenario:
`javascript
// Store data
this.setContext('key', value);
// Retrieve data
const value = this.getContext('key');
// Clear all context
this.clearContext();
// Access Chai expect
this.expect(actual).to.equal(expected);
`
`javascript
const { Before, After, BeforeAll, AfterAll } = require('@fflow/core');
BeforeAll(function() {
// Runs once before all scenarios
});
Before(function() {
// Runs before each scenario
});
After(function(scenario) {
// Runs after each scenario
});
AfterAll(function() {
// Runs once after all scenarios
});
`
Create a custom World class with additional functionality:
`javascript
const { createWorld, setWorldConstructor } = require('@fflow/core');
const CustomWorld = createWorld({
// Add custom properties or methods
apiClient: null,
async makeRequest(endpoint) {
// Custom method
return await this.apiClient.get(endpoint);
}
});
setWorldConstructor(CustomWorld);
`
Create a cucumber.js file in your project root:
`javascript`
module.exports = {
default: {
require: [
'features/step_definitions/*/.js',
'features/support/*/.js'
],
format: [
'progress',
'json:reports/cucumber_report.json',
'html:reports/cucumber_report.html'
],
publishQuiet: true
}
};
- npm test - Run all testsnpm run test:watch
- - Run tests in watch modenpm run test:dry-run
- - Validate feature files without executingnpm run test:parallel
- - Run tests in parallelnpm run test:tags @tagname
- - Run specific tagged scenariosnpm run report
- - Generate test reports
``
your-project/
āāā features/
ā āāā step_definitions/
ā ā āāā your_steps.js
ā āāā support/
ā ā āāā world.js
ā ā āāā hooks.js
ā āāā your.feature
āāā cucumber.js
āāā package.json
1. Keep scenarios focused: Each scenario should test one specific behavior
2. Use Background wisely: Only include steps that are truly common to all scenarios
3. Write declarative scenarios: Focus on what, not how
4. Reuse step definitions: Create generic, reusable steps when possible
5. Use tags for organization: Tag features and scenarios for selective execution
Check out the included example in the features` directory to see a working calculator implementation with:
- Feature file with multiple scenarios
- Step definitions
- World context usage
- Scenario outlines with examples
Please submit issues and pull requests to the fflow/core repository.
ISC