Skip to content

Commit

Permalink
Support, organize & pick tests to run tests in Bun + Node
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Apr 7, 2024
1 parent f877e85 commit 62ccde8
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci-bun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
# With the lockfile, Bun collapses over the `sharp` dependency in docs
- run: rm bun.lockb
- name: Install dependencies
run: bun install --frozen-lockfile
run: bun install
- name: Build knip
run: bun run build
working-directory: packages/knip
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/ci-ts-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ jobs:
- name: Build knip
run: npm run build
working-directory: packages/knip
- name: QA (format, lint, organize imports)
run: npm run ci
- name: Test knip
run: npm run test
run: npm run test:node
working-directory: packages/knip
- name: Run knip
run: npx knip
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,5 @@ jobs:
- name: Run knip (production/strict)
run: npx knip --production --strict
- name: Test knip
run: npm run test
run: npm run test:node
working-directory: packages/knip
- name: Build docs
run: npm run build
working-directory: packages/docs
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const config: KnipConfig = {
entry: ['src/{index,cli}.ts!', 'src/plugins/*/index.ts!'],
project: ['src/**/*.ts!'],
ignore: ['**/fixtures/**', '**/_template/**', '**/dist/**'],
ignoreBinaries: ['tsx'],
ignoreDependencies: ['@pnpm/logger'],
'node-test-runner': {
entry: ['test/**/*.test.ts'],
Expand Down
2 changes: 2 additions & 0 deletions packages/knip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"lint": "biome lint .",
"format": "biome format --write .",
"test": "bun test test/**/*.test.ts",
"test:node": "glob -c \"tsx --test --import ./transform-test.js\" \"test/**/*.test.ts\"",
"watch": "npm link && tsc --watch",
"prebuild": "node rmdir.js dist",
"build": "tsc",
Expand Down Expand Up @@ -89,6 +90,7 @@
"@types/npmcli__package-json": "^4.0.4",
"@types/resolve": "^1.20.6",
"@types/webpack": "^5.28.5",
"glob": "^10.3.12",
"playwright": "^1.43.0",
"release-it": "^17.1.1",
"tsx": "^4.7.2",
Expand Down
5 changes: 4 additions & 1 deletion packages/knip/test/plugins/lefthook-v1.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os from 'node:os';
import { test } from 'bun:test';
import assert from 'node:assert/strict';
import fs from 'node:fs/promises';
Expand All @@ -6,9 +7,11 @@ import { join, resolve } from '../../src/util/path.js';
import baseArguments from '../helpers/baseArguments.js';
import baseCounters from '../helpers/baseCounters.js';

const skipIf = typeof Bun !== 'undefined' && os.platform() === 'win32' ? test.skip : test;

const cwd = resolve('fixtures/plugins/lefthook-v1');

test('Find dependencies with the lefthook v1 plugin', async () => {
skipIf('Find dependencies with the lefthook v1 plugin', async () => {
const CI = process.env.CI;
process.env.CI = '';
await fs.rename(join(cwd, '_git'), join(cwd, '.git')); // Can't add .git folder to repo
Expand Down
4 changes: 3 additions & 1 deletion packages/knip/test/self-reference-from-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { resolve } from '../src/util/path.js';
import baseArguments from './helpers/baseArguments.js';
import baseCounters from './helpers/baseCounters.js';

const skipIf = typeof Bun !== 'undefined' ? test.skip : test;

const cwd = resolve('fixtures/self-reference-from-plugin');

test.skip('Allows self-references from plugin', async () => {
skipIf('Allows self-references from plugin', async () => {
const { counters } = await main({
...baseArguments,
cwd,
Expand Down
4 changes: 3 additions & 1 deletion packages/knip/test/workspaces-self-reference.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { resolve } from '../src/util/path.js';
import baseArguments from './helpers/baseArguments.js';
import baseCounters from './helpers/baseCounters.js';

test.skip('Find unused files, dependencies and exports in workspaces with cross self-references', async () => {
const skipIf = typeof Bun !== 'undefined' ? test.skip : test;

skipIf('Find unused files, dependencies and exports in workspaces with cross self-references', async () => {
const cwd = resolve('fixtures/workspaces-self-reference');

const { counters } = await main({
Expand Down
13 changes: 13 additions & 0 deletions packages/knip/transform-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { readFile } from 'node:fs/promises';
import module from 'node:module';

module.register('./transform-test.js', { parentURL: import.meta.url });

export async function load(url, context, next) {
if (url.endsWith('.test.ts')) {
const content = await readFile(new URL(url), 'utf8');
const source = content.replace(/import { test } from 'bun:test';/, `import test from 'node:test';`);
return next(url, { ...context, source });
}
return next(url, context);
}

0 comments on commit 62ccde8

Please sign in to comment.