@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.
- package/README.md +41 -130
- package/lib/config.js +25 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,46 +1,40 @@
|
|
|
1
1
|
# @ash-mallick/browserstack-sync
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
5
|
+
**By Ashutosh Mallick**
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
##
|
|
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
|
-
|
|
15
|
+
Or run without installing: `npx @ash-mallick/browserstack-sync --csv-only`
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Run
|
|
20
20
|
|
|
21
|
-
From your
|
|
21
|
+
From your project root (where your e2e specs live):
|
|
22
22
|
|
|
23
23
|
```bash
|
|
24
|
-
#
|
|
24
|
+
# Generate CSVs only
|
|
25
25
|
npx am-browserstack-sync --csv-only
|
|
26
26
|
|
|
27
|
-
# Sync to BrowserStack
|
|
27
|
+
# Sync to BrowserStack (interactive: choose all or specific specs)
|
|
28
28
|
npx am-browserstack-sync
|
|
29
29
|
|
|
30
|
-
# Sync all specs
|
|
30
|
+
# Sync all specs, no prompt (e.g. CI)
|
|
31
31
|
npx am-browserstack-sync --all
|
|
32
32
|
|
|
33
|
-
# Sync only
|
|
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
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
### 3. Configure (optional)
|
|
57
|
-
|
|
58
|
-
Defaults:
|
|
48
|
+
---
|
|
59
49
|
|
|
60
|
-
|
|
61
|
-
- **CSV output:** `playwright/e2e-csv`
|
|
50
|
+
## Config (optional)
|
|
62
51
|
|
|
63
|
-
|
|
52
|
+
**Auto-detection:** The tool automatically detects your e2e directory structure:
|
|
64
53
|
|
|
65
|
-
|
|
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
|
-
|
|
60
|
+
No config needed for standard Playwright or Cypress projects!
|
|
68
61
|
|
|
69
|
-
|
|
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
|
-
|
|
71
|
+
Or **package.json**: `"amBrowserstackSync": { "e2eDir": "...", "csvOutputDir": "..." }`
|
|
72
|
+
Or env: `PLAYWRIGHT_BROWSERSTACK_E2E_DIR`, `PLAYWRIGHT_BROWSERSTACK_CSV_DIR`.
|
|
79
73
|
|
|
80
|
-
|
|
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
|
-
|
|
96
|
-
- `PLAYWRIGHT_BROWSERSTACK_CSV_DIR` – CSV output directory
|
|
76
|
+
## BrowserStack sync
|
|
97
77
|
|
|
98
|
-
|
|
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
|
-
|
|
80
|
+
**Setup:**
|
|
101
81
|
|
|
102
|
-
1. In
|
|
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 [
|
|
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
|
-
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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/
|
|
113
|
+
cwd: '/path/to/project',
|
|
163
114
|
csvOnly: true,
|
|
164
|
-
all: true,
|
|
165
|
-
spec: ['login.spec'],
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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 >
|
|
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
|
-
|
|
26
|
-
|
|
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