Skip to content

Commit 436a473

Browse files
committedOct 8, 2023
Add .ts extension to ava plugin entry file patterns, config can be a function
1 parent 28b723d commit 436a473

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed
 

‎src/plugins/ava/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ or `devDependencies`:
1414
"ava": {
1515
"config": ["ava.config.{js,cjs,mjs}", "package.json"],
1616
"entry": [
17-
"test.{js,cjs,mjs}",
18-
"{src,source}/test.{js,cjs,mjs}",
19-
"**/__tests__/**/*.{js,cjs,mjs}",
20-
"**/*.spec.{js,cjs,mjs}",
21-
"**/*.test.{js,cjs,mjs}",
22-
"**/test-*.{js,cjs,mjs}",
23-
"**/test/**/*.{js,cjs,mjs}",
24-
"**/tests/**/*.{js,cjs,mjs}",
17+
"test.{js,cjs,mjs,ts}",
18+
"{src,source}/test.{js,cjs,mjs,ts}",
19+
"**/__tests__/**/*.{js,cjs,mjs,ts}",
20+
"**/*.spec.{js,cjs,mjs,ts}",
21+
"**/*.test.{js,cjs,mjs,ts}",
22+
"**/test-*.{js,cjs,mjs,ts}",
23+
"**/test/**/*.{js,cjs,mjs,ts}",
24+
"**/tests/**/*.{js,cjs,mjs,ts}",
2525
"!**/__tests__/**/__{helper,fixture}?(s)__/**/*",
2626
"!**/test?(s)/**/{helper,fixture}?(s)/**/*"
2727
]

‎src/plugins/ava/index.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { _getDependenciesFromScripts } from '../../binaries/index.js';
22
import { timerify } from '../../util/Performance.js';
33
import { hasDependency, load } from '../../util/plugin.js';
44
import { toEntryPattern } from '../../util/protocols.js';
5-
import type { PluginConfig } from './types.js';
5+
import type { AvaConfig } from './types.js';
66
import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
77

88
// https://github.com/avajs/ava/blob/main/docs/06-configuration.md
@@ -18,20 +18,22 @@ export const CONFIG_FILE_PATTERNS = ['ava.config.{js,cjs,mjs}', 'package.json'];
1818

1919
/** @public */
2020
export const ENTRY_FILE_PATTERNS = [
21-
`test.{js,cjs,mjs}`,
22-
`{src,source}/test.{js,cjs,mjs}`,
23-
`**/__tests__/**/*.{js,cjs,mjs}`,
24-
`**/*.spec.{js,cjs,mjs}`,
25-
`**/*.test.{js,cjs,mjs}`,
26-
`**/test-*.{js,cjs,mjs}`,
27-
`**/test/**/*.{js,cjs,mjs}`,
28-
`**/tests/**/*.{js,cjs,mjs}`,
21+
`test.{js,cjs,mjs,ts}`,
22+
`{src,source}/test.{js,cjs,mjs,ts}`,
23+
`**/__tests__/**/*.{js,cjs,mjs,ts}`,
24+
`**/*.spec.{js,cjs,mjs,ts}`,
25+
`**/*.test.{js,cjs,mjs,ts}`,
26+
`**/test-*.{js,cjs,mjs,ts}`,
27+
`**/test/**/*.{js,cjs,mjs,ts}`,
28+
`**/tests/**/*.{js,cjs,mjs,ts}`,
2929
'!**/__tests__/**/__{helper,fixture}?(s)__/**/*',
3030
'!**/test?(s)/**/{helper,fixture}?(s)/**/*',
3131
];
3232

3333
const findAvaDependencies: GenericPluginCallback = async (configFilePath, { cwd, manifest, isProduction }) => {
34-
const config: PluginConfig = configFilePath.endsWith('package.json') ? manifest.ava : await load(configFilePath);
34+
let config: AvaConfig = configFilePath.endsWith('package.json') ? manifest.ava : await load(configFilePath);
35+
36+
if (typeof config === 'function') config = config();
3537

3638
const entryPatterns = (config?.files ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
3739
if (isProduction) return entryPatterns;

‎src/plugins/ava/types.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
export type PluginConfig = {
1+
type Config = {
22
files?: string[];
33
require?: string[];
44
nodeArguments?: string[];
5+
extensions?: string[];
56
};
7+
8+
export type AvaConfig = Config | (() => Config);

0 commit comments

Comments
 (0)
Please sign in to comment.