-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import test from 'node:test'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@fixtures/node-test-runner", | ||
"scripts": { | ||
"test": "node --test" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Node.js Test Runner | ||
|
||
## Enabled | ||
|
||
This plugin is enabled when any of the following package names and/or regular expressions has a match in `dependencies` | ||
or `devDependencies`: | ||
|
||
- \`\` | ||
|
||
## Default configuration | ||
|
||
```json | ||
{ | ||
"node-test-runner": { | ||
"entry": [ | ||
"**/test.{js,cjs,mjs}", | ||
"**/test-*.{js,cjs,mjs}", | ||
"**/*{.,-,_}test.{js,cjs,mjs}", | ||
"**/test/**/*.{js,cjs,mjs}" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
Also see [Knip plugins][1] for more information about plugins. | ||
|
||
[1]: https://github.com/webpro/knip/blob/main/README.md#plugins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { timerify } from '../../util/Performance.js'; | ||
import { toEntryPattern } from '../../util/protocols.js'; | ||
import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js'; | ||
|
||
// https://nodejs.dev/en/api/test/ | ||
|
||
export const NAME = 'Node.js Test Runner'; | ||
|
||
/** @public */ | ||
export const ENABLERS = ['']; | ||
|
||
export const isEnabled: IsPluginEnabledCallback = ({ manifest }) => { | ||
// TODO Better to scan the entry files until the first `node:test` import, but that's expensive | ||
return Boolean(manifest.scripts?.test && /node.+--test/.test(manifest.scripts?.test)); | ||
}; | ||
|
||
export const ENTRY_FILE_PATTERNS = [ | ||
'**/test.{js,cjs,mjs}', | ||
'**/test-*.{js,cjs,mjs}', | ||
'**/*{.,-,_}test.{js,cjs,mjs}', | ||
'**/test/**/*.{js,cjs,mjs}', | ||
]; | ||
|
||
const findNodeTestRunnerDependencies: GenericPluginCallback = async () => { | ||
return ENTRY_FILE_PATTERNS.map(toEntryPattern); | ||
}; | ||
|
||
export const findDependencies = timerify(findNodeTestRunnerDependencies); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import assert from 'node:assert/strict'; | ||
import test from 'node:test'; | ||
import * as nodeTestRunner from '../../src/plugins/node-test-runner/index.js'; | ||
import { resolve, join } from '../../src/util/path.js'; | ||
import { getManifest } from '../helpers/index.js'; | ||
|
||
const cwd = resolve('fixtures/plugins/node-test-runner'); | ||
const manifest = getManifest(cwd); | ||
|
||
test('Find dependencies in node-test-runner configuration (json)', async () => { | ||
const configFilePath = join(cwd, 'package.json'); | ||
const dependencies = await nodeTestRunner.findDependencies(configFilePath, { manifest }); | ||
assert.deepEqual(dependencies, [ | ||
'e:**/test.{js,cjs,mjs}', | ||
'e:**/test-*.{js,cjs,mjs}', | ||
'e:**/*{.,-,_}test.{js,cjs,mjs}', | ||
'e:**/test/**/*.{js,cjs,mjs}', | ||
]); | ||
}); |