Skip to content

Commit 311404d

Browse files
committed
fix test filtering
1 parent 2c91f54 commit 311404d

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

packages/core/src/entry/testing/cli/index.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { initializePardon } from "../../../runtime/runtime.js";
1919
import {
2020
chooseReportOutput,
2121
executeSelectedTests,
22+
filterTestPlanning,
2223
loadTests,
2324
PardonTestConfiguration,
2425
writeResultSummary,
@@ -111,18 +112,13 @@ async function main() {
111112
environment = updates;
112113
}
113114

114-
const { cases, patterns, antipatterns } = await testplanner(
115+
const planning = await testplanner(
115116
environment,
116117
parseSmokeConfig(smoke),
117118
...positionals,
118119
);
119120

120-
const testplan = cases.filter(
121-
({ testcase }) =>
122-
!patterns ||
123-
(patterns.some((p) => p.test(testcase)) &&
124-
!antipatterns.some((p) => p.test(testcase))),
125-
);
121+
const testplan = filterTestPlanning(planning);
126122

127123
if (testplan.length === 0) {
128124
console.warn(`
@@ -131,7 +127,7 @@ FAIL
131127
132128
no testcases configured and/or
133129
all testcases filtered out.${
134-
patterns?.some((p) => p.source.includes("package\\.json"))
130+
planning.patterns?.some((p) => p.source.includes("package\\.json"))
135131
? `
136132
137133
(Hint: You may need to put your ** filter in quotes.)
@@ -142,7 +138,7 @@ all testcases filtered out.${
142138
return 1;
143139
}
144140

145-
if (plan || !patterns) {
141+
if (plan || !planning.patterns) {
146142
if (plan) {
147143
console.info(`--- TEST PLAN ---`);
148144
} else {

packages/core/src/entry/testing/cli/runner.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ export type TestSetup = {
5757
testenv: Record<string, unknown>;
5858
};
5959

60+
export type TestPlanning = {
61+
cases: TestSetup[];
62+
patterns?: RegExp[];
63+
antipatterns?: RegExp[];
64+
}
65+
6066
const inflight = new AsyncLocalStorage<{
6167
scheduled: Promise<unknown>[];
6268
awaited: ReturnType<typeof tracking>;
@@ -720,12 +726,21 @@ export async function loadTests(
720726
cases,
721727
patterns,
722728
antipatterns,
723-
};
729+
} satisfies TestPlanning;
724730
},
725731
configuration,
726732
};
727733
}
728734

735+
export function filterTestPlanning({ cases, patterns, antipatterns }: TestPlanning): TestSetup[] {
736+
return cases.filter(
737+
({ testcase }) =>
738+
!patterns?.length ||
739+
(patterns.some((p) => p.test(testcase)) &&
740+
!antipatterns?.some((p) => p.test(testcase))),
741+
);
742+
}
743+
729744
async function configureTrials(
730745
{ trials }: PardonTestConfiguration,
731746
testenv: Record<string, unknown>,

packages/core/src/modules/running.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
99
OF ANY KIND, either express or implied. See the License for the specific language
1010
governing permissions and limitations under the License.
1111
*/
12-
export { loadTests, executeTest } from "../entry/testing/cli/runner.js";
12+
export { loadTests, executeTest, filterTestPlanning } from "../entry/testing/cli/runner.js";
1313
export { initTrackingEnvironment } from "../runtime/environment.js";
1414
export { sequenceRegistry } from "../entry/testing/sequence.js";
1515

packages/favor/electron/pardon-worker.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
type SmokeConfig,
4343
awaitedSequences,
4444
semaphore,
45+
filterTestPlanning,
4546
} from "pardon/running";
4647

4748
let nextTestRunId = Date.now();
@@ -323,7 +324,7 @@ async function initializePardonAndLoadSamples(
323324

324325
const testing = loadTestEngine(app);
325326

326-
await initTrackingEnvironment({});
327+
await initTrackingEnvironment();
327328

328329
return { app, samples, testing };
329330
}
@@ -593,8 +594,9 @@ const handlers = {
593594
{ smoke, filter }: { smoke?: SmokeConfig; filter?: string[] },
594595
) {
595596
const { testing } = await ready;
596-
const testplan = await (await testing)?.testplanner(environment, smoke, ...(filter || []));
597-
return testplan.cases.map(({ testenv, testcase }) => ({ testenv, testcase }));
597+
const planning = await (await testing)!.testplanner(environment, smoke, ...(filter || []));
598+
599+
return filterTestPlanning(planning);
598600
},
599601
async executeTestcases(
600602
testenv: Record<string, unknown>,
@@ -612,7 +614,7 @@ const handlers = {
612614
...testcases,
613615
);
614616

615-
const tests = (await testplan)?.cases;
617+
const tests = filterTestPlanning(testplan);
616618

617619
parentPort!.postMessage(
618620
ship({
@@ -633,7 +635,7 @@ const handlers = {
633635
return currentTestRun.run(testRun, () =>
634636
all_disconnected(
635637
tests.map(
636-
async ({ environment: initEnv, test, testcase }) =>
638+
async ({ testenv: initEnv, test, testcase }) =>
637639
await concurrently(() =>
638640
disconnected(async () => {
639641
let errors: unknown[] = [];
@@ -662,7 +664,7 @@ const handlers = {
662664
} catch (error) {
663665
notifyFastFailed(error);
664666
errors.push(error);
665-
emitEnv = { ...environment };
667+
emitEnv = { ...testenv };
666668

667669
return { testcase, errors, environment: emitEnv };
668670
} finally {

packages/favor/vite.main.config.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ export default extendMainConfig({
3838
exports: "named",
3939
sourcemap: true,
4040
},
41-
},
42-
commonjsOptions: {
43-
transformMixedEsModules: true,
44-
ignoreDynamicRequires: true,
45-
},
41+
}
4642
},
4743
});

0 commit comments

Comments
 (0)