playwright-cucumber-ts-steps 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/core/runner.ts"],"names":[],"mappings":"AAMA,OAAO,0BAA0B,CAAC;AAClC,OAAO,6BAA6B,CAAC;AACrC,OAAO,2BAA2B,CAAC;AACnC,OAAO,sBAAsB,CAAC;AAC9B,OAAO,uBAAuB,CAAC;AAE/B,OAAO,qBAAqB,CAAC;AAE7B,UAAU,aAAa;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CAC3C;AAED,wBAAgB,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,QAmGpE"}
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/core/runner.ts"],"names":[],"mappings":"AAOA,OAAO,0BAA0B,CAAC;AAClC,OAAO,6BAA6B,CAAC;AACrC,OAAO,2BAA2B,CAAC;AACnC,OAAO,sBAAsB,CAAC;AAC9B,OAAO,uBAAuB,CAAC;AAE/B,OAAO,qBAAqB,CAAC;AAE7B,UAAU,aAAa;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CAC3C;AAED,wBAAgB,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,QA2GpE"}
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.runTests = runTests;
37
+ // src/core/runner.ts
37
38
  const test_1 = require("@playwright/test");
38
39
  const fs = __importStar(require("fs"));
39
40
  const glob_1 = require("glob");
@@ -51,9 +52,9 @@ function runTests(featureGlob, options) {
51
52
  state_1.dbState.setAdapter(options.dbQuery);
52
53
  }
53
54
  const files = (0, glob_1.globSync)(featureGlob);
54
- if (files.length === 0) {
55
- console.warn(`⚠️ No feature files found for pattern: ${featureGlob}`);
56
- }
55
+ // SUPPORT ENV VAR TAGS (Alternative to -g)
56
+ // If user runs: TAGS='@login' npx playwright test
57
+ const envTag = process.env.TAGS;
57
58
  for (const file of files) {
58
59
  const content = fs.readFileSync(file, "utf8");
59
60
  const featureMatch = content.match(/Feature:\s*(.+)/);
@@ -61,20 +62,31 @@ function runTests(featureGlob, options) {
61
62
  ? featureMatch[1].trim()
62
63
  : "Unnamed Feature";
63
64
  test_1.test.describe(featureName, () => {
64
- // 1. SAFE SCENARIO REGEX
65
65
  const scenarioRegex = /(?:(@[^:\r\n]+)\s+)?Scenario:\s*(.+)/g;
66
66
  let match;
67
67
  while ((match = scenarioRegex.exec(content)) !== null) {
68
68
  const foundTags = match[1] || "";
69
69
  const scenarioName = match[2].trim();
70
+ // 🔥 1. APPEND TAGS TO TITLE
71
+ // This allows 'npx playwright test -g @login' to work natively
72
+ const fullName = foundTags
73
+ ? `${scenarioName} ${foundTags}`
74
+ : scenarioName;
75
+ // 🔥 2. FILTER LOGIC
76
+ // Filter by Code Options OR Env Variable
77
+ const activeFilter = options?.tags || envTag;
78
+ if (activeFilter) {
79
+ // Allow comma separated tags (OR logic): "@login,@regression"
80
+ const targetTags = activeFilter.split(",").map((t) => t.trim());
81
+ const hasMatch = targetTags.some((t) => foundTags.includes(t));
82
+ if (!hasMatch)
83
+ continue;
84
+ }
70
85
  const startIndex = match.index + match[0].length;
71
86
  const nextMatchIndex = content.slice(startIndex).search(/Scenario:/);
72
87
  const blockEnd = nextMatchIndex === -1 ? content.length : startIndex + nextMatchIndex;
73
88
  const scenarioBlock = content.slice(startIndex, blockEnd);
74
- if (options?.tags && !foundTags.includes(options.tags)) {
75
- continue;
76
- }
77
- (0, test_1.test)(scenarioName, async ({ page }, testInfo) => {
89
+ (0, test_1.test)(fullName, async ({ page }, testInfo) => {
78
90
  const lines = scenarioBlock
79
91
  .trim()
80
92
  .split("\n")
@@ -100,7 +112,6 @@ function runTests(featureGlob, options) {
100
112
  .replace(/^(Given|When|Then|And|But)\s+/i, "")
101
113
  .replace(/:$/, "")
102
114
  .trim();
103
- // 2. SMART STEP MATCHING
104
115
  const matchResult = findMatchingStep(cleanStep);
105
116
  if (!matchResult) {
106
117
  throw new Error(`❌ Undefined Step: "${cleanStep}"`);
@@ -109,7 +120,6 @@ function runTests(featureGlob, options) {
109
120
  const args = [...matchResult.args];
110
121
  if (tableData.length > 0)
111
122
  args.push(tableData);
112
- console.log(`✅ Executing: ${cleanStep}`);
113
123
  await matchResult.fn(page, ...args);
114
124
  }
115
125
  catch (error) {
@@ -130,32 +140,24 @@ function runTests(featureGlob, options) {
130
140
  });
131
141
  }
132
142
  }
133
- // 3. ROBUST FINDER FUNCTION
134
143
  function findMatchingStep(text) {
135
144
  for (const step of registry_1.stepRegistry) {
136
- // A. Handle RegExp (If you defined steps with Regex)
137
145
  if (step.expression instanceof RegExp) {
138
146
  const match = step.expression.exec(text);
139
- if (match) {
147
+ if (match)
140
148
  return { fn: step.fn, args: match.slice(1) };
141
- }
142
149
  }
143
- // B. Handle Cucumber Expressions (The Objects we saw in your logs)
144
- // We check if it has a .match() method
145
150
  else if (typeof step.expression.match === "function") {
146
151
  const match = step.expression.match(text);
147
- if (match) {
152
+ if (match)
148
153
  return {
149
154
  fn: step.fn,
150
155
  args: match.map((arg) => arg.getValue(null)),
151
156
  };
152
- }
153
157
  }
154
- // C. Handle Simple Strings
155
158
  else if (typeof step.expression === "string") {
156
- if (step.expression === text) {
159
+ if (step.expression === text)
157
160
  return { fn: step.fn, args: [] };
158
- }
159
161
  }
160
162
  }
161
163
  return null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "playwright-cucumber-ts-steps",
3
3
  "description": "A collection of reusable Playwright step definitions for Cucumber in TypeScript, designed to streamline end-to-end testing across web, API, and mobile applications.",
4
- "version": "1.1.1",
4
+ "version": "1.1.2",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",