Skip to content

test: add node:test framework with a seed pricing test (#25) - #32

Merged
Carl723000 merged 2 commits into
ClaudeCodeUsage:mainfrom
nickearnshaw:nickearnshaw/add-test-framework
Jun 15, 2026
Merged

Carl723000 merged 2 commits into
ClaudeCodeUsage:mainfrom
nickearnshaw:nickearnshaw/add-test-framework

Conversation

@nickearnshaw

Copy link
Copy Markdown
Contributor

Closes #25.

Sets up a lightweight test foundation using Node's built-in test runner (node:test + node:assert) against compiled output — the approach you preferred in the issue, with zero new dependencies. Branched off fresh main (v2.0.2) as you suggested.

What's here

Kept intentionally to a single seed test so the pattern is clear without a big drop:

  • src/test/pricing.test.ts — covers pricing.ts because it's pure logic with no vscode import. Two assertions: known-model cost calculation (Opus current tier → $36.75 for 1M of each token type) and the family-aware fallback for an unrecognised snapshot.
  • package.json — test script: npm run compile && node --test "out/test/**/*.test.js". Tests live in src/test/, so tsc (rootDir: src) emits them to out/test/.
  • .vscodeignore — adds out/test/** so the compiled tests never ship in the .vsix (verified with vsce ls).
  • .github/workflows/test.yml — runs npm test on pushes to main and on every PR.

Notes for review

  • Only pure, dependency-free modules belong in this harness. Anything touching the live vscode API would need the heavier @vscode/test-electron setup — out of scope here.
  • The repo's tsconfig.json has no esModuleInterop, so the test uses namespace imports (import { test } / import * as assert) rather than default imports.
  • The CI workflow reports a check but won't block merge until Test is added as a required status check in the repo's branch-protection settings — that's an owner-side step.

Local run: npm test → 2 pass, 0 fail. Natural next targets following the same pattern: aggregation, quota-window handling, and i18n.

🤖 Generated with Claude Code

nickearnshaw and others added 2 commits June 12, 2026 23:02
…ge#25)

Adds a lightweight test setup using Node's built-in test runner
(node:test + node:assert) against compiled output — zero new
dependencies, per the maintainer's preference on issue ClaudeCodeUsage#25.

- src/test/pricing.test.ts: one seed test covering known-model cost
  calculation and family-aware pricing fallback. Tests live in
  src/test/ so tsc (rootDir: src) emits them to out/test/.
- package.json: `test` script compiles then runs `node --test` over
  out/test/**/*.test.js.
- .vscodeignore: keep compiled tests out of the published .vsix.
- .github/workflows/test.yml: run `npm test` on pushes to main and on
  every PR.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
CI runs Node 20, whose `node --test` does not expand glob patterns
(that landed in Node 21), so the quoted "out/test/**/*.test.js" was
passed literally and matched nothing. Drop the quotes and use a
single-level glob the shell expands into real file paths — portable
across Node versions and both bash/dash.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nickearnshaw

Copy link
Copy Markdown
Contributor Author

@Carl723000 one owner-side step to flag: this PR adds the Test workflow so a red ✗ now shows on every PR, but a workflow check on its own doesn't block merging — GitHub will still let a PR merge past a failing check unless it's marked required.

To actually gate merges on it, once this is merged:

Settings → Branches → Branch protection rules for main → enable "Require status checks to pass before merging" and add Test to the required list.

(There's a note to this effect in the workflow file's header comment too, but it's easy to miss there — hence calling it out here.) Happy to do anything on my end if that's useful.

@ildyria

ildyria commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

@nickearnshaw Can you run action-up (https://github.com/azat-io/actions-up) on the PR so that the actions are updated to latest and using pin commits instead of version numbers ? :)

@ildyria

ildyria commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

Also while you are at it, you should add a CODEOWNER file (in .github/CODEOWNERS ). 👍

See for example:

# This is a comment.
# Each line is a file pattern followed by one or more owners.

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.

# Default owner for everything in the repo are members of the reviewers team.

* @Carl723000 @jack21 

# Comments bellow are kept for reference

# Order is important; the last matching pattern takes the most
# precedence. When someone opens a pull request that only
# modifies JS files, only @js-owner and not the global
# owner(s) will be requested for a review.
# *.js    @js-owner #This is an inline comment.

# You can also use email addresses if you prefer. They'll be
# used to look up users just like we do for commit author
# emails.
# *.go docs@example.com

# Teams can be specified as code owners as well. Teams should
# be identified in the format @org/team-name. Teams must have
# explicit write access to the repository. In this example,
# the octocats team in the octo-org organization owns all .txt files.
# *.txt @octo-org/octocats

# In this example, @doctocat owns any files in the build/logs
# directory at the root of the repository and any of its
# subdirectories.
# /build/logs/ @doctocat

# The `docs/*` pattern will match files like
# `docs/getting-started.md` but not further nested files like
# `docs/build-app/troubleshooting.md`.
# docs/* docs@example.com

# In this example, @octocat owns any file in an apps directory
# anywhere in your repository.
# apps/ @octocat

# In this example, @doctocat owns any file in the `/docs`
# directory in the root of your repository and any of its
# subdirectories.
# /docs/ @doctocat

# In this example, any change inside the `/scripts` directory
# will require approval from @doctocat or @octocat.
# /scripts/ @doctocat @octocat

# In this example, @octocat owns any file in a `/logs` directory such as
# `/build/logs`, `/scripts/logs`, and `/deeply/nested/logs`. Any changes
# in a `/logs` directory will require approval from @octocat.
# **/logs @octocat

# In this example, @octocat owns any file in the `/apps`
# directory in the root of your repository except for the `/apps/github`
# subdirectory, as its owners are left empty. Without an owner, changes
# to `apps/github` can be made with the approval of any user who has
# write access to the repository.
# /apps/ @octocat
# /apps/github

# In this example, @octocat owns any file in the `/apps`
# directory in the root of your repository except for the `/apps/github`
# subdirectory, as this subdirectory has its own owner @doctocat
# /apps/ @octocat
# /apps/github @doctocat

@Carl723000

Copy link
Copy Markdown
Collaborator

@ildyria both great calls. I'll add .github/CODEOWNERS and pin the workflow actions to commit SHAs (via action-up) in a CI-hardening pass this week, and I'll credit you on that commit.

@nickearnshaw the framework looks clean and the zero-dependency approach is exactly right. Planning to merge this first as the base, then wire up the required Test check once branch protection is on. Thanks again!

@Carl723000
Carl723000 merged commit 0c98da0 into ClaudeCodeUsage:main Jun 15, 2026
2 checks passed
Carl723000 pushed a commit that referenced this pull request Jun 15, 2026
* docs: document test expectations in CONTRIBUTING

Replace the "no test suite yet" note with how the node:test harness
works: where tests live (src/test/*.test.ts -> out/test/), how to run
(npm test), what belongs here (pure logic) vs what needs
@vscode/test-electron, and a pointer to the worked example.

Depends on the test-framework PR (#32) landing first.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs: update CLAUDE.md test status and note the flat src/test layout

- CLAUDE.md: the node:test suite now exists (was "planned, see #25").
- CONTRIBUTING: spell out that src/test/ must stay flat, since the test
  script globs out/test/*.test.js a single level deep (kept single-level
  for Node-version portability) so nested files would be skipped.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Carl723000 added a commit that referenced this pull request Jun 15, 2026
Supply-chain hardening suggested by @ildyria:
- Pin actions/checkout, actions/setup-node, softprops/action-gh-release and
  release-drafter to full commit SHAs (moving tags like @v4 can be repointed;
  a SHA cannot), each annotated with a trailing "# vX".
- Add .github/CODEOWNERS (* @Carl723000 @jack21) so PRs auto-request review.
- release-drafter: add exclude-labels so attribution-only PRs labelled
  skip-changelog stay out of the release notes.

Co-Authored-By: ildyria <627094+ildyria@users.noreply.github.com>
@Carl723000 Carl723000 added the ci CI / workflow change label Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci CI / workflow change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No testing framework present — blocks adding automated tests

3 participants