@ash-mallick/browserstack-sync 1.0.0 → 1.0.4

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.
Files changed (3) hide show
  1. package/README.md +41 -130
  2. package/lib/config.js +25 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,46 +1,40 @@
1
1
  # @ash-mallick/browserstack-sync
2
2
 
3
- **By Ashutosh Mallick** — Sync **Playwright** and **Cypress** e2e spec files to **CSV** (one per spec, with test case IDs TC-001, TC-002, …) and optionally to **BrowserStack Test Management** (one folder per spec, test cases imported).
3
+ Sync **Playwright** and **Cypress** e2e specs to CSV (TC-001, TC-002, …) and optionally to **BrowserStack Test Management** (one folder per spec, create/update test cases).
4
4
 
5
- Use it in any project that has Playwright or Cypress e2e tests. Configure paths per project and run via **`am-browserstack-sync`** with `npx` or as a dependency.
5
+ **By Ashutosh Mallick**
6
6
 
7
7
  ---
8
8
 
9
- ## Use in your project
10
-
11
- ### 1. Install
9
+ ## Install
12
10
 
13
11
  ```bash
14
12
  npm install @ash-mallick/browserstack-sync
15
- # or run without installing
16
- npx @ash-mallick/browserstack-sync --csv-only
17
13
  ```
18
14
 
19
- ### 2. Run
15
+ Or run without installing: `npx @ash-mallick/browserstack-sync --csv-only`
16
+
17
+ ---
18
+
19
+ ## Run
20
20
 
21
- From your **project root** (where your `playwright/e2e` or Cypress specs live):
21
+ From your project root (where your e2e specs live):
22
22
 
23
23
  ```bash
24
- # CSV only (no BrowserStack API calls)
24
+ # Generate CSVs only
25
25
  npx am-browserstack-sync --csv-only
26
26
 
27
- # Sync to BrowserStack interactive: choose all specs or pick specific ones
27
+ # Sync to BrowserStack (interactive: choose all or specific specs)
28
28
  npx am-browserstack-sync
29
29
 
30
- # Sync all specs (no prompt, e.g. for CI)
30
+ # Sync all specs, no prompt (e.g. CI)
31
31
  npx am-browserstack-sync --all
32
32
 
33
- # Sync only specific spec(s)
34
- npx am-browserstack-sync --spec=login.spec
33
+ # Sync only certain specs
35
34
  npx am-browserstack-sync --spec=login.spec,checkout.spec
36
35
  ```
37
36
 
38
- If you installed the package, the command is `am-browserstack-sync`. With `npx` you can use either:
39
-
40
- - `npx am-browserstack-sync` (uses the bin name)
41
- - `npx @ash-mallick/browserstack-sync` (runs the package)
42
-
43
- Add scripts in your project’s `package.json`:
37
+ **Scripts** in `package.json`:
44
38
 
45
39
  ```json
46
40
  {
@@ -51,22 +45,21 @@ Add scripts in your project’s `package.json`:
51
45
  }
52
46
  ```
53
47
 
54
- Then: `npm run sync:e2e-csv` or `npm run sync:e2e`.
55
-
56
- ### 3. Configure (optional)
57
-
58
- Defaults:
48
+ ---
59
49
 
60
- - **E2E directory:** `playwright/e2e`
61
- - **CSV output:** `playwright/e2e-csv`
50
+ ## Config (optional)
62
51
 
63
- For **Cypress**, set `e2eDir` to your specs folder (e.g. `cypress/e2e`, `cypress/integration`, or `cypress/specs`).
52
+ **Auto-detection:** The tool automatically detects your e2e directory structure:
64
53
 
65
- Override in one of these ways (first wins):
54
+ | Priority | Directory | CSV Output |
55
+ |----------|-----------|------------|
56
+ | 1st | `playwright/e2e` | `playwright/e2e-csv` |
57
+ | 2nd | `cypress/e2e` | `cypress/e2e-csv` |
58
+ | 3rd | `e2e` | `e2e-csv` |
66
59
 
67
- **A) Config file** in project root
60
+ No config needed for standard Playwright or Cypress projects!
68
61
 
69
- Create `.am-browserstack-sync.json` or `am-browserstack-sync.config.json`:
62
+ **Override** via **`.am-browserstack-sync.json`** in project root:
70
63
 
71
64
  ```json
72
65
  {
@@ -75,137 +68,55 @@ Create `.am-browserstack-sync.json` or `am-browserstack-sync.config.json`:
75
68
  }
76
69
  ```
77
70
 
78
- (Legacy names `.am-e2e-sync.json`, `playwright-browserstack-sync.config.json`, etc. are still supported.)
71
+ Or **package.json**: `"amBrowserstackSync": { "e2eDir": "...", "csvOutputDir": "..." }`
72
+ Or env: `PLAYWRIGHT_BROWSERSTACK_E2E_DIR`, `PLAYWRIGHT_BROWSERSTACK_CSV_DIR`.
79
73
 
80
- **B) package.json**
81
-
82
- ```json
83
- {
84
- "amBrowserstackSync": {
85
- "e2eDir": "tests/e2e",
86
- "csvOutputDir": "tests/e2e-csv"
87
- }
88
- }
89
- ```
90
-
91
- (Legacy fields `amE2eSync`, `playwrightBrowserstackSync` are also supported.)
92
-
93
- **C) Environment**
74
+ ---
94
75
 
95
- - `PLAYWRIGHT_BROWSERSTACK_E2E_DIR` – e2e directory (relative to cwd)
96
- - `PLAYWRIGHT_BROWSERSTACK_CSV_DIR` – CSV output directory
76
+ ## BrowserStack sync
97
77
 
98
- ### 4. BrowserStack sync
78
+ Sync pushes your e2e tests into **BrowserStack Test Management** so you can track test cases, link runs, and keep specs in sync with one source of truth. Under your chosen project it creates **one folder per spec file** (e.g. `login.spec`, `checkout.spec`) and one **test case** per test, with title, description, steps, state (Active), type (Functional), automation status, and tags. Existing test cases are matched by title or TC-id and **updated**; new ones are **created**. No duplicates.
99
79
 
100
- To push test cases to BrowserStack Test Management:
80
+ **Setup:**
101
81
 
102
- 1. In your project root, create a `.env` file (do not commit it):
82
+ 1. In project root, create **`.env`** (do not commit):
103
83
 
104
84
  ```env
105
85
  BROWSERSTACK_USERNAME=your_username
106
86
  BROWSERSTACK_ACCESS_KEY=your_access_key
107
87
  BROWSERSTACK_PROJECT_ID=PR-XXXX
108
88
  ```
109
-
110
89
  Or use a single token: `BROWSERSTACK_API_TOKEN=your_token`
111
90
 
112
- 2. Get credentials and project ID from [BrowserStack Test Management → API keys](https://test-management.browserstack.com/settings/api-keys). Project ID is in the project URL (e.g. `PR-1234`).
113
-
114
- 3. Run without `--csv-only`:
115
-
116
- ```bash
117
- npx am-browserstack-sync
118
- ```
119
-
120
- The tool will:
91
+ 2. Get credentials and project ID from [Test Management → API keys](https://test-management.browserstack.com/settings/api-keys). The project ID is in the project URL (e.g. `PR-1234`).
121
92
 
122
- - Create **one folder per spec file** under your project (e.g. `login.spec`, `checkout.spec`).
123
- - **Create** test cases that don’t exist yet; **update** existing ones (matched by title or TC-id tag). No duplicates.
124
- - When you change a test in the repo and run sync again, the corresponding test case on BrowserStack is updated.
93
+ 3. Run **`npx am-browserstack-sync`** (without `--csv-only`). You’ll be prompted to sync all specs or pick specific ones (unless you use `--all` or `--spec=...`). After sync, open your project in BrowserStack to see the new folders and test cases.
125
94
 
126
95
  ---
127
96
 
128
97
  ## What it does
129
98
 
130
- 1. **Analyzes** all spec files in your e2e dir:
131
- - **Playwright:** `*.spec.ts`, `*.spec.js`, `*.test.ts`, `*.test.js`
132
- - **Cypress:** `*.cy.ts`, `*.cy.js`
133
- 2. **Extracts** test titles from `test('...')` and `it('...')` (ignores `describe`).
134
- 3. **Enriches** each test with defaults: State **Active**, Type **Functional**, **automated**, plus inferred **tags** (framework: `playwright` or `cypress`, plus spec name and title).
135
- 4. **Writes one CSV per spec** with columns: `test_case_id`, `title`, `state`, `case_type`, `steps`, `expected_results`, `jira_issues`, `automation_status`, `tags`, `description`, `spec_file`.
136
- 5. **Optionally** syncs to BrowserStack: creates folders, creates/updates test cases with description, steps, expected results, state, type, automation status, and tags.
137
-
138
- ### CSV columns and BrowserStack fields
139
-
140
- | Column / field | Description | Default / example |
141
- |----------------|-------------|-------------------|
142
- | **title** | Test case title | From spec `test('...')` / `it('...')` |
143
- | **state** | Lifecycle state | `Active` (or Draft, In Review, Outdated, Rejected) |
144
- | **case_type** | Type of test | `Functional` (or Smoke & Sanity, Regression, etc.) |
145
- | **steps** | Test steps with expected result | "Step 1: Run Playwright/Cypress e2e test \| Expected: See spec file..." |
146
- | **expected_results** | Expected outcome | Filled from step results |
147
- | **jira_issues** | Linked Jira keys | Empty (comma-separated in CSV) |
148
- | **automation_status** | Automated or not | `automated` |
149
- | **tags** | Functionality / labels | Inferred from spec name + title plus `playwright`/`cypress`, `e2e` |
150
- | **description** | Test description | "Playwright/Cypress e2e test. ID: TC-001. [title]" |
99
+ - Finds **Playwright** (`*.spec.*`, `*.test.*`) and **Cypress** (`*.cy.*`) spec files in your e2e dir.
100
+ - Extracts test titles from `test('...')` / `it('...')`, assigns TC-001, TC-002, …
101
+ - Enriches with state (Active), type (Functional), automation (automated), tags (from spec + title).
102
+ - Writes **one CSV per spec** (test_case_id, title, state, case_type, steps, expected_results, jira_issues, automation_status, tags, description, spec_file).
103
+ - Optionally syncs to BrowserStack with description, steps, and tags.
151
104
 
152
105
  ---
153
106
 
154
107
  ## Programmatic API
155
108
 
156
- You can import the package and call `runSync` from your own scripts:
157
-
158
109
  ```js
159
110
  import { runSync } from '@ash-mallick/browserstack-sync';
160
111
 
161
112
  await runSync({
162
- cwd: '/path/to/your/project',
113
+ cwd: '/path/to/project',
163
114
  csvOnly: true,
164
- all: true, // skip interactive prompt, sync all specs
165
- spec: ['login.spec'], // or sync only these specs
166
- // optional: e2eDir, csvOutputDir, auth: { username, accessKey, projectId },
115
+ all: true,
116
+ spec: ['login.spec'],
167
117
  });
168
118
  ```
169
119
 
170
120
  ---
171
121
 
172
- ## Publishing this package
173
-
174
- 1. **Package name** is `@ash-mallick/browserstack-sync`. The CLI command is **`am-browserstack-sync`**.
175
-
176
- 2. **Set repository URL** in `package.json` (optional):
177
- ```json
178
- "repository": { "type": "git", "url": "https://github.com/ash-mallick/browserstack-sync" }
179
- ```
180
-
181
- 3. **Publish to npm:**
182
- ```bash
183
- npm login
184
- npm publish --access public
185
- ```
186
- (Scoped packages require `--access public` for public installs.)
187
-
188
- 4. **Use it in another project:**
189
- ```bash
190
- npm install @ash-mallick/browserstack-sync
191
- npx am-browserstack-sync --csv-only
192
- ```
193
-
194
- ---
195
-
196
- ## This repo as a demo
197
-
198
- This repository is the package source and includes sample specs under `playwright/e2e/`. To run the sync **in this repo**:
199
-
200
- ```bash
201
- npm install
202
- npm run sync:csv-only
203
- # or with .env set:
204
- npm run sync:csv
205
- ```
206
-
207
- CSVs are written to `playwright/e2e-csv/`.
208
-
209
- ---
210
-
211
122
  **Author:** Ashutosh Mallick
package/lib/config.js CHANGED
@@ -11,19 +11,37 @@ const CONFIG_FILES = [
11
11
  '.config/am-browserstack-sync.json',
12
12
  ];
13
13
 
14
- const DEFAULTS = {
15
- e2eDir: 'playwright/e2e',
16
- csvOutputDir: 'playwright/e2e-csv',
17
- };
14
+ /**
15
+ * Auto-detect e2e directory based on common framework structures.
16
+ * Checks for existence in order: playwright/e2e, cypress/e2e, then fallback.
17
+ */
18
+ function detectE2eDir(resolvedCwd) {
19
+ const candidates = [
20
+ { e2eDir: 'playwright/e2e', csvOutputDir: 'playwright/e2e-csv' },
21
+ { e2eDir: 'cypress/e2e', csvOutputDir: 'cypress/e2e-csv' },
22
+ { e2eDir: 'e2e', csvOutputDir: 'e2e-csv' }, // Generic fallback
23
+ ];
24
+ for (const candidate of candidates) {
25
+ const fullPath = path.join(resolvedCwd, candidate.e2eDir);
26
+ if (fs.existsSync(fullPath)) {
27
+ return candidate;
28
+ }
29
+ }
30
+ // Default to playwright if nothing found (user will see "directory not found" error)
31
+ return { e2eDir: 'playwright/e2e', csvOutputDir: 'playwright/e2e-csv' };
32
+ }
18
33
 
19
34
  /**
20
- * Load config from cwd: env > config file > package.json field > defaults.
35
+ * Load config from cwd: env > config file > package.json field > auto-detect.
21
36
  * Returns { cwd, e2eDir, csvOutputDir } (paths are absolute).
22
37
  */
23
38
  export function loadConfig(cwd) {
24
39
  const resolvedCwd = path.resolve(cwd || process.cwd());
25
- let e2eDir = DEFAULTS.e2eDir;
26
- let csvOutputDir = DEFAULTS.csvOutputDir;
40
+
41
+ // Auto-detect based on existing directory structure
42
+ const detected = detectE2eDir(resolvedCwd);
43
+ let e2eDir = detected.e2eDir;
44
+ let csvOutputDir = detected.csvOutputDir;
27
45
 
28
46
  // package.json field
29
47
  const pkgPath = path.join(resolvedCwd, 'package.json');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ash-mallick/browserstack-sync",
3
- "version": "1.0.0",
3
+ "version": "1.0.4",
4
4
  "description": "Sync Playwright & Cypress e2e specs to CSV and BrowserStack Test Management (one folder per spec)",
5
5
  "author": "Ashutosh Mallick",
6
6
  "type": "module",