Generate ESM code and use vitest for tests#172
Conversation
5fe56ab to
be3e371
Compare
tstirrat15
left a comment
There was a problem hiding this comment.
See annotations
| src/authzedapi/authzed/api/v0 | ||
| src/authzedapi/authzed/api/v1alpha1 |
There was a problem hiding this comment.
No longer necessary with the changes to the buf generation file.
| # NOTE: This grabs only the v1 proto and ignores v0 and v1dev. | ||
| - "authzed/api/v1" |
There was a problem hiding this comment.
These being those changes
| "name": "@authzed/authzed-js-node", | ||
| "author": "authzed", | ||
| "version": "0.19.0", | ||
| "type": "module", |
There was a problem hiding this comment.
This will make importing code happy with the ES code found in this module.
| "only-run-tests": "ts-node node_modules/jasmine/bin/jasmine --config=jasmine.json", | ||
| "buf": "./buf.gen.yaml", | ||
| "only-run-tests": "vitest", | ||
| "buf": "buf generate && tsc-esm-fix --src src/authzedapi --ext='.js'", |
There was a problem hiding this comment.
the tsc-esm-fix is needed until timostamm/protobuf-ts#656 is fixed.
| "build": "tsc", | ||
| "prepublish": "yarn build", | ||
| "build-js-client": "tsc --target es2018 --declaration false --outDir js-dist" | ||
| "build-js-client": "tsc --declaration false --outDir js-dist" |
There was a problem hiding this comment.
Don't need to override target here - they can use the same targets.
| import { ClientSecurity } from "./util.js"; | ||
| import * as v1 from "./v1.js"; | ||
| import { Consistency } from "./v1.js"; | ||
| import { generateTestToken } from './__utils__/helpers.js' |
There was a problem hiding this comment.
Typescript is sticky on this point - if you're using node16 as the module target, you need to have a file suffix on your relative imports. Apparently this is a part of the JS spec that TS implements but it mostly annoys people.
I ran tsc-esm-fix to generate these changes.
|
|
||
| describe("a check following a write of schema and relationships", () => { | ||
| it("should succeed", (done) => { | ||
| it("should succeed", () => new Promise<void>((done) => { |
There was a problem hiding this comment.
This was a drive-by TS fix.
| "extends": "@tsconfig/node18/tsconfig.json", | ||
|
|
There was a problem hiding this comment.
This is actually probably the biggest change - this extends a TS config that works with Node 18. When we walk our node support we can change this and get the new configuration easily.
I removed all of the configuration that would re-specify what's already in the extension.
Fixes #171
Description
This started out as a QOL thing. Vitest is the current state-of-the-art and supports typescript out of the box without the need for manual transpilation. It also is quite fast and supports concurrency and parallelization nicely.
However, Vitest doesn't play nicely in non-ESM environments, and we weren't generating ESM with our TS configuration. This updates that, since we don't have a reason not to - Node has supported ESM since version 16.
Changes
Testing
Review. See that things are green.