Repository navigation
test: add node:test framework with a seed pricing test (#25) - #32
Carl723000 merged 2 commits into
Conversation
…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>
|
@Carl723000 one owner-side step to flag: this PR adds the To actually gate merges on it, once this is merged: Settings → Branches → Branch protection rules for (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. |
|
@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 ? :) |
|
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 |
|
@ildyria both great calls. I'll add @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 |
* 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>
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>
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 freshmain(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— coverspricing.tsbecause it's pure logic with novscodeimport. 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—testscript:npm run compile && node --test "out/test/**/*.test.js". Tests live insrc/test/, sotsc(rootDir: src) emits them toout/test/..vscodeignore— addsout/test/**so the compiled tests never ship in the.vsix(verified withvsce ls)..github/workflows/test.yml— runsnpm teston pushes tomainand on every PR.Notes for review
vscodeAPI would need the heavier@vscode/test-electronsetup — out of scope here.tsconfig.jsonhas noesModuleInterop, so the test uses namespace imports (import { test }/import * as assert) rather than default imports.Testis 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