Skip to content

Commit

Permalink
Merge pull request #193 from pplancq/feature/eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
bencompton committed Mar 24, 2024
2 parents e292177 + 2300d15 commit 31d7160
Show file tree
Hide file tree
Showing 67 changed files with 8,452 additions and 4,120 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root = true

[*]
end_of_line = lf
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { loadFeatures, autoBindSteps } from 'jest-cucumber';
import { VendingMachine } from '../../src/vending-machine';

export const vendingMachineSteps = ({ given, and, when, then }) => {
let vendingMachine;

given(/^the vending machine has "(.*)" in stock$/, (itemName) => {
vendingMachine = new VendingMachine();
vendingMachine.stockItem(itemName, 1);
});

and('I have inserted the correct amount of money', () => {
vendingMachine.insertMoney(0.50);
});

when(/^I purchase "(.*)"$/, (itemName) => {
vendingMachine.dispenseItem(itemName);
});

then(/^my "(.*)" should be dispensed$/, (itemName) => {
const inventoryAmount = vendingMachine.items[itemName];
expect(inventoryAmount).toBe(0);
});
};

const features = loadFeatures('./specs/features/auto-binding/**/*.feature');

autoBindSteps(features, [ vendingMachineSteps ]);
// eslint-disable-next-line import/no-unresolved
import { loadFeatures, autoBindSteps } from 'jest-cucumber';
import { VendingMachine } from '../../src/vending-machine';

export const vendingMachineSteps = ({ given, and, when, then }) => {
let vendingMachine;

given(/^the vending machine has "(.*)" in stock$/, itemName => {
vendingMachine = new VendingMachine();
vendingMachine.stockItem(itemName, 1);
});

and('I have inserted the correct amount of money', () => {
vendingMachine.insertMoney(0.5);
});

when(/^I purchase "(.*)"$/, itemName => {
vendingMachine.dispenseItem(itemName);
});

then(/^my "(.*)" should be dispensed$/, itemName => {
const inventoryAmount = vendingMachine.items[itemName];
expect(inventoryAmount).toBe(0);
});
};

const features = loadFeatures('./specs/features/auto-binding/**/*.feature');

autoBindSteps(features, [vendingMachineSteps]);
145 changes: 73 additions & 72 deletions examples/ecmascript/specs/step-definitions/backgrounds.steps.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
import { loadFeature, defineFeature } from 'jest-cucumber';
import { ArcadeMachine, COIN_TYPES } from '../../src/arcade-machine';

const feature = loadFeature('./specs/features/backgrounds.feature');

defineFeature(feature, (test) => {
let arcadeMachine;

beforeEach(() => {
arcadeMachine = new ArcadeMachine();
});

const givenMyMachineIsConfiguredToRequireCoins = (given) => {
given('my machine is configured to require coins', () => {
arcadeMachine.requireCoins = true;
});
};

const givenMyMachineIsConfiguredToAcceptUsQuarters = (given) => {
given('my machine is configured to accept US Quarters', () => {
arcadeMachine.acceptedCoinType = COIN_TYPES.USQuarter;
});
};

test('Successfully inserting coins', ({ given, when, then }) => {
givenMyMachineIsConfiguredToRequireCoins(given);

given('I have not inserted any coins', () => {
arcadeMachine.balance = 0;
});

when('I insert one US quarter', () => {
arcadeMachine.insertCoin(COIN_TYPES.USQuarter);
});

then(/^I should have a balance of (\d+) cents$/, (balance) => {
arcadeMachine.balance = balance / 100;
});
});

test('Inserting a Canadian coin', ({ given, when, then }) => {
let coinStatus;

givenMyMachineIsConfiguredToRequireCoins(given);

givenMyMachineIsConfiguredToAcceptUsQuarters(given);

when('I insert a Canadian Quarter', () => {
coinStatus = arcadeMachine.insertCoin(COIN_TYPES.CanadianQuarter);
});

then('my coin should be returned', () => {
expect(coinStatus).toBe('CoinReturned');
});
});

test('Inserting a badly damaged coin', ({ given, when, then }) => {
let coinStatus;

givenMyMachineIsConfiguredToRequireCoins(given);

givenMyMachineIsConfiguredToAcceptUsQuarters(given);

when('I insert a US Quarter that is badly damaged', () => {
coinStatus = arcadeMachine.insertCoin(COIN_TYPES.Unknown);
});

then('my coin should be returned', () => {
expect(coinStatus).toBe('CoinReturned');
});
});
});
// eslint-disable-next-line import/no-unresolved
import { loadFeature, defineFeature } from 'jest-cucumber';
import { ArcadeMachine, COIN_TYPES } from '../../src/arcade-machine';

const feature = loadFeature('./specs/features/backgrounds.feature');

defineFeature(feature, test => {
let arcadeMachine;

beforeEach(() => {
arcadeMachine = new ArcadeMachine();
});

const givenMyMachineIsConfiguredToRequireCoins = given => {
given('my machine is configured to require coins', () => {
arcadeMachine.requireCoins = true;
});
};

const givenMyMachineIsConfiguredToAcceptUsQuarters = given => {
given('my machine is configured to accept US Quarters', () => {
arcadeMachine.acceptedCoinType = COIN_TYPES.USQuarter;
});
};

test('Successfully inserting coins', ({ given, when, then }) => {
givenMyMachineIsConfiguredToRequireCoins(given);

given('I have not inserted any coins', () => {
arcadeMachine.balance = 0;
});

when('I insert one US quarter', () => {
arcadeMachine.insertCoin(COIN_TYPES.USQuarter);
});

then(/^I should have a balance of (\d+) cents$/, balance => {
arcadeMachine.balance = balance / 100;
});
});

test('Inserting a Canadian coin', ({ given, when, then }) => {
let coinStatus;

givenMyMachineIsConfiguredToRequireCoins(given);

givenMyMachineIsConfiguredToAcceptUsQuarters(given);

when('I insert a Canadian Quarter', () => {
coinStatus = arcadeMachine.insertCoin(COIN_TYPES.CanadianQuarter);
});

then('my coin should be returned', () => {
expect(coinStatus).toBe('CoinReturned');
});
});

test('Inserting a badly damaged coin', ({ given, when, then }) => {
let coinStatus;

givenMyMachineIsConfiguredToRequireCoins(given);

givenMyMachineIsConfiguredToAcceptUsQuarters(given);

when('I insert a US Quarter that is badly damaged', () => {
coinStatus = arcadeMachine.insertCoin(COIN_TYPES.Unknown);
});

then('my coin should be returned', () => {
expect(coinStatus).toBe('CoinReturned');
});
});
});
33 changes: 17 additions & 16 deletions examples/ecmascript/specs/step-definitions/basic-scenarios.steps.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
// eslint-disable-next-line import/no-unresolved
import { defineFeature, loadFeature } from 'jest-cucumber';
import { PasswordValidator } from '../../src/password-validator';

const feature = loadFeature('./specs/features/basic-scenarios.feature');

defineFeature(feature, (test) => {
let passwordValidator = new PasswordValidator();
let accessGranted = false;
defineFeature(feature, test => {
let passwordValidator = new PasswordValidator();
let accessGranted = false;

beforeEach(() => {
passwordValidator = new PasswordValidator();
});
beforeEach(() => {
passwordValidator = new PasswordValidator();
});

test('Entering a correct password', ({ given, when, then }) => {
given('I have previously created a password', () => {
passwordValidator.setPassword('1234');
});
test('Entering a correct password', ({ given, when, then }) => {
given('I have previously created a password', () => {
passwordValidator.setPassword('1234');
});

when('I enter my password correctly', () => {
accessGranted = passwordValidator.validatePassword('1234');
});
when('I enter my password correctly', () => {
accessGranted = passwordValidator.validatePassword('1234');
});

then('I should be granted access', () => {
expect(accessGranted).toBe(true);
});
then('I should be granted access', () => {
expect(accessGranted).toBeTrue();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// eslint-disable-next-line import/no-unresolved
import { defineFeature, loadFeature } from 'jest-cucumber';
import { SeriesSolver } from '../../src/series-solver';

const feature = loadFeature('./specs/features/more-scenario-outlines.feature');

defineFeature(feature, (test) => {
defineFeature(feature, test => {
let solver;
let solution;
let terms;
Expand All @@ -13,14 +14,14 @@ defineFeature(feature, (test) => {
solver = new SeriesSolver();
});

const whenISolveTheSeries = (when) => {
const whenISolveTheSeries = when => {
when(/^I solve the series$/, () => {
solution = solver.solve(terms, operator);
});
};

const thenIShouldGetXAsTheAnswer = (then) => {
then(/^I should get (.*) as the answer$/, (expectedSolution) => {
const thenIShouldGetXAsTheAnswer = then => {
then(/^I should get (.*) as the answer$/, expectedSolution => {
expect(solution).toBe(expectedSolution);
});
};
Expand All @@ -29,27 +30,26 @@ defineFeature(feature, (test) => {
given(
/^I have a series (.*) (.*) (.*) (.*) (.*) (.*) (.*)$/,
(firstTerm, firstOperator, secondTerm, secondOperator, thirdTerm, thirdOperator, forthTerm) => {
expect(firstOperator).toEqual(secondOperator);
expect(firstOperator).toEqual(thirdOperator);
expect(firstOperator).toStrictEqual(secondOperator);
expect(firstOperator).toStrictEqual(thirdOperator);

operator = firstOperator;
terms = [firstTerm, secondTerm, thirdTerm, forthTerm];
});
},
);

whenISolveTheSeries(when);

thenIShouldGetXAsTheAnswer(then);
});

test('Adding series', ({ given, when, then }) => {
given(
/^I add the following series:$/,
(table) => {
const row = table[0];
terms = row.Series.split(` ${row.Operator} `);
operator = row.Operator;
solver.add(terms, operator, row.Solution);
});
given(/^I add the following series:$/, table => {
const row = table[0];
terms = row.Series.split(` ${row.Operator} `);
operator = row.Operator;
solver.add(terms, operator, row.Solution);
});

whenISolveTheSeries(when);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
// eslint-disable-next-line import/no-unresolved
import { defineFeature, loadFeature } from 'jest-cucumber';
import { OnlineSales } from '../../src/online-sales';

const feature = loadFeature('./specs/features/scenario-outlines.feature');

defineFeature(feature, test => {
let onlineSales;
let salesPrice;

beforeEach(() => {
onlineSales = new OnlineSales();
});
let onlineSales;
let salesPrice;

test('Selling an <Item> at $<Amount>', ({ given, when, then, pending }) => {
given(/^I have a\(n\) (.*)$/, item => {
onlineSales.listItem(item);
});
beforeEach(() => {
onlineSales = new OnlineSales();
});

when(/^I sell the (.*)$/, item => {
salesPrice = onlineSales.sellItem(item);
});
test('Selling an <Item> at $<Amount>', ({ given, when, then }) => {
given(/^I have a\(n\) (.*)$/, item => {
onlineSales.listItem(item);
});

then(/^I should get \$(\d+)$/, expectedSalesPrice => {
expect(salesPrice).toBe(parseInt(expectedSalesPrice));
});
});
});
when(/^I sell the (.*)$/, item => {
salesPrice = onlineSales.sellItem(item);
});

then(/^I should get \$(\d+)$/, expectedSalesPrice => {
expect(salesPrice).toBe(parseInt(expectedSalesPrice, 10));
});
});
});

0 comments on commit 31d7160

Please sign in to comment.