Testing Typescript Projects
This page will discuss common topics around working with test suites using the Mill build tool
Defining Unit Test Suites
package build
import mill._, javascriptlib._
object bar extends TypeScriptModule {
object test extends TypeScriptTests with TestModule.Jest
}
object baz extends TypeScriptModule {
object test extends TypeScriptTests with TestModule.Vitest
}
object foo extends TypeScriptModule {
object test extends TypeScriptTests with TestModule.Mocha
}
object qux extends TypeScriptModule {
object test extends TypeScriptTests with TestModule.Jasmine
}
Documentation for mill.example.javascriptlib This build defines 4 modules bar, baz, foo & qux with test suites configured to use Jest, Vitest, Mocaha & Jasmine respectively
> mill foo.test
...
...4 passing...
...
> mill bar.test
...Calculator
...
Test Suites:...1 passed, 1 total...
Tests:...4 passed, 4 total...
...
> mill baz.test
.../calculator.test.ts...
...Test Files 1 passed...
...Tests 4 passed...
...
> mill qux.test
...
4 specs, 0 failures
Test Dependencies
package build
import mill._, javascriptlib._
object bar extends TypeScriptModule {
def npmDeps = Seq("immutable@4.3.7")
object test extends TypeScriptTests with TestModule.Jest
}
object foo extends TypeScriptModule {
def moduleDeps = Seq(bar)
object test extends TypeScriptTests with TestModule.Jest
}
Documentation for mill.example.javascriptlib
In this example, foo
depend on bar
, but we also make
foo.test
depend on bar.test
.
That lets foo.test
make use of the default function exported from
bar/test/utils/bar.tests.utils.ts
, allowing us to re-use this
test helper throughout multiple modules' test suites.
> mill foo.test
PASS .../foo.test.ts
...
Test Suites:...1 passed, 1 total...
Tests:...3 passed, 3 total...
...
> mill bar.test
PASS .../bar.test.ts
...
Test Suites:...1 passed, 1 total...
Tests:...2 passed, 2 total...
...