Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/publish-to-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
cache: npm
- run: npm ci
- run: npm run test:unit -- --runInBand
# Tests build dist/ with source maps; rebuild without them before packing.
- run: npm run build
- run: npm pack --dry-run
- run: npm publish --access public
env:
Expand Down
3 changes: 3 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
```bash
npm ci
npm test -- --runInBand
npm run build
npm pack --dry-run
```

Tests build `dist/` with source maps for coverage. Run `npm run build` before `npm pack` so the package contains no `.map` files. `npm publish` does this automatically via `prepublishOnly`.

Real API tests require `CAPTCHA_API_KEY` and the target variables documented in `tests/README.md`:

```bash
Expand Down
11 changes: 8 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
export default {
testEnvironment: 'node',

// Collect coverage from every file in src/, not just the ones imported
// by tests. Otherwise a new file that nothing imports yet would silently
// drop out of the report instead of showing up as 0%.
// Tests import the built package from dist/, so that is what gets
// instrumented. `npm run build:test` emits source maps, which map the
// report back to src/*.ts instead of hashed dist/chunk-*.js files.
//
// Only the ESM build (*.js) is listed: the CommonJS build (*.cjs) is loaded
// through Node's native require() and is never instrumented by Jest, so
// listing it would only add bogus 0% entries. public-api.test.js covers it
// with smoke tests instead.
collectCoverageFrom: ['dist/**/*.js'],

// text -- console output, lcov -- for uploading to Coveralls.
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
],
"scripts": {
"build": "tsup src/index.ts src/tasks.ts src/exceptions.ts --format esm,cjs --dts --clean",
"build:test": "npm run build -- --sourcemap",
"typecheck": "tsc --noEmit",
"test": "npm run build && node --experimental-vm-modules node_modules/jest/bin/jest.js",
"test:unit": "npm run build && node --experimental-vm-modules node_modules/jest/bin/jest.js tests/unit",
"test:integration": "npm run build && node --experimental-vm-modules node_modules/jest/bin/jest.js tests/integration",
"prepublishOnly": "npm run test:unit -- --runInBand"
"test": "npm run build:test && node --experimental-vm-modules node_modules/jest/bin/jest.js",
"test:unit": "npm run build:test && node --experimental-vm-modules node_modules/jest/bin/jest.js tests/unit",
"test:integration": "npm run build:test && node --experimental-vm-modules node_modules/jest/bin/jest.js tests/integration",
"prepublishOnly": "npm run test:unit -- --runInBand && npm run build"
},
"keywords": [
"captcha-solver",
Expand Down
14 changes: 7 additions & 7 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,20 +388,20 @@ Current state:

```
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
All files | 97.53 | 83.63 | 100 | 97.5 |
client.js | 95.45 | 80.76 | 100 | 95.34 | 35,53
exceptions.js | 100 | 100 | 100 | 100 |
index.js | 100 | 100 | 100 | 100 |
tasks.js | 100 | 84.52 | 100 | 100 | 26,38,71-77,89,107
All files | 98.4 | 87.5 | 100 | 100 |
client.ts | 97.67 | 96.66 | 100 | 100 | 195
exceptions.ts | 100 | 100 | 100 | 100 |
tasks.ts | 98.41 | 85.08 | 100 | 100 | 28,232,284-493,579-623,682-695
version.ts | 100 | 100 | 100 | 100 |
```

What is uncovered: the HTTP error branch (`!response.ok`) and the `AbortError` handling in `_request()`, plus some default parameter values in the task constructors.
What is uncovered: the second timeout check in `solve()` (it needs fake timers to hit) and default parameter values in the task constructors.

The figure counts **unit tests only**. Integration is deliberately left out: without a key those suites skip, and the number would swing depending on whether `CAPTCHA_API_KEY` happened to be available.

Two settings in [jest.config.js](../jest.config.js) matter specifically for coverage:

- `collectCoverageFrom: ['dist/**/*.{js,cjs}']` — count every JavaScript file in the built `dist/` package, including the public entry point, even when a test does not import it directly.
- `collectCoverageFrom: ['dist/**/*.js']` — instrument the built ESM package in `dist/`, since that is what the tests import. `npm run build:test` emits source maps, so the report is mapped back to `src/*.ts` instead of hashed `dist/chunk-*.js` files, and the file list stays stable in Coveralls. The CommonJS build (`*.cjs`) is loaded through Node's native `require()` and is never instrumented by Jest, so it is not listed; `public-api.test.js` covers it with smoke tests instead.
- `coverageReporters: ['text', 'lcov']` — `text` for the console, `lcov` for the Coveralls upload from CI.

Artifacts are written to `coverage/` (gitignored).
Expand Down
Loading