Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrated shared-fixtures to ast-spec #6436

Conversation

JoshuaKGoldberg
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg commented Feb 7, 2023

PR Checklist

Overview

Migrates all the old shared-fixtures fixtures into the new ast-spec fixtures. Within that they're given the same folder name as their old fixture path.

It would be better long-term to split these fixtures up as described in #6065:

Each fixture should only cover one hyper-targeted, specific case to keep things easy to debug and review.

...but there are ~375 of them, and I'd rather get them into ast-spec sooner. This way they'll be easier to split up later! If this PR is approved I can file a followup issue & find-and-replace the // TODO comments in fixtures to refer to it.

Most of the work in this PR was done in two steps:

  1. 327aa0c29: Ran yarn tsx tools/migrate-fixtures.ts to create unsorted-fixtures from the old shared-fixtures
  2. bec1fe800: Deleted shared-fixtures altogether
tools/migrate-fixtures.ts
import * as cp from "node:child_process";
import { existsSync, promises as fs } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { promisify } from "node:util";

import glob from "glob";

const exec = promisify(cp.exec);

const newFixturesDir = "packages/ast-spec/src/unsorted-fixtures";

const oldFixtures = glob.sync("packages/shared-fixtures/fixtures/**/*.ts");

async function main(): Promise<void> {
  // Make sure the new fixtures directory exists, and has no prior contents
  if (existsSync(newFixturesDir)) {
    await fs.rm(newFixturesDir, { recursive: true });
  }

  await fs.mkdir(newFixturesDir, {
    recursive: true,
  });

  // Copy each of the old fixtures into the new fixtures directory
  for (const fixture of oldFixtures) {
    const [oldFileName, group] = fixture.split("/").reverse();
    const fixtureName = oldFileName.split(".")[0];
    const fixtureDirectory = path.join(
      newFixturesDir,
      group,
      "fixtures",
      fixtureName
    );

    await fs.mkdir(fixtureDirectory, { recursive: true });
    await fs.writeFile(
      path.join(fixtureDirectory, "fixture.ts"),
      await fs.readFile(fixture)
    );
  }

  // Run Jest on ast-spec to find new fixtures with syntax errors
  const tempFile = path.join(tmpdir(), "temp.json");
  try {
    await exec(`jest /fixtures --json > ${tempFile}`, {
      cwd: "packages/ast-spec",
    });
  } catch {
    /* expected */
  }
  const jestOutput = JSON.parse((await fs.readFile(tempFile)).toString()) as {
    testResults: {
      assertionResults: { ancestorTitles: string[]; status: string }[];
    }[];
  };
  await fs.rm(tempFile);

  // Filter & deduplicate messages from those failing tests
  const failingFixtures = Array.from(
    new Set(
      jestOutput.testResults[0]
        .filter(
          (assertion) =>
            assertion.ancestorTitles.includes("unsorted-fixtures") &&
            assertion.status !== "passed"
        )
        .map((assertion) => assertion.ancestorTitles.slice(2).join("/"))
    )
  );

  // For each failing fixture, move it to an _error_ directory
  for (const failingFixture of failingFixtures) {
    const failingFixtureDirectory = path.join(
      newFixturesDir,
      failingFixture.replace("/", "/fixtures/")
    );

    const newErrorFixtureDirectory = path.join(
      failingFixtureDirectory.replace("/fixtures/", "/fixtures/_error_/")
    );
    await fs.mkdir(newErrorFixtureDirectory, {
      recursive: true,
    });
    await fs.rename(
      path.join(failingFixtureDirectory, "fixture.ts"),
      path.join(newErrorFixtureDirectory, "fixture.ts")
    );
    await fs.rm(path.join(failingFixtureDirectory, "snapshots"), {
      recursive: true,
    });
  }

  // Re-run Jest to update snapshots a second time
  await exec(`jest /fixtures`, {
    cwd: "packages/ast-spec",
  });
}

main()
  .then(() => console.log("Done."))
  .catch((error) => {
    throw error;
  });

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @JoshuaKGoldberg!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

@nx-cloud
Copy link

nx-cloud bot commented Feb 7, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 05446b1. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 47 targets

Sent with 💌 from NxCloud.

@netlify
Copy link

netlify bot commented Feb 7, 2023

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 05446b1
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/63e55bb1e7f2da0008d8233e
😎 Deploy Preview https://deploy-preview-6436--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@codecov
Copy link

codecov bot commented Feb 7, 2023

Codecov Report

Merging #6436 (05446b1) into main (a9cb860) will decrease coverage by 0.87%.
The diff coverage is n/a.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6436      +/-   ##
==========================================
- Coverage   91.53%   90.66%   -0.87%     
==========================================
  Files         371      371              
  Lines       12662    12662              
  Branches     3721     3721              
==========================================
- Hits        11590    11480     -110     
- Misses        754      845      +91     
- Partials      318      337      +19     
Flag Coverage Δ
unittest 90.66% <ø> (-0.87%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/typescript-estree/src/convert-comments.ts 57.14% <0.00%> (-42.86%) ⬇️
packages/typescript-estree/src/convert.ts 85.67% <0.00%> (-11.46%) ⬇️
packages/typescript-estree/src/node-utils.ts 83.51% <0.00%> (-7.45%) ⬇️
...escript-estree/src/semantic-or-syntactic-errors.ts 80.00% <0.00%> (-6.67%) ⬇️
...pt-estree/src/parseSettings/createParseSettings.ts 95.00% <0.00%> (-2.50%) ⬇️

@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review February 7, 2023 23:52
@bradzacher
Copy link
Member

Let's do this:

  1. move this out of the src folder to a new folder called like legacy-fixtures
  2. remove the todo comments and add info to the readme about how to add fixtures and what not to do.

Eg

The legacy-fixtures folder contains all of the old fixtures from our previous testing framework. No new fixtures should be added to this folder, and instead we should be attempting to migrate and remove cases wherever possible.

insert steps #6065?

After that I think we're in a good spot to land this?

@JoshuaKGoldberg JoshuaKGoldberg changed the title chore: migrated shared-fixtures to ast-spec chore: migrated shared-fixtures to ast-spec Feb 8, 2023
@bradzacher
Copy link
Member

We'll also want to make sure these fixtures are automatically re-tested using the test tooling, so you'll need to update the test to include them

@JoshuaKGoldberg
Copy link
Member Author

Hmm, would you be upset if I moved legacy-fixtures to within src/? That way I don't have to keep these logic changes for two test directories...

@bradzacher
Copy link
Member

ah yeah I guess the test isn't built to be relative to anything other than the src folder.
feel free to drop it in there then.

Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yas

@JoshuaKGoldberg JoshuaKGoldberg merged commit fb799e7 into typescript-eslint:main Feb 10, 2023
@JoshuaKGoldberg JoshuaKGoldberg deleted the migrate-shared-fixtures-to-ast-spec branch February 10, 2023 02:33
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Repo: move shared-fixtures tests to ast-spec fixtures
2 participants