Skip to content

TypeScript: support testing #22148

@huonw

Description

@huonw

Is your feature request related to a problem? Please describe.

We have typescript_test and tsx_test (and so on) targets, but the test goal doesn't find them.

Describe the solution you'd like

Running pants test :: should run typescript tests, somehow.

Notes:

Demo using ts-jest:

cd $(mktemp -d)

cat > package.json <<'EOF'
{
  "name": "demo",
  "version": "0.0.1",
  "scripts": {
    "test": "npx jest"
  },
  "dependencies": {
    "@types/jest": "29.5.14",
    "jest": "29.7.0",
    "ts-jest": "29.3.0"
  },
  "jest": {
    "testMatch": ["<rootDir>/**/*.test.{js,ts}"],
    "transform": {
      "^.+\\.tsx?$": "ts-jest"
    }
  }
}
EOF

cat > typescript.test.ts <<EOF
test("typescript", () => {});
EOF


# setup the lockfile
npm install

# OKAY: running tests outside of pants runs TS tests
npm test
#  PASS  ./typescript.test.ts


# Now try Pants:
cat > pants.toml <<EOF
[GLOBAL]
pants_version = "2.26.0a0"

backend_packages.add = [
  "pants.backend.experimental.javascript",
  "pants.backend.experimental.typescript",
]

[nodejs]
package_manager = "npm"
EOF

cat > BUILD <<EOF
package_json(name="root", dependencies=[], scripts=[node_test_script()])

typescript_tests(name="ts_tests")
EOF

# Currently runs nothing:
pants test ::

Describe alternatives you've considered

None yet.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions