Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Expose testing utilities (helper.ts) in a d.ts file and in npm package #532

Closed
HamletDRC opened this issue Jul 27, 2015 · 6 comments
Closed

Comments

@HamletDRC
Copy link
Contributor

I have written several custom tslint rules.
I have some ad-hoc testing utilities written to test them, but I would rather just reuse the framework for testing rules that is defined in the tslint source code. It would make it easier for me to test my own rules and also easier to port back to the main source code and submit as pull requests.

What I /think/ I need is:

  • the code from helper.ts exposed in a tslint-test.d.ts
  • the code from helper.ts (and dependencies) compiled into tslint-test.js

Please note: I may not know what I want technically. From a feature standpoint... I just want my tests to look exactly like your tests!

@adidahiya
Copy link
Contributor

This is definitely a useful feature and we do want to expose testing utilities for custom rules.

I think the easiest way to do this would be to refactor our testing utilities into a TestLib object which we then export from our current npm module + include its typings in tslint.d.ts. The goal would be to allow users to write import { TestLib } from "tslint";

Thoughts @gscshoyru, @ashwinr?

@gscshoyru
Copy link
Contributor

I feel a little strange exposing test code in the main repository -- but eslint does it, and the fact that we have pluggable rules is meant to be a feature. So I think that your idea makes sense.

Except: I think we might want to split the testlib typings out into another d.ts file, since those types/functionality should only be available in tests.

@adidahiya
Copy link
Contributor

+1 for exposing the typings separately. although that makes our build a little more complicated...

@adidahiya
Copy link
Contributor

This is being implemented in #900. With that PR we're just going to do the straightforward thing and leave the typings where they are, accessible to users like this:

// names of these exports might change
import {runTest, consoleTestResultHandler} from "tslint/lib/test";

const didAllTestsPass = consoleTestResultHandler(runTest("path/to/my/testing/dir/"));
if (!didAllTestsPass) {
    process.exit(1);
}

@jkillian
Copy link
Contributor

Also, the --test command will provide a way to test rules via the CLI

@andy-hanson
Copy link
Contributor

Can this be closed then?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants