Skip to content

Commit

Permalink
Make option name more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
bojavou committed Aug 2, 2024
1 parent 3cc44eb commit e40eed7
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 16 deletions.
6 changes: 3 additions & 3 deletions docs/06-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ The `nodeArguments` configuration may be used to specify additional arguments fo

[CLI]: ./05-command-line.md

## Thread arguments filter
## Node arguments filter for worker threads

In a config file only, `threadArgumentsFilter` may provide a function used for filtering `nodeArguments` sent to worker threads. This enables excluding arguments that throw if sent to a thread. The filter is ignored by worker processes.
In a config file only, `filterNodeArgumentsForWorkerThreads` may provide a function used for filtering `nodeArguments` sent to worker threads. This enables excluding arguments that throw if sent to a thread. The filter is ignored by worker processes.

`ava.config.js`:
```js
Expand All @@ -350,6 +350,6 @@ const processOnly = new Set([
]);

export default {
threadArgumentsFilter: argument => !processOnly.has(argument)
filterNodeArgumentsForWorkerThreads: argument => !processOnly.has(argument)
}
```
4 changes: 2 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ export default async function loadCli() { // eslint-disable-line complexity
let nodeArguments;
try {
nodeArguments = normalizeNodeArguments(conf.nodeArguments, argv['node-arguments']);
if (workerThreads && 'threadArgumentsFilter' in conf) {
const {threadArgumentsFilter: filter} = conf;
if (workerThreads && 'filterNodeArgumentsForWorkerThreads' in conf) {
const {filterNodeArgumentsForWorkerThreads: filter} = conf;
nodeArguments = nodeArguments.filter(argument => filter(argument));
}
} catch (error) {
Expand Down
7 changes: 5 additions & 2 deletions lib/load-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,11 @@ export async function loadConfig({configFile, resolveFrom = process.cwd(), defau
...defaults, nonSemVerExperiments: {}, ...fileConf, ...packageConf, projectDir, configFile,
};

if ('threadArgumentsFilter' in config && typeof config.threadArgumentsFilter !== 'function') {
throw new Error(`threadArgumentsFilter from ${fileForErrorMessage} must be a function`);
if (
'filterNodeArgumentsForWorkerThreads' in config
&& typeof config.filterNodeArgumentsForWorkerThreads !== 'function'
) {
throw new Error(`filterNodeArgumentsForWorkerThreads from ${fileForErrorMessage} must be a function`);
}

const {nonSemVerExperiments: experiments} = config;
Expand Down
2 changes: 1 addition & 1 deletion test-tap/fixture/load-config/non-function/ava.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default {
threadArgumentsFilter: [],
filterNodeArgumentsForWorkerThreads: [],
};
2 changes: 1 addition & 1 deletion test/config/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ test.serial('throws an error if a .js config file has no default export', notOk(

test.serial('throws an error if a config file contains `ava` property', notOk('contains-ava-property'));

test.serial('throws an error if a config file contains a non-function `threadArgumentsFilter` property', notOk('non-function'));
test.serial('throws an error if a config file contains a non-function `filterNodeArgumentsForWorkerThreads` property', notOk('non-function'));

test.serial('throws an error if a config file contains a non-object `nonSemVerExperiments` property', notOk('non-object-experiments'));

Expand Down
10 changes: 8 additions & 2 deletions test/config/snapshots/loader.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ Generated by [AVA](https://avajs.dev).
'Encountered ’ava’ property in ava.config.js; avoid wrapping the configuration'

## throws an error if a config file contains a non-function `threadArgumentsFilter` property
## throws an error if a config file contains a non-function `filterNodeArgumentsForWorkerThreads` property

> error message
'threadArgumentsFilter from ava.config.js must be a function'
'filterNodeArgumentsForWorkerThreads from ava.config.js must be a function'

## throws an error if a config file contains a non-object `nonSemVerExperiments` property

Expand All @@ -63,3 +63,9 @@ Generated by [AVA](https://avajs.dev).
> error message
'Conflicting configuration in ava.config.js and ava.config.cjs'

## throws an error if a config file contains a non-function `threadArgumentsFilter` property

> error message
'threadArgumentsFilter from ava.config.js must be a function'
Binary file modified test/config/snapshots/loader.js.snap
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export default {
'--throw-deprecation',
'--allow-natives-syntax',
],
threadArgumentsFilter: argument => !processOnly.has(argument),
filterNodeArgumentsForWorkerThreads: argument => !processOnly.has(argument),
};
26 changes: 24 additions & 2 deletions test/node-arguments/snapshots/test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Generated by [AVA](https://avajs.dev).
},
]

## `threadArgumentsFilter` configuration filters arguments for worker thread
## `filterNodeArgumentsForWorkerThreads` configuration filters arguments for worker thread

> tests pass
Expand All @@ -26,7 +26,7 @@ Generated by [AVA](https://avajs.dev).
},
]

## `threadArgumentsFilter` configuration ignored for worker process
## `filterNodeArgumentsForWorkerThreads` configuration ignored for worker process

> tests pass
Expand All @@ -53,3 +53,25 @@ Generated by [AVA](https://avajs.dev).
title: 'works',
},
]

## `threadArgumentsFilter` configuration filters arguments for worker thread

> tests pass
[
{
file: 'thread.js',
title: 'exec arguments filtered',
},
]

## `threadArgumentsFilter` configuration ignored for worker process

> tests pass
[
{
file: 'process.js',
title: 'exec arguments unfiltered',
},
]
Binary file modified test/node-arguments/snapshots/test.js.snap
Binary file not shown.
4 changes: 2 additions & 2 deletions test/node-arguments/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('passed node arguments to workers', async t => {
t.snapshot(result.stats.passed, 'tests pass');
});

test('`threadArgumentsFilter` configuration filters arguments for worker thread', async t => {
test('`filterNodeArgumentsForWorkerThreads` configuration filters arguments for worker thread', async t => {
const options = {
cwd: cwd('thread-arguments-filter'),
};
Expand All @@ -23,7 +23,7 @@ test('`threadArgumentsFilter` configuration filters arguments for worker thread'
t.snapshot(result.stats.passed, 'tests pass');
});

test('`threadArgumentsFilter` configuration ignored for worker process', async t => {
test('`filterNodeArgumentsForWorkerThreads` configuration ignored for worker process', async t => {
const options = {
cwd: cwd('thread-arguments-filter'),
};
Expand Down

0 comments on commit e40eed7

Please sign in to comment.