A package with a build or prepare script and a tsconfig.json is built with tsc -p . in the shut-off run step, at both levels, instead of the --noEmit type-check; the fetch's --ignore-scripts never runs those scripts. mesh-sdk's tests import ../dist and failed ERR_MODULE_NOT_FOUND. The result names the step build.
53 lines
2.4 KiB
Go
53 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// The package.json of mesh-sdk's TypeScript package (feat/r4e-sdk 9cb4d59), whose tests import its own build output
|
|
// (test/retire.test.ts imports ../dist/...): built by `tsc` (build and prepare), which a fetch with --ignore-scripts
|
|
// never runs.
|
|
const sdkPackageJSON = `{"name":"@novox/mesh-sdk","version":"0.1.15","type":"module","exports":{".":"./dist/index.js"},"files":["dist"],` +
|
|
`"scripts":{"build":"tsc","test":"node --test --experimental-strip-types 'test/*.test.ts'","prepare":"tsc"}}`
|
|
|
|
// Issue 1869: a package that builds (a build or prepare script) is emitted by tsc into the workspace, inside the shut-off
|
|
// run step, at both levels, before its tests, which import what it emits; the result names it "build". A package that
|
|
// does not build is still type-checked without emitting.
|
|
func TestAPackageThatBuildsIsEmittedBeforeItsTests(t *testing.T) {
|
|
for _, level := range []string{"unit", "integration"} {
|
|
m, f, work := newMachine(t)
|
|
pkg := sdkPackageJSON
|
|
if level == "integration" {
|
|
pkg = strings.Replace(pkg, `"prepare":"tsc"`, `"prepare":"tsc","test:integration":"node --test test/it.mjs"`, 1)
|
|
}
|
|
workspaceWith(t, work, map[string]string{"package.json": pkg, "tsconfig.json": `{"compilerOptions":{"outDir":"dist"}}`,
|
|
"src/index.ts": "export const a = 1;\n", "test/retire.test.ts": "import '../dist/index.js';\n"})
|
|
out, err := m.test(context.Background(), testArgs(level))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r := out.(*TestResult)
|
|
if !slices.Contains(r.Ran, "build") || slices.Contains(r.Ran, "type-check") {
|
|
t.Errorf("%s: ran %v, want the build and no separate type-check", level, r.Ran)
|
|
}
|
|
first := joined(f.calls[0])
|
|
if strings.Contains(first, "--noEmit") || !strings.HasSuffix(first, "typescript/bin/tsc -p .") {
|
|
t.Errorf("%s: the build ran %s, want tsc -p . emitting", level, first)
|
|
}
|
|
if len(f.shut) == 0 || !strings.Contains(f.shut[0].command, "tsc -p .") {
|
|
t.Errorf("%s: the build did not run shut off", level)
|
|
}
|
|
}
|
|
m, f, work := newMachine(t)
|
|
workspaceWith(t, work, map[string]string{"package.json": `{"scripts":{"test":"node --test"}}`, "tsconfig.json": `{}`, "index.ts": "export const a = 1;\n"})
|
|
if _, err := m.test(context.Background(), testArgs("unit")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if first := joined(f.calls[0]); !strings.Contains(first, "--noEmit") {
|
|
t.Errorf("a package that does not build ran %s, want the type-check", first)
|
|
}
|
|
}
|