Skip to content

Commit 7eb4ab3

Browse files
committed
Test test test
1 parent 28c56cb commit 7eb4ab3

11 files changed

Lines changed: 47 additions & 109 deletions

File tree

.github/DEVELOPMENT.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ To skip slower tests related to CLI and `--fix`, while still covering all the
5050
essentials and plugins:
5151

5252
```shell
53-
pnpm test:smoke
54-
bun test:bun:smoke
53+
pnpm test --smoke
5554
```
5655

5756
Note that Git `core.symlinks=true` is required for some tests.
@@ -167,7 +166,7 @@ test file to run and debug.
167166
In case you're wondering if or why some code is ever hit, attach the debugger to
168167
each test. Set a breakpoint and run all tests in one of the following ways:
169168

170-
- From built-in terminal: `tsx --inspect --test test/**/*.test.ts`
169+
- From built-in terminal: `node --inspect --test test/**/*.test.ts`
171170
- Use the "Debug all tests with Bun" launch config.
172171

173172
## QA

.github/workflows/ci-bun.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ jobs:
3636
- name: Run knip (production/strict)
3737
run: ./packages/knip/bin/knip-bun.js --production --strict
3838
- name: Test knip
39-
run: bun run test:bun
39+
run: bun run test
4040
working-directory: packages/knip

.github/workflows/ci-legacy-5.0.4.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
pnpm tsc --noEmit
4747
working-directory: packages/knip
4848
- name: Test knip
49-
run: pnpm run test:smoke
49+
run: pnpm test --runtime node --smoke
5050
working-directory: packages/knip
5151
- name: Run knip
5252
run: ./packages/knip/bin/knip.js --reporter github-actions

.github/workflows/ci-legacy-latest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
run: pnpm run build
3131
working-directory: packages/knip
3232
- name: Test knip
33-
run: pnpm run test:node
33+
run: pnpm test --runtime node
3434
working-directory: packages/knip
3535
- name: Run knip
3636
run: ./packages/knip/bin/knip.js

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
run: pnpm run build
2929
working-directory: packages/knip
3030
- name: Test knip
31-
run: pnpm run test:node
31+
run: pnpm test --runtime node
3232
working-directory: packages/knip
3333
- name: Run knip
3434
run: ./packages/knip/bin/knip.js

AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ To run all relevant tests without having to build `knip`:
123123

124124
```sh
125125
cd packages/knip
126-
pnpm run test:bun:smoke
126+
pnpm test --runtime bun --smoke
127127
```
128128

129129
Use `node` if Bun is not available:
130130

131131
```sh
132132
cd packages/knip
133133
node --test test/commonjs.test.ts
134-
pnpm test:smoke
134+
pnpm test --smoke
135135
```
136136

137137
Build core package and run all tests only if there are changes in auto-fix,

knip.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
"ignoreBinaries": ["tsc"]
77
},
88
"packages/knip": {
9-
"project": [
10-
"src/**/*.ts!",
11-
"test/**/*.ts",
12-
"!src/util/empty.ts",
13-
"!**/_template"
14-
],
9+
"entry": ["test/**/*.ts"],
10+
"project": ["src/**/*.ts!", "!src/util/empty.ts", "!**/_template"],
1511
"ignoreDependencies": ["prettier"]
1612
},
1713
"packages/docs": {

packages/knip/package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,10 @@
8181
"knip:production": "node ./src/cli.ts --directory ../.. --production --strict",
8282
"lint": "oxlint",
8383
"fmt": "oxfmt -c ../../.oxfmtrc.json --ignore-path ../../.prettierignore",
84-
"test": "node scripts/run-test.ts",
85-
"test:node": "tsx --test test/*.test.ts test/**/*.test.ts",
86-
"test:bun": "bun test test/*.test.ts test/**/*.test.ts",
87-
"test:smoke": "glob -c \"tsx --test\" \"test/*.test.ts\" && glob -c \"tsx --test\" \"test/plugins/*.test.ts\" && glob -c \"tsx --test\" \"test/util/*.test.ts\"",
88-
"test:bun:smoke": "bun test test/*.test.ts test/{plugins,util}/*.test.ts",
84+
"test": "node scripts/run-test.js",
8985
"prebuild": "pnpm run generate-plugin-defs && node rmdir.js dist",
9086
"build": "tsgo",
91-
"qa": "pnpm lint && pnpm build && pnpm knip && pnpm knip:production && pnpm run test",
87+
"qa": "pnpm lint && pnpm build && pnpm knip && pnpm knip:production && pnpm test",
9288
"release": "NODE_OPTIONS=--no-deprecation release-it",
9389
"create-plugin": "node ./scripts/create-new-plugin.ts",
9490
"postcreate-plugin": "pnpm run build && (oxfmt schema.json schema-jsonc.json src/schema/plugins.ts || true)",
@@ -120,7 +116,6 @@
120116
"@typescript/native-preview": "7.0.0-dev.20260415.1",
121117
"@wdio/types": "^9.20.0",
122118
"codeclimate-types": "^0.3.1",
123-
"glob-bin": "^1.1.0",
124119
"prettier": "^3.8.1",
125120
"tsx": "^4.21.0"
126121
},

packages/knip/scripts/run-test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env node
2+
import { spawnSync } from 'node:child_process';
3+
import { createRequire } from 'node:module';
4+
// oxlint-disable-next-line no-restricted-imports
5+
import { dirname, resolve } from 'node:path';
6+
import { parseArgs } from 'node:util';
7+
import { globSync } from 'tinyglobby';
8+
9+
const { values } = parseArgs({
10+
options: {
11+
runtime: { type: 'string', default: 'bun' },
12+
smoke: { type: 'boolean', default: false },
13+
},
14+
});
15+
16+
const useBun =
17+
values.runtime === 'bun' && spawnSync('bun', ['--version'], { stdio: 'ignore', shell: true }).status === 0;
18+
19+
const patterns = values.smoke
20+
? ['test/*.test.ts', 'test/{plugins,util}/*.test.ts']
21+
: ['test/*.test.ts', 'test/**/*.test.ts'];
22+
23+
const files = globSync(patterns);
24+
25+
const [major, minor] = process.versions.node.split('.').map(Number);
26+
const nativeTS = major >= 24 || (major === 22 && minor >= 18);
27+
28+
const require = createRequire(import.meta.url);
29+
const tsxBin = nativeTS ? null : resolve(dirname(require.resolve('tsx/package.json')), require('tsx/package.json').bin);
30+
31+
const result = useBun
32+
? spawnSync('bun', ['test', ...files], { stdio: 'inherit' })
33+
: spawnSync(process.execPath, [...(tsxBin ? [tsxBin] : []), '--test', ...files], { stdio: 'inherit' });
34+
35+
process.exit(result.status ?? 1);

packages/knip/scripts/run-test.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)