Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: super basic test suite support #4

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
134 changes: 134 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Checks

on:
push:
branches:
- main
- renovate/**
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'renovate/'))

name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
with:
check-latest: true
node-version: lts/*
- run: corepack enable
- run: yarn install
- run: yarn build --sourcemap
- uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4
with:
name: build-${{ github.sha }}
path: build

check:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'renovate/'))

name: Check
needs:
- build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
with:
check-latest: true
node-version: lts/*
- run: corepack enable
- run: yarn install
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: build-${{ github.sha }}
path: build
- run: yarn check:spelling
- run: yarn check:types

quality:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'renovate/'))

name: Code Quality
needs:
- build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
with:
check-latest: true
node-version: lts/*
- run: corepack enable
- run: yarn install
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: build-${{ github.sha }}
path: build
- run: yarn biome ci --error-on-warnings

test-node:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'renovate/'))

name: Test Build on Node.js v${{ matrix.node-version }}
needs:
- build
strategy:
fail-fast: false
matrix:
node-version: ['18.19', '18.x', '20.x', '22.x', '23.x']
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
with:
check-latest: true
node-version: ${{ matrix.node-version }}
- run: corepack enable
- run: yarn install
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: build-${{ github.sha }}
path: build
- run: "yarn test:mocha"
- run: "yarn test:tstyche"
- run: "yarn test:tstyche-as-mocha"

test-os:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'renovate/'))

name: Test Build on ${{ matrix.os }}
needs:
- build
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
with:
check-latest: true
node-version: lts/*
- run: corepack enable
- run: yarn install
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: build-${{ github.sha }}
path: build
- run: "yarn test:mocha"
- run: "yarn test:tstyche"
- run: "yarn test:tstyche-as-mocha"
46 changes: 46 additions & 0 deletions .mocharc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const console = require("node:console");
const process = require("node:process");

let showSpec = false;
const args = process.argv.slice(2);
/** @type {string[]} */
const positionals = [];
while (args.length > 0) {
const arg = args.shift() ?? "";
if (arg.startsWith("--")) {
if (arg.startsWith("--show-spec")) {
showSpec = true;
}
if (!arg.includes("=")) {
args.shift();
}
} else if (!arg.startsWith("-") && arg !== ".") {
positionals.push(arg);
}
}
let spec = [
// "**/*.test.js",
// "**/*.test.mjs",
// "**/*.test.cjs",
"**/*.test.ts",
];
if (positionals.length > 0) {
spec = positionals;
}

if (showSpec) {
console.log(`spec: ${JSON.stringify(spec)}`);
}

/**
* @type {{checkLeaks:boolean,ignore:string,loader?:string,"node-option"?:string[],recursive:boolean,spec:string[]}}
*/
const config = {
checkLeaks: true,
ignore: "node_modules/**/*",
"node-option": ["import=tsx", "import=source-map-support"],
recursive: true,
spec,
};

module.exports = config;
92 changes: 92 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Development

For the smoothest development experience in this codebase, you'll need:

- [Node.js] — You'll need at least v18, which is the oldest supported version.
rickosborne marked this conversation as resolved.
Show resolved Hide resolved
- [fnm] — Optional, but helpful.
- [yarn] — Not just npm.
- [hyperfine] — Optional for many basic tasks, but required for performance metrics.
rickosborne marked this conversation as resolved.
Show resolved Hide resolved

You'll do a typical setup sequence from there.

Update your local packages:

```shell
yarn install
```

Build the app:

```shell
yarn build
```

Run tests:

```shell
yarn test
```

You can then see everything as a user would, by running TSTyche against some example tests:

```shell
yarn test:tstyche
```

Which is just an alias for:

```shell
tstyche ./type-test
```
Comment on lines +30 to +40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. Not sure this is applicable in this repo. Or?


## Install notes for macos

- You can't just `brew install yarn`.
It will install an ancient version, and won't work.
Instead, see the [yarn setup instructions].

- For `fnm` and `hyperfine`, `brew install` works for both.
rickosborne marked this conversation as resolved.
Show resolved Hide resolved

## Before you commit

Please make sure the CI tests will pass:

```shell
yarn lint
yarn check
yarn clean
yarn build
yarn test
```

If you want to be extra thorough, and have `fnm` installed, you can run those tests on various supported versions of Node.js.
Remember that you'll need to enable corepack (for yarn) for each version of node you install:

```shell
fnm install --corepack-enabled v18
fnm install --corepack-enabled v20
fnm install --corepack-enabled v22
```

Once you have v18, v20, and v22 installed, you can use them to run the tests:

```shell
yarn test:v18
yarn test:v20
yarn test:v22
```

These are just aliases for commands like:

```shell
fnm exec --with v18 yarn test
```

You can also do this with [nvm], though `fnm` makes it a bit easier by working from within a `package.json` script, which `nvm` won't do without lots of extra setup.

[Node.js]: https://nodejs.org
[fnm]: https://github.com/Schniz/fnm
[nvm]: https://github.com/nvm-sh/nvm
[yarn]: https://yarnpkg.com/getting-started/install
[hyperfine]: https://github.com/sharkdp/hyperfine
[yarn setup instructions]: https://yarnpkg.com/getting-started/install
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"files": {
"ignore": [".cache/**", ".idea/**", ".yarn/**", "build/**", "coverage/**", "node_modules/**"]
"ignore": [".cache/**", ".idea/**", ".yarn/**", "build/**", "coverage/**", "node_modules/**", "package.json"],
"ignoreUnknown": true
},
"formatter": {
"enabled": true,
Expand Down
2 changes: 1 addition & 1 deletion cspell.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"files": ["**/*.js", "**/*.json", "**/*.md", "source/**/*", "static/**/*", "tests/**/*"],
"ignorePaths": ["build/**/*"],
"ignoreRegExpList": ["\"tstyche/tstyche\"", "tstyche#\\d+"],
"ignoreRegExpList": ["\"tstyche/tstyche\"", "tstyche#\\d+", "tstyche[.]config[.]json"],
"language": "en-US",
"useGitignore": true,
"words": ["mochajs"]
Expand Down
18 changes: 15 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,33 @@
"check:spelling": "cspell --config cspell.config.json --quiet",
"check:types": "tsc --noEmit --project tsconfig.json",
"clean": "rimraf build --preserve-root",
"format": "biome format --write",
"format": "biome format --write --verbose",
"lint": "biome lint --write",
"prepublish": "yarn clean && yarn build",
"test": "echo '🚧 TODO: tests 🚧'"
"precommit": "yarn lint && yarn format && yarn check && yarn build && yarn test",
"prepublish": "yarn build",
"test": "yarn test:mocha && yarn test:tstyche && yarn test:tstyche-as-mocha",
"test:mocha": "mocha",
"test:tstyche": "tstyche type-test",
"test:tstyche-as-mocha": "tsx ./source/mocha.ts --reporter ../test/test-reporter.mjs",
"test:v18": "fnm exec --using v18 yarn test",
"test:v20": "fnm exec --using v20 yarn test",
"test:v22": "fnm exec --using v22 yarn test"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@types/chai": "5.0.1",
"@types/mocha": "10.0.10",
"@types/node": "22.10.5",
"chai": "5.1.2",
"cpr": "3.0.1",
"cspell": "8.17.1",
"mkdirp": "3.0.1",
"mocha": "11.0.1",
"mocha-reporter-gha": "1.1.1",
"rimraf": "6.0.1",
"source-map-support": "0.5.21",
"tstyche": "3.3.1",
"tsx": "4.19.2",
"typescript": "5.7.2"
},
"packageManager": "[email protected]",
Expand Down
Loading
Loading