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 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
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ trim_trailing_whitespace = true

[*.{md,txt}]
trim_trailing_whitespace = false

[*.{js,mjs,cjs}]
ij_javascript_force_semicolon_style = true
ij_javascript_use_semicolon_after_statement = true

[*.{ts,cts,mts,tsx}]
ij_typescript_force_semicolon_style = true
ij_typescript_use_semicolon_after_statement = true
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:ts"

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:ts"
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;
102 changes: 102 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# 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
Other [LTS versions] may be helpful.
- [yarn] — Not just npm.
- [fnm] — Optional, but helpful.

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`, `brew install fnm` works.
See below for additional guidance around multiple versions.

## 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
```

And just to make sure you're up to date:

```shell
fnm install --corepack-enabled --lts
```

This will likely tell you the latest LTS version is already installed, at least until these docs are out of date.

Once you have multiple versions 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
[LTS versions]: https://nodejs.org/en/about/previous-releases
[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
4 changes: 2 additions & 2 deletions cspell.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
},
"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"]
"words": ["mochajs", "subpath"]
}
26 changes: 22 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"bin": "./source/mocha.ts",
"scripts": {
"build": "yarn clean && yarn build:mkdir && yarn build:cjs && yarn build:esm && yarn build:types && yarn build:static && yarn build:readme",
"build:cjs": "echo '🚧 TODO: CJS 🚧'",
"build:cjs": "echo '🚧 TODO: Build CJS 🚧'",
"build:esm": "tsc --project tsconfig.esm.json",
"build:mkdir": "mkdirp build",
"build:readme": "cpr README.md build/README.md",
Expand All @@ -34,21 +34,39 @@
"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 && yarn test:js",
"prepublish": "yarn build",
"test": "yarn test:mocha && yarn test:tstyche && yarn test:tstyche-as-mocha:ts",
"test:js": "yarn test:tstyche-as-mocha:esm && yarn test:tstyche-as-mocha:cjs",
"test:js:v18": "fnm exec --using v18 yarn test:js",
"test:js:v20": "fnm exec --using v20 yarn test:js",
"test:js:v22": "fnm exec --using v22 yarn test:js",
"test:mocha": "mocha",
"test:tstyche": "tstyche type-test",
"test:tstyche-as-mocha:cjs": "echo '🚧 TODO: Test CJS 🚧'",
"test:tstyche-as-mocha:esm": "node ./build/esm/mocha.js --reporter ../../test/test-reporter.mjs",
"test:tstyche-as-mocha:ts": "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