Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ func (p *selectionPlatform) SanityCheck(ctx context.Context) error {
func TestResolveTestEnvironment(t *testing.T) {
original := detectPlatform
t.Cleanup(func() { detectPlatform = original })
p := &selectionPlatform{framework: framework.NewJest()}
p := &selectionPlatform{framework: framework.NewJest(platform.NewJavaScript())}
calls := 0
detectPlatform = func() (platform.Platform, error) {
calls++
Expand All @@ -980,7 +980,7 @@ func TestCommandsRejectSelectionErrorsBeforePlanningOrExecution(t *testing.T) {
original := detectPlatform
t.Cleanup(func() { detectPlatform = original })
failure := errors.New("selection failed")
p := &selectionPlatform{framework: framework.NewJest()}
p := &selectionPlatform{framework: framework.NewJest(platform.NewJavaScript())}
detectPlatform = func() (platform.Platform, error) {
if stage == "platform" {
return nil, failure
Expand Down Expand Up @@ -1027,7 +1027,7 @@ func TestPlanDoesNotCheckTracerPrerequisites(t *testing.T) {
probeReached := errors.New("runtime tag probe reached")
p := &selectionPlatform{
platformName: name,
framework: framework.NewJest(),
framework: framework.NewJest(platform.NewJavaScript()),
sanityErr: errors.New("tracer is not installed"),
tagsErr: probeReached,
}
Expand Down
5 changes: 3 additions & 2 deletions internal/compatibility/cucumber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/DataDog/ddtest/internal/discovery"
"github.com/DataDog/ddtest/internal/framework"
"github.com/DataDog/ddtest/internal/platform"
)

func TestCucumberAdapterIntegration(t *testing.T) {
Expand Down Expand Up @@ -63,7 +64,7 @@ Given('a failing step', function () { throw new Error('unassigned file ran') })
}

configureFramework(shellCommand(cucumberBinary), "")
cucumber := framework.NewCucumber()
cucumber := framework.NewCucumber(platform.NewJavaScript())
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
discovered, err := cucumber.DiscoverTestFiles(ctx, discovery.TestFileSet{Pattern: cucumber.TestPattern()})
Expand All @@ -74,7 +75,7 @@ Given('a failing step', function () { throw new Error('unassigned file ran') })
if !slices.Equal(discovered, wantFiles) {
t.Fatalf("discovered = %v", discovered)
}
if err := cucumber.RunTests(ctx, []string{"features/included.feature"}, nil); err != nil {
if err := cucumber.RunTests(ctx, []string{"features/included.feature"}, map[string]string{"NODE_OPTIONS": ""}); err != nil {
t.Fatalf("selected-file run failed: %v", err)
}
}
7 changes: 4 additions & 3 deletions internal/compatibility/cypress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/DataDog/ddtest/internal/discovery"
"github.com/DataDog/ddtest/internal/framework"
"github.com/DataDog/ddtest/internal/platform"
)

func TestCypressAdapterIntegration(t *testing.T) {
Expand Down Expand Up @@ -109,7 +110,7 @@ func TestCypressAdapterIntegration(t *testing.T) {
}

configureFramework(shellCommand(binary, "run", "--project", test.projectName), "")
cypress := framework.NewCypress()
cypress := framework.NewCypress(platform.NewJavaScript())
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
files, err := cypress.DiscoverTestFiles(ctx, discovery.TestFileSet{})
cancel()
Expand Down Expand Up @@ -159,7 +160,7 @@ func TestCypressAdapterExecutionIntegration(t *testing.T) {
command = []string{xvfb, "-a", binary, "run"}
}
configureFramework(shellCommand(command...), "")
cypress := framework.NewCypress()
cypress := framework.NewCypress(platform.NewJavaScript())
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()

Expand All @@ -170,7 +171,7 @@ func TestCypressAdapterExecutionIntegration(t *testing.T) {
wantFiles := []string{"cypress/e2e/selected.cy.js", "cypress/e2e/unselected.cy.js"}
requireFiles(t, files, wantFiles)

if err := cypress.RunTests(ctx, []string{"cypress/e2e/selected.cy.js"}, nil); err != nil {
if err := cypress.RunTests(ctx, []string{"cypress/e2e/selected.cy.js"}, map[string]string{"NODE_OPTIONS": ""}); err != nil {
t.Fatalf("selected-file run failed: %v", err)
}
}
16 changes: 16 additions & 0 deletions internal/compatibility/framework_env_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package compatibility

import (
"testing"

"github.com/DataDog/ddtest/internal/framework"
)

func frameworkRunEnv(t *testing.T, f framework.Framework) map[string]string {
t.Helper()
env, err := f.Platform().RunEnv(framework.RuntimeOptions{ESM: f.Name() == "vitest"})
if err != nil {
t.Fatal(err)
}
return env
}
5 changes: 3 additions & 2 deletions internal/compatibility/jest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/DataDog/ddtest/internal/discovery"
"github.com/DataDog/ddtest/internal/framework"
"github.com/DataDog/ddtest/internal/platform"
"github.com/DataDog/ddtest/internal/testdrive"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -47,7 +48,7 @@ process.on('exit', () => {
t.Setenv("NODE_OPTIONS", "--require "+strconv.Quote(filepath.Join(root, "noisy.cjs")))
t.Chdir(root)

jest := framework.NewJest()
jest := framework.NewJest(platform.NewJavaScript())
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()

Expand All @@ -59,7 +60,7 @@ process.on('exit', () => {
wantFiles := []string{"tests/selected.test.js", "tests/unselected.test.js"}
requireFiles(t, files, wantFiles)

if err := jest.RunTests(ctx, []string{"tests/selected.test.js"}, map[string]string{"DDTEST_JEST_WORKER": "selected"}); err != nil {
if err := jest.RunTests(ctx, []string{"tests/selected.test.js"}, map[string]string{"DDTEST_JEST_WORKER": "selected", "NODE_OPTIONS": os.Getenv("NODE_OPTIONS")}); err != nil {
t.Fatalf("selected-file run failed: %v", err)
}
}
Expand Down
6 changes: 4 additions & 2 deletions internal/compatibility/minitest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

"github.com/DataDog/ddtest/internal/discovery"
"github.com/DataDog/ddtest/internal/framework"
"github.com/DataDog/ddtest/internal/platform"
"github.com/DataDog/ddtest/internal/settings"
)

func TestMinitestAdapterIntegration(t *testing.T) {
Expand Down Expand Up @@ -50,8 +52,8 @@ end
`)
t.Chdir(root)

minitest := framework.NewMinitest()
minitest.SetPlatformEnv(map[string]string{"RUBYOPT": "-rbundler/setup -rdatadog/ci/auto_instrument"})
minitest := framework.NewMinitest(platform.NewRuby(settings.TestSkippingLevelTest))
t.Setenv("RUBYOPT", "-rbundler/setup -rdatadog/ci/auto_instrument")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()

Expand Down
12 changes: 6 additions & 6 deletions internal/compatibility/mocha_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestMochaAdapterIntegration(t *testing.T) {
writeFixture(t, root, "test/unselected.spec.js", `describe("unselected", () => { it("must not run", () => { throw new Error("unselected file ran") }) })`)
t.Chdir(root)

mocha := framework.NewMocha()
mocha := framework.NewMocha(platform.NewJavaScript())
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
files, err := mocha.DiscoverTestFiles(ctx, discovery.TestFileSet{Pattern: mocha.TestPattern()})
Expand All @@ -37,7 +37,7 @@ func TestMochaAdapterIntegration(t *testing.T) {
}
want := []string{"test/selected.spec.js", "test/unselected.spec.js"}
requireFiles(t, files, want)
if err := mocha.RunTests(ctx, []string{"test/selected.spec.js"}, nil); err != nil {
if err := mocha.RunTests(ctx, []string{"test/selected.spec.js"}, map[string]string{"NODE_OPTIONS": ""}); err != nil {
t.Fatalf("selected-file run failed: %v", err)
}

Expand Down Expand Up @@ -67,15 +67,15 @@ func TestMochaAdapterCustomLocationAndCommandIntegration(t *testing.T) {
t.Chdir(root)
configureFramework(shellCommand(wrapper, mochaCommand), "spec/**/*.js")

mocha := framework.NewMocha()
mocha := framework.NewMocha(platform.NewJavaScript())
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
files, err := mocha.DiscoverTestFiles(ctx, discovery.TestFileSet{Pattern: mocha.TestPattern()})
if err != nil {
t.Fatal(err)
}
requireFiles(t, files, []string{"spec/custom.spec.js"})
if err := mocha.RunTests(ctx, files, nil); err != nil {
if err := mocha.RunTests(ctx, files, map[string]string{"NODE_OPTIONS": ""}); err != nil {
t.Fatalf("custom-command run failed: %v", err)
}
}
Expand Down Expand Up @@ -131,9 +131,9 @@ func testMochaActionPreloadIntegration(t *testing.T, explicit bool) {
fw, err = javascript.DetectFramework()
require.NoError(t, err)
if explicit {
require.Empty(t, fw.GetPlatformEnv(), "worker should inherit the customer's absolute preload")
require.Empty(t, frameworkRunEnv(t, fw), "worker should inherit the customer's absolute preload")
} else {
require.Equal(t, "-r "+strconv.Quote(preload), fw.GetPlatformEnv()["NODE_OPTIONS"])
require.Equal(t, "-r "+strconv.Quote(preload), frameworkRunEnv(t, fw)["NODE_OPTIONS"])
}
files, err = fw.DiscoverTestFiles(ctx, discovery.TestFileSet{Pattern: fw.TestPattern()})
require.NoError(t, err)
Expand Down
11 changes: 6 additions & 5 deletions internal/compatibility/playwright_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/DataDog/ddtest/internal/discovery"
"github.com/DataDog/ddtest/internal/framework"
"github.com/DataDog/ddtest/internal/platform"
)

func TestPlaywrightAdapterIntegration(t *testing.T) {
Expand Down Expand Up @@ -72,7 +73,7 @@ func TestPlaywrightAdapterIntegration(t *testing.T) {

baseCommand := []string{binary, "test", "--config", "apps/web/playwright.config.js"}
configureFramework(shellCommand(baseCommand...), "")
playwright := framework.NewPlaywright()
playwright := framework.NewPlaywright(platform.NewJavaScript())
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
files, err := playwright.DiscoverTestFiles(ctx, discovery.TestFileSet{})
Expand All @@ -84,8 +85,8 @@ func TestPlaywrightAdapterIntegration(t *testing.T) {

projectCommand := append(append([]string{}, baseCommand...), "--project", "one")
configureFramework(shellCommand(projectCommand...), "")
projectPlaywright := framework.NewPlaywright()
if err := projectPlaywright.RunTests(ctx, []string{"apps/web/tests/a.spec.ts"}, nil); err != nil {
projectPlaywright := framework.NewPlaywright(platform.NewJavaScript())
if err := projectPlaywright.RunTests(ctx, []string{"apps/web/tests/a.spec.ts"}, map[string]string{"NODE_OPTIONS": ""}); err != nil {
t.Fatalf("running one assigned file failed: %v", err)
}
if source, ok := playwright.SourceFileForSuite("a.spec.ts"); !ok || source != "apps/web/tests/a.spec.ts" {
Expand All @@ -94,15 +95,15 @@ func TestPlaywrightAdapterIntegration(t *testing.T) {

emptyCommand := append(append([]string{}, baseCommand...), "__ddtest_no_match__")
configureFramework(shellCommand(emptyCommand...), "")
emptyPlaywright := framework.NewPlaywright()
emptyPlaywright := framework.NewPlaywright(platform.NewJavaScript())
if files, err := emptyPlaywright.DiscoverTestFiles(ctx, discovery.TestFileSet{}); err != nil || len(files) != 0 {
t.Fatalf("empty native discovery = %v, %v", files, err)
}

writeFixture(t, projectRoot, "tests/broken.spec.ts", "throw new Error('collection exploded')\n")
brokenCommand := append(append([]string{}, baseCommand...), "broken.spec.ts")
configureFramework(shellCommand(brokenCommand...), "")
brokenPlaywright := framework.NewPlaywright()
brokenPlaywright := framework.NewPlaywright(platform.NewJavaScript())
if _, err := brokenPlaywright.DiscoverTestFiles(ctx, discovery.TestFileSet{}); err == nil {
t.Fatal("collection failure was accepted as an empty discovery")
}
Expand Down
23 changes: 22 additions & 1 deletion internal/compatibility/project_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,27 @@ atexit.register(lambda: print('shutdown stderr', file=sys.stderr))
tags, err := python.CreateTagsMap(ctx)
require.NoError(t, err, "planning tags must not require an installed tracer")
requireRuntimeTags(t, tags, "python")
resetSettingsAfterTest(t)
// A custom discovery command can supply the report without importing ddtrace.
writeFixture(t, root, "discovery.py", `import json, os
from pathlib import Path
report = Path(os.environ["DD_TEST_OPTIMIZATION_DISCOVERY_FILE"])
report.parent.mkdir(parents=True, exist_ok=True)
report.write_text(json.dumps({"name": "test_example", "suite": "test_example.py", "suiteSourceFile": "test_example.py"}))
`)
writeFixture(t, root, "test_example.py", "def test_example(): pass\n")
configureFramework(shellCommand("python", filepath.Join(root, "discovery.py")), "")
pytest := framework.NewPytest(python)
files := discovery.TestFileSet{Pattern: "test_*.py"}
tests, err := pytest.DiscoverTests(ctx, files)
require.NoError(t, err)
require.Len(t, tests, 1)
require.Equal(t, "test_example", tests[0].Name)
require.Equal(t, "test_example.py", tests[0].SuiteSourceFile)
discovered, err := pytest.DiscoverTestFiles(ctx, files)
require.NoError(t, err)
require.Equal(t, []string{"test_example.py"}, discovered)

t.Setenv("PYTHONPATH", filepath.Join(root, "packages"))
require.NoError(t, python.SanityCheck(ctx))
version, err := python.DetectTracer(ctx, platform.TracerOptions{Command: "python"})
Expand Down Expand Up @@ -210,7 +231,7 @@ func TestRubyTagsWithoutTracer(t *testing.T) {
resetSettingsAfterTest(t)
writeFixture(t, root, "discovery.rb", "File.write('discovery-ran', 'unexpected')\n")
configureFramework(shellCommand("ruby", filepath.Join(root, "discovery.rb")), "")
for _, fw := range []framework.Framework{framework.NewRSpec(), framework.NewMinitest()} {
for _, fw := range []framework.Framework{framework.NewRSpec(platform.NewRuby(settings.TestSkippingLevelTest)), framework.NewMinitest(platform.NewRuby(settings.TestSkippingLevelTest))} {
t.Run(fw.Name(), func(t *testing.T) {
t.Cleanup(func() { _ = os.Remove(filepath.Join(root, "discovery-ran")) })
writeFixture(t, root, "example_test.rb", "# File discovery needs no tracer.\n")
Expand Down
5 changes: 3 additions & 2 deletions internal/compatibility/pytest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/DataDog/ddtest/internal/discovery"
"github.com/DataDog/ddtest/internal/framework"
"github.com/DataDog/ddtest/internal/platform"
)

func TestPyTestAdapterIntegration(t *testing.T) {
Expand All @@ -29,8 +30,8 @@ def test_preserves_worker_environment():
t.Chdir(root)

configureFramework(shellCommand(python, "-m", "pytest"), "")
pytest := framework.NewPytest()
pytest.SetPlatformEnv(map[string]string{"PYTEST_ADDOPTS": "--ddtrace"})
pytest := framework.NewPytest(platform.NewPython())
t.Setenv("PYTEST_ADDOPTS", "--ddtrace")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()

Expand Down
6 changes: 4 additions & 2 deletions internal/compatibility/rspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

"github.com/DataDog/ddtest/internal/discovery"
"github.com/DataDog/ddtest/internal/framework"
"github.com/DataDog/ddtest/internal/platform"
"github.com/DataDog/ddtest/internal/settings"
)

func TestRSpecAdapterIntegration(t *testing.T) {
Expand Down Expand Up @@ -35,8 +37,8 @@ end
`)
t.Chdir(root)

rspec := framework.NewRSpec()
rspec.SetPlatformEnv(map[string]string{"RUBYOPT": "-rbundler/setup -rdatadog/ci/auto_instrument"})
rspec := framework.NewRSpec(platform.NewRuby(settings.TestSkippingLevelTest))
t.Setenv("RUBYOPT", "-rbundler/setup -rdatadog/ci/auto_instrument")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()

Expand Down
Loading
Loading