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

Add automated regression testing against old TS versions #1752

Open
bradzacher opened this issue Mar 17, 2020 · 7 comments · May be fixed by #5573
Open

Add automated regression testing against old TS versions #1752

bradzacher opened this issue Mar 17, 2020 · 7 comments · May be fixed by #5573
Assignees
Labels
accepting prs Go ahead, send a pull request that resolves this issue tests anything to do with testing

Comments

@bradzacher
Copy link
Member

bradzacher commented Mar 17, 2020

#1698 introduced a regression for TS<3.8.x (#1746).
This wasn't caught by the type checker, nor was it caught by the tests because both were using TS3.8.

It was a simple mistake, but one that shouldn't have happened.
We should add an integration test in order to make sure that this doesn't happen again.

We cannot run builds against older versions of TS, because our code relies upon property types etc added by the latest versions, but we can easily run tests against the old versions.
I don't think we need to test every version we support, but at least testing against the previous one or two minors and the minimum supported version should be good enough.

Regressions that would have been caught:

@JoshuaKGoldberg
Copy link
Member

Copying the useful bits from my dup issue:

The simplest approach might be extending CI's unit_tests_on_other_node_versions to also switch on different TypeScript package versions (example syntax).

It'd be great as a next step (followup issue?) to also make use of CodeCov's report merging to combine unit test coverage from all of them. #2516 is an example PR where code under test changes behavior on the TypeScript version.

@bradzacher
Copy link
Member Author

The thing that makes this difficult is ensuring that the rules that have variant functionality on TS versions will have to pass on the other TS versions (this is the same problem that makes #2464 difficult)

To make this work we'll have to extend and customise the core ESLint RuleTester and design a config system for it.


There's a lot of codecov features we should totally leverage more of - I've just never bothered to read the docs 😅

@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Sep 15, 2020

To start, can that be as simple as checking the TypeScript version at Jest runtime when constructing the .test.ts file tests?

tests/rules/some-rule.test.ts:

ruleTester.run('some-rule', rule, {
  // ...
});

if (util.isAboveTsVersion('3.9')) {
  ruleTester.run('some-rule typescript@>=3.9', rule, {
    // ...
  });
} else {
  ruleTester.run('some-rule typescript@<3.9', rule, {
    // ...
  });
}

util/versions.ts:

// (may need to add overrides or some logic if any TS releases had unusual version numbers...)
export const isAboveTsVersion = (version: string) =>
  semver.satisfies(
    ts.version,
    `>= ${version}.0 || >= ${version}.1-rc || >= ${version}.0-beta`,
    {
      includePrerelease: true,
    },
  );

Are there other testing features needed?

@bradzacher
Copy link
Member Author

It should be pretty trivial for us to extend the rule tester and add a property to the config object. It'd set a good precedence for doing a similar thing with ESLint version

We can chuck it in here

Something like:

type RunTests<TMessageIds extends string, TOptions extends Readonly<unknown[]>> = MakeSomeChangesToTheType<TSESLint.RunTests<TMessageIds, TOptions>>;

class RuleTester extends RuleTester {
  run<TMessageIds extends string, TOptions extends Readonly<unknown[]>>(
    name: string,
    rule: TSESLint.RuleModule<TMessageIds, TOptions>,
    testsReadonly: RunTests<TMessageIds, TOptions>,
  ): void {
    const tests = { ...testsReadonly };

    // standardize the valid tests as objects
    tests.valid = tests.valid.map(test => {
      if (typeof test === 'string') {
        return {
          code: test,
        };
      }
      return test;
    });

    const filter = test => isValidTsVersion(test.tsVersion);

    tests.valid = tests.valid.filter(filter);
    tests.invalid = tests.valid.filter(filter);
  }
}

@voxpelli
Copy link

Following up on original suggestion, I just pushed a suggestion to type-fest that re-utilizes the matrix for testing on many ts-versions: sindresorhus/type-fest@3a4bb56

@JoshuaKGoldberg JoshuaKGoldberg added the accepting prs Go ahead, send a pull request that resolves this issue label Oct 25, 2021
@bradzacher
Copy link
Member Author

bradzacher commented Jul 24, 2022

I think in the next major we need to consider filling DefinitelyTyped's example and bump our minimum TS version as well?

We support a super old one and it's getting to be a but out of date at this point!
We go back as TS 3.1 which is 4 years old!

DT supports 4.0 and above for a few more days (at which point 4.1 will be EOL)
https://github.com/DefinitelyTyped/DefinitelyTyped/#support-window

@JoshuaKGoldberg

@JoshuaKGoldberg
Copy link
Member

Proposal: let's support the same time range as DT? I don't see any particular reason to go older.

@bradzacher bradzacher added this to the 6.0.0 milestone Jul 24, 2022
bradzacher added a commit that referenced this issue Nov 2, 2022
BREAKING CHANGE:
Bumps the minimum supported range and removes handling for old versions.

Ref #1752
@bradzacher bradzacher removed this from the 6.0.0 milestone Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue tests anything to do with testing
Projects
None yet
3 participants