-
-
Notifications
You must be signed in to change notification settings - Fork 323
detect test files if tsx --test script is present
#1090
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
Changes from 2 commits
8e70452
05ab171
aae489a
f6a2816
e4ba4d7
63d384d
3e65590
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "name": "@fixtures/tsx", | ||
| "devDependencies": { | ||
| "tsx": "*" | ||
| }, | ||
| "scripts": { | ||
| "test": "tsx --test" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,38 @@ | ||
| import type { Plugin } from '../../types/config.js'; | ||
| import type { PackageJson } from 'src/types/package-json.js'; | ||
| import { toDependency, toEntry } from 'src/util/input.js'; | ||
| import { hasDependency } from 'src/util/plugin.js'; | ||
| import type { IsPluginEnabled, Plugin, ResolveConfig } from '../../types/config.js'; | ||
|
|
||
| // https://tsx.is | ||
|
|
||
| const title = 'tsx'; | ||
|
|
||
| const enablers = ['tsx']; | ||
|
|
||
| const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers); | ||
|
|
||
| const config = ['package.json']; | ||
|
|
||
| const packageJsonPath = (id: PackageJson) => id; | ||
|
|
||
| const resolveConfig: ResolveConfig<PackageJson> = localConfig => { | ||
| const scripts = localConfig.scripts; | ||
|
|
||
| const entries = [toDependency('tsx')]; | ||
|
||
|
|
||
| if (scripts && Object.keys(scripts).some(script => /(?<=^|\s)tsx\s(.*)--test/.test(scripts[script]))) { | ||
| const patterns = [ | ||
| '**/*{.,-,_}test.?(c|m)(j|t)s', | ||
| '**/test-*.?(c|m)(j|t)s', | ||
| '**/test.?(c|m)(j|t)s', | ||
| '**/test/**/*.?(c|m)(j|t)s', | ||
| ]; | ||
| entries.push(...patterns.map(id => toEntry(id))); | ||
| } | ||
|
|
||
| return entries; | ||
| }; | ||
|
|
||
| const args = { | ||
| positional: true, | ||
| nodeImportArgs: true, | ||
|
|
@@ -12,5 +41,9 @@ const args = { | |
|
|
||
| export default { | ||
| title, | ||
| isEnabled, | ||
| packageJsonPath, | ||
| config, | ||
| resolveConfig, | ||
| args, | ||
| } satisfies Plugin; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { test } from 'bun:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { main } from '../../src/index.js'; | ||
| import { resolve } from '../../src/util/path.js'; | ||
| import baseArguments from '../helpers/baseArguments.js'; | ||
| import baseCounters from '../helpers/baseCounters.js'; | ||
|
|
||
| const cwd = resolve('fixtures/plugins/tsx'); | ||
|
|
||
| test('Find dependencies with the tsx plugin', async () => { | ||
| const { counters } = await main({ | ||
| ...baseArguments, | ||
| cwd, | ||
| }); | ||
|
|
||
| assert.deepEqual(counters, { | ||
| ...baseCounters, | ||
| processed: 2, | ||
| total: 2, | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use relative imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed