Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@
"output": []
},
"test:watch": {
"command": "uvu lib/test \"^watch\\.test\\.js$\"",
"command": "node --test --test-reporter=dot lib/test/watch.test.js",
"env": {
"NODE_OPTIONS": "--enable-source-maps"
},
Expand All @@ -417,7 +417,7 @@
"devDependencies": {
"@eslint/js": "^9.10.0",
"@types/brace-expansion": "^1.1.2",
"@types/node": "^22.5.4",
"@types/node": "^18.19.130",
"@types/node-forge": "^1.3.0",
"@types/proper-lockfile": "^4.1.2",
"@types/selfsigned": "^2.0.1",
Expand Down
20 changes: 17 additions & 3 deletions src/test/util/rig-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,23 @@ export const rigTest = <T extends {rig?: WireitTestRig}>(
};

export function rigTestNode(
fn: (args: {rig: WireitTestRig}) => unknown,
handler: (args: {rig: WireitTestRig}) => unknown,
options?: {flaky?: boolean},
): TestFn {
return async function () {
await fn({rig: await WireitTestRig.setup()});
const runTest = async () => {
await using rig = await WireitTestRig.setup();
await handler({rig});
};
if (options?.flaky) {
return async () => {
try {
return await runTest();
} catch {
console.log('Test failed, retrying...');
}
return await runTest();
};
} else {
return runTest;
}
}
58 changes: 27 additions & 31 deletions src/test/watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,27 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {suite} from 'uvu';
import * as assert from 'uvu/assert';
import {rigTest} from './util/rig-test.js';
import {test, describe} from 'node:test';
import * as assert from 'node:assert';
import {rigTestNode as rigTest} from './util/rig-test.js';
import type {WireitTestRig} from './util/test-rig.js';

tests('WIREIT_WATCH_STRATEGY=<default=event>');
void describe('WIREIT_WATCH_STRATEGY=<default=event>', () => tests());

tests('WIREIT_WATCH_STRATEGY=poll', (rig: WireitTestRig) => {
rig.env.WIREIT_WATCH_STRATEGY = 'poll';
// Default is 500, let's speed up the tests.
rig.env.WIREIT_WATCH_POLL_MS = '50';
});
void describe('WIREIT_WATCH_STRATEGY=poll', () =>
tests((rig: WireitTestRig) => {
rig.env.WIREIT_WATCH_STRATEGY = 'poll';
// Default is 500, let's speed up the tests.
rig.env.WIREIT_WATCH_POLL_MS = '50';
}));

function tests(
suiteName: string,
// TODO(aomarks) There should be a better way to prepare a rig without having
// to remember to call it in every test case. We should refactor to use the
// node test runner, maybe can do this as part of that.
prepareRig: (rig: WireitTestRig) => void | Promise<void> = () => {},
) {
const test = suite<object>(suiteName);

test(
void test(
'runs initially and waits for SIGINT',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -80,7 +78,7 @@ function tests(
),
);

test(
void test(
'runs again when input file changes after execution',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -131,7 +129,7 @@ function tests(
),
);

test(
void test(
'runs again when new input file created',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -182,7 +180,7 @@ function tests(
),
);

test(
void test(
'runs again when input file deleted',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -231,7 +229,7 @@ function tests(
),
);

test(
void test(
'runs again when input file changes in the middle of execution',
rigTest(async ({rig}) => {
await prepareRig(rig);
Expand Down Expand Up @@ -279,7 +277,7 @@ function tests(
}),
);

test(
void test(
'reloads config when package.json changes and runs again',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -340,7 +338,7 @@ function tests(
),
);

test(
void test(
'changes are detected in same-package dependencies',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -424,7 +422,7 @@ function tests(
),
);

test(
void test(
'changes are detected in cross-package dependencies',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -514,7 +512,7 @@ function tests(
),
);

test(
void test(
'error from script is not fatal',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -567,7 +565,7 @@ function tests(
),
);

test(
void test(
'recovers from analysis errors',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -675,7 +673,7 @@ function tests(
),
);

test(
void test(
'watchers understand negations',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -739,7 +737,7 @@ function tests(
),
);

test(
void test(
'.dotfiles are watched',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -787,7 +785,7 @@ function tests(
),
);

test(
void test(
'package-lock.json files are watched',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -833,7 +831,7 @@ function tests(
),
);

test(
void test(
'debounces when two scripts are watching the same file',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -900,7 +898,7 @@ function tests(
),
);

test(
void test(
'strips leading slash from watch paths',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -947,7 +945,7 @@ function tests(
),
);

test(
void test(
'script fails but still emits output consumed by another script',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -1028,7 +1026,7 @@ function tests(
),
);

test(
void test(
'input file changes but the contents are the same',
rigTest(
async ({rig}) => {
Expand Down Expand Up @@ -1068,6 +1066,4 @@ function tests(
{flaky: true},
),
);

test.run();
}
Loading