Skip to content

Commit

Permalink
Update biome snapshots and clean up manual replacer (#695)
Browse files Browse the repository at this point in the history
2 cleanups, motivated by nightly:
- Generate new release-able snapshot for biome, and update the script to
autogen snapshots even if not all the tests are failing (e.g. 1 failure,
2 passes, identical on platforms)
- Add some more args for manual version replacer (~for psscriptanalyzer
so things can land until their `v1.22.0` asset gets released~)
  • Loading branch information
TylerJang27 authored Mar 11, 2024
1 parent ba5ae6c commit df1b0fa
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 10 deletions.
73 changes: 73 additions & 0 deletions linters/biome/test_data/biome_v1.6.0_basic_check.check.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// trunk-upgrade-validation:RELEASE

exports[`Testing linter biome test basic_check 1`] = `
{
"issues": [
{
"code": "lint/complexity/noUselessLoneBlockStatements",
"column": "3",
"file": "test_data/basic_check.in.ts",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"line": "13",
"linter": "biome",
"message": "This block statement doesn't serve any purpose and can be safely removed.",
"targetType": "typescript",
},
{
"code": "lint/style/useEnumInitializers",
"column": "6",
"file": "test_data/basic_check.in.ts",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"line": "4",
"linter": "biome",
"message": "This enum declaration contains members that are implicitly initialized.",
"targetType": "typescript",
},
],
"lintActions": [
{
"command": "fmt",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/basic_check.in.ts",
],
"verb": "TRUNK_VERB_FMT",
},
{
"command": "lint",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/basic_check.in.ts",
],
"verb": "TRUNK_VERB_CHECK",
},
{
"command": "lint",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/basic_check.in.ts",
],
"upstream": true,
"verb": "TRUNK_VERB_CHECK",
},
],
"taskFailures": [],
"unformattedFiles": [
{
"column": "1",
"file": "test_data/basic_check.in.ts",
"issueClass": "ISSUE_CLASS_UNFORMATTED",
"level": "LEVEL_HIGH",
"line": "1",
"linter": "biome",
"message": "Incorrect formatting, autoformat by running 'trunk fmt'",
},
],
}
`;
24 changes: 24 additions & 0 deletions linters/biome/test_data/biome_v1.6.0_basic_fmt.fmt.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// trunk-upgrade-validation:RELEASE

exports[`Testing formatter biome test basic_fmt 1`] = `
"const foobar = () => {};
const barfoo = () => {};

enum Bar {
Baz,
}

const foo = (bar: Bar) => {
switch (bar) {
case Bar.Baz:
foobar();
barfoo();
break;
}
{
!foo ? null : 1;
}
};
"
`;
7 changes: 7 additions & 0 deletions linters/biome/test_data/biome_v1.6.0_basic_json.fmt.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// trunk-upgrade-validation:RELEASE

exports[`Testing formatter biome test basic_json 1`] = `
"{ "a": "foo", "b": 1, "a": true }
"
`;
11 changes: 9 additions & 2 deletions linters/psscriptanalyzer/psscriptanalyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ import { TEST_DATA } from "tests/utils";
const checkArgs = `${path.join(TEST_DATA, "check.in.ps1")} -y`;

// Run tests with default rules
linterFmtTest({ linterName: "psscriptanalyzer", namedTestPrefixes: ["format"] });
customLinterCheckTest({ linterName: "psscriptanalyzer", testName: "check", args: checkArgs });
linterFmtTest({
linterName: "psscriptanalyzer",
namedTestPrefixes: ["format"],
});
customLinterCheckTest({
linterName: "psscriptanalyzer",
testName: "check",
args: checkArgs,
});

// Create a PSScriptAnalyzerSettings.psd1 for further testing
const preCheck = (driver: TrunkLintDriver) => {
Expand Down
24 changes: 22 additions & 2 deletions tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ export const fuzzyLinterCheckTest = ({
* Takes in the test's linter version (from snapshots).
* @param preCheck callback to run during setup
* @param postCheck callback to run for additional assertions from the base snapshot
* @param manualVersionReplacer a mutator to replace the enabled version with another version
*/
export const linterCheckTest = ({
linterName,
Expand All @@ -671,13 +672,15 @@ export const linterCheckTest = ({
skipTestIf = (_version?: string) => false,
preCheck,
postCheck,
manualVersionReplacer,
}: {
linterName: string;
dirname?: string;
namedTestPrefixes?: string[];
skipTestIf?: (version?: string) => boolean;
preCheck?: TestCallback;
postCheck?: TestCallback;
manualVersionReplacer?: (version: string) => string;
}) => {
// Step 1a: Detect test files to run
const linterTestTargets = detectTestTargets(dirname, namedTestPrefixes);
Expand All @@ -690,7 +693,14 @@ export const linterCheckTest = ({
// TODO(Tyler): Find a reliable way to replace the name "test" with version that doesn't violate snapshot export names.
describe("test", () => {
// Step 2: Define test setup and teardown
const driver = setupLintDriver(dirname, {}, linterName, linterVersion, preCheck);
const driver = setupLintDriver(
dirname,
{},
linterName,
linterVersion,
preCheck,
manualVersionReplacer,
);

// Step 3: Run each test
conditionalTest(skipTestIf(linterVersion), prefix, async () => {
Expand Down Expand Up @@ -754,6 +764,7 @@ export const linterCheckTest = ({
* Takes in the test's linter version (from snapshots).
* @param preCheck callback to run during setup
* @param postCheck callback to run for additional assertions from the base snapshot
* @param manualVersionReplacer a mutator to replace the enabled version with another version
*/
export const linterFmtTest = ({
linterName,
Expand All @@ -762,13 +773,15 @@ export const linterFmtTest = ({
skipTestIf = (_version?: string) => false,
preCheck,
postCheck,
manualVersionReplacer,
}: {
linterName: string;
dirname?: string;
namedTestPrefixes?: string[];
skipTestIf?: (version?: string) => boolean;
preCheck?: TestCallback;
postCheck?: TestCallback;
manualVersionReplacer?: (version: string) => string;
}) => {
// Step 1a: Detect test files to run and versions for asserts.
const linterTestTargets = detectTestTargets(dirname, namedTestPrefixes);
Expand All @@ -781,7 +794,14 @@ export const linterFmtTest = ({
// TODO(Tyler): Find a reliable way to replace the name "test" with version that doesn't violate snapshot export names.
describe("test", () => {
// Step 2: Define test setup and teardown
const driver = setupLintDriver(dirname, {}, linterName, linterVersion, preCheck);
const driver = setupLintDriver(
dirname,
{},
linterName,
linterVersion,
preCheck,
manualVersionReplacer,
);

// Step 3: Run each test
conditionalTest(skipTestIf(linterVersion), prefix, async () => {
Expand Down
17 changes: 11 additions & 6 deletions tests/parse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const mergeTestFailureMetadata = (original: TestResult, incoming: TestResult) =>
return;
}

// If the incoming test result is a failure and not assertion_failure, **invalidate the failure mode
// If the incoming test result is a failure and not assertion_failure, invalidate the failure mode
if (incomingSuspectedFailureMode !== "assertion_failure") {
original.testFailureMetadata.set(testFullName, incomingSuspectedFailureMode);
return;
Expand Down Expand Up @@ -312,7 +312,7 @@ const writeFailuresForNotification = (failures: FailedVersion[]) => {
const writeRerunTests = (rerunPaths: string[]) => {
const rerunString = rerunPaths.join(" ");
fs.writeFileSync(RERUN_FILE, rerunString);
console.log(`Wrote ${rerunString} reruns out to ${RERUN_FILE}:`);
console.log(`Wrote ${rerunString} reruns out to ${RERUN_FILE}`);
};

/**
Expand Down Expand Up @@ -346,10 +346,15 @@ const writeTestResults = (testResults: TestResultSummary) => {
},
]) => {
if (status !== "passed" && status !== "skipped") {
const shouldRerunTest = Array.from(testFailureMetadata.values()).every(
// If any non-assertion-type failures occur, we can't proactively generate snapshot.
(failureMode) => failureMode === "assertion_failure" || failureMode === "skipped",
);
const allMetadata = Array.from(testFailureMetadata.values());
// Must have at least one assertion_failure and no other failure types in order to proactively generate snapshot.
const shouldRerunTest =
allMetadata.every(
(failureMode) =>
failureMode === "assertion_failure" ||
failureMode === "skipped" ||
failureMode === "passed",
) && allMetadata.find((failureMode) => failureMode === "assertion_failure") !== undefined;
if (shouldRerunTest) {
rerunPaths.push(testFilePath);
}
Expand Down

0 comments on commit df1b0fa

Please sign in to comment.