Skip to content

Commit

Permalink
Merge pull request #30 from thelazurite-cell/refactor/update-cucumber…
Browse files Browse the repository at this point in the history
…-lib/issue-22

refactor(cucumber library): update to the latest cucumber library ver…
  • Loading branch information
Arthy000 authored Mar 8, 2021
2 parents 8238ee5 + 8094257 commit 68d65c3
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
*.iml
.idea
.npmrc
.npmrc
package-lock.json
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ Once official support is established, this package will be abandoned.

Install `gherkin-testcafe` and `cucumber`<sup>1</sup> via npm or yarn:

npm i gherkin-testcafe cucumber
npm i gherkin-testcafe @cucumber/cucumber

or

yarn add gherkin-testcafe cucumber
yarn add gherkin-testcafe @cucumber/cucumber

You may also install gherkin-testcafe globally in order to be able to use the
CLI without npx.
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-param-type-registry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ParameterTypeRegistry, ParameterType } = require('cucumber-expressions');
const { ParameterTypeRegistry, ParameterType } = require('@cucumber/cucumber-expressions');

class Color {
constructor(name) {
Expand Down
3 changes: 2 additions & 1 deletion examples/custom-param-type.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Feature: Using custom parameter types
@googleHook
Scenario: Searching for color in Google
Given I open Google's search page
When I am searching for the blue color on Google
When I dismiss the privacy statement when it appears
And I am searching for the blue color on Google
And I am pressing "enter" key on Google
Then I should see the #0000FF value in the page
2 changes: 1 addition & 1 deletion examples/custom-param-type.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { When, Then } from 'cucumber';
import { When, Then } from '@cucumber/cucumber';
import { Selector as NativeSelector } from 'testcafe';

const Selector = (input, t) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/datatable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cucumber';
import { Given, When, Then } from '@cucumber/cucumber';
import { Selector as NativeSelector } from 'testcafe';

const Selector = (input, t) => {
Expand Down
6 changes: 4 additions & 2 deletions examples/google.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ Feature: The big search feature
@googleHook
Scenario: Searching for TestCafe by Google
Given I open Google's search page
When I am typing my search request "github TestCafe" on Google
When I dismiss the privacy statement when it appears
And I am typing my search request "github TestCafe" on Google
And I am pressing "enter" key on Google
Then I should see that the first Google's result is "DevExpress/testcafe:"

Scenario Outline: Searching for <keyword> on Google
Given I open Google's search page
When I am typing my search request "<keyword>" on Google
When I dismiss the privacy statement when it appears
And I am typing my search request "<keyword>" on Google
And I am pressing "enter" key on Google
Then I should see that the first Google's result is "<result-text>"

Expand Down
20 changes: 18 additions & 2 deletions examples/google.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Given, When, Then, Before } from 'cucumber';
import { Selector as NativeSelector } from 'testcafe';
import { Given, When, Then, Before } from '@cucumber/cucumber';
import { ClientFunction, Selector as NativeSelector } from 'testcafe';

const Selector = (input, t) => {
return NativeSelector(input).with({ boundTestRun: t });
Expand All @@ -13,6 +13,14 @@ Given("I open Google's search page", async t => {
await t.navigateTo('https://www.google.com');
});

When(/^I dismiss the privacy statement when it appears$/, async (t) => {
const elem = Selector('#lb > div > div:nth-child(1)', t);
await t.expect(elem.exists).eql(true, 'The privacy statement should be displayed', { timeout: 5000 });

// forcefully remove as it seems google knows when an automated session is running
await removeElement(t, '#lb');
});

When(/^I am typing my search request "(.+)" on Google$/, async (t, [searchRequest]) => {
const input = Selector('[name="q"]', t);

Expand All @@ -28,3 +36,11 @@ Then(/^I should see that the first Google's result is "(.+)"$/, async (t, [expec

await t.expect(firstLink.innerText).contains(expectedSearchResult);
});

async function removeElement(t, elementSelector) {
await ClientFunction((elementSelector) => {
const element = document.querySelector(elementSelector);
element.parentNode.removeChild(element);
}).with(t)(elementSelector);
}

4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ declare module 'gherkin-testcafe' {
declare module 'cucumber' {
import { t } from 'testcafe';

export interface TableDefinition {
export interface DataTable {
/** Returns the table as a 2-D array. */
raw(): string[][];

Expand All @@ -61,7 +61,7 @@ declare module 'cucumber' {
export type StepFunction = (
testController: typeof t,
parameters: any[],
dataTable: TableDefinition | null
dataTable: DataTable | null
) => Promise<void>;

export function Given(pattern: RegExp | string, code: StepFunction): void;
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@
"release": "standard-version"
},
"dependencies": {
"@cucumber/cucumber": "^7.0.0",
"@cucumber/cucumber-expressions": "^12.0.0",
"gherkin": "^8.1.1"
},
"peerDependencies": {
"cucumber": "^5.1.0",
"@cucumber/cucumber": "^7.0.0",
"@cucumber/cucumber-expressions": "^12.0.0",
"testcafe": "^1.10.1"
},
"devDependencies": {
"commitizen": "^4.2.1",
"cucumber": "^5.1.0",
"cz-conventional-changelog": "3.3.0",
"prettier": "^1.17.1",
"standard-version": "^9.1.0",
Expand Down
20 changes: 10 additions & 10 deletions src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ const Fixture = require('testcafe/lib/api/structure/fixture');
const Test = require('testcafe/lib/api/structure/test');
const { GeneralError } = require('testcafe/lib/errors/runtime');
const { RUNTIME_ERRORS } = require('testcafe/lib/errors/types');
const { supportCodeLibraryBuilder } = require('cucumber');
const DataTable = require('cucumber/lib/models/data_table').default;
const supportCodeLibraryBuilder = require('@cucumber/cucumber/lib/support_code_library_builder').default;
const DataTable = require('@cucumber/cucumber/lib/models/data_table').default;
const testRunTracker = require('testcafe/lib/api/test-run-tracker');
const cucumberExpressions = require('cucumber-expressions');
const cucumberExpressions = require('@cucumber/cucumber-expressions');
const TestcafeESNextCompiler = require('testcafe/lib/compiler/test-file/formats/es-next/compiler');
const TestcafeTypescriptCompiler = require('testcafe/lib/compiler/test-file/formats/typescript/compiler');
const CustomizableCompilers = require('testcafe/lib/configuration/customizable-compilers');
const { readFileSync } = require('fs');
const { IdGenerator } = require('@cucumber/messages');
const chalk = require('chalk');

const AND_SEPARATOR = ' and ';
Expand Down Expand Up @@ -157,10 +158,9 @@ module.exports = class GherkinTestcafeCompiler {
.after(ctx => this._runFeatureHooks(ctx, this.afterAllHooks))
.meta(
'tags',
`${
gherkinDocument.feature.tags.length > 0
? gherkinDocument.feature.tags.map(tag => tag.name).reduce((acc, cur) => `${acc},${cur}`)
: ''
`${gherkinDocument.feature.tags.length > 0
? gherkinDocument.feature.tags.map(tag => tag.name).reduce((acc, cur) => `${acc},${cur}`)
: ''
}`
);

Expand Down Expand Up @@ -212,7 +212,7 @@ module.exports = class GherkinTestcafeCompiler {
}

async _loadStepDefinitions() {
supportCodeLibraryBuilder.reset(process.cwd());
supportCodeLibraryBuilder.reset(process.cwd(), IdGenerator.uuid());

const compilerResult = this.externalCompilers.map(async externalCompiler => {
const testFiles = this.stepFiles.filter(filename => {
Expand Down Expand Up @@ -246,7 +246,7 @@ module.exports = class GherkinTestcafeCompiler {

await Promise.all(compilerResult);

supportCodeLibraryBuilder.options.parameterTypeRegistry = this.cucumberExpressionParamRegistry;
supportCodeLibraryBuilder.parameterTypeRegistry = this.cucumberExpressionParamRegistry;
const finalizedStepDefinitions = supportCodeLibraryBuilder.finalize();
this.afterHooks = finalizedStepDefinitions.afterTestCaseHookDefinitions;
this.afterAllHooks = finalizedStepDefinitions.afterTestRunHookDefinitions;
Expand Down Expand Up @@ -361,5 +361,5 @@ module.exports = class GherkinTestcafeCompiler {
return ['.js', '.ts', '.feature'];
}

static cleanUp() {}
static cleanUp() { }
};

0 comments on commit 68d65c3

Please sign in to comment.