Skip to content

Commit

Permalink
add internalize scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Jan 22, 2025
1 parent 6c4752c commit 8543b57
Show file tree
Hide file tree
Showing 3 changed files with 258 additions and 0 deletions.
198 changes: 198 additions & 0 deletions internalize.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
diff --git a/.github/workflows/tc39.yml b/.github/workflows/tc39.yml
index bd223f97a..e82421110 100644
--- a/.github/workflows/tc39.yml
+++ b/.github/workflows/tc39.yml
@@ -27,6 +27,6 @@ jobs:
- name: Run tests
run: |
set -x
- cd js/tc39
+ cd internal/js/tc39
sh checkout.sh
go test -timeout 1h
diff --git a/.github/workflows/wpt.yml b/.github/workflows/wpt.yml
index 1cd84215e..e2f14adbd 100644
--- a/.github/workflows/wpt.yml
+++ b/.github/workflows/wpt.yml
@@ -22,12 +22,12 @@ jobs:
- name: Run Streams Tests
run: |
set -x
- cd js/modules/k6/experimental/streams/tests
+ cd internal/js/modules/k6/experimental/streams/tests
sh checkout.sh
go test ../... -tags=wpt
- name: Run Webcrypto Tests
run: |
set -x
- cd js/modules/k6/webcrypto/tests
+ cd internal/js/modules/k6/webcrypto/tests
sh checkout.sh
go test ./... -tags=wpt
diff --git a/.gitignore b/.gitignore
index 3a37d8837..bdce1071f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,8 +2,8 @@
/k6.exe
/dist
/pkg-build
-/js/tc39/TestTC39
-/js/modules/k6/experimental/streams/tests/wpt
+/internal/js/tc39/TestTC39
+/internal/js/modules/k6/experimental/streams/tests/wpt

.vscode
*.sublime-workspace
@@ -36,4 +36,4 @@ script.js
/packaging/*.gpg

# web platform tests
-js/modules/k6/webcrypto/tests/wpt/
+/internal/js/modules/k6/webcrypto/tests/wpt/
diff --git a/cmd/execute.go b/cmd/execute.go
new file mode 100644
index 000000000..e84f839ba
--- /dev/null
+++ b/cmd/execute.go
@@ -0,0 +1,10 @@
+// Package cmd is here to provide a way for xk6 to build a binary with added extensions
+package cmd
+
+import "go.k6.io/k6/internal/cmd"
+
+// Execute exectues the k6 command
+// It only is exported here for backwards compatibility and the ability to use xk6 to build extended k6
+func Execute() {
+ cmd.Execute()
+}
diff --git a/cmd/tests/global_state.go b/cmd/tests/global_state.go
new file mode 100644
index 000000000..2b06bbf11
--- /dev/null
+++ b/cmd/tests/global_state.go
@@ -0,0 +1,17 @@
+// Package tests contains types needed for running integration tests that run k6 commands.
+package tests
+
+import (
+ "testing"
+
+ "go.k6.io/k6/internal/cmd/tests"
+)
+
+// GlobalTestState is a wrapper around GlobalState for use in tests.
+type GlobalTestState = tests.GlobalTestState
+
+// NewGlobalTestState returns an initialized GlobalTestState, mocking all
+// GlobalState fields for use in tests.
+func NewGlobalTestState(tb testing.TB) *GlobalTestState {
+ return tests.NewGlobalTestState(tb)
+}
diff --git a/internal/cmd/tests/cmd_run_grpc_test.go b/internal/cmd/tests/cmd_run_grpc_test.go
index 6783f4e11..a7399db44 100644
--- a/internal/cmd/tests/cmd_run_grpc_test.go
+++ b/internal/cmd/tests/cmd_run_grpc_test.go
@@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
)

-const projectRootPath = "../../"
+const projectRootPath = "../../../"

// TestGRPCInputOutput runs same k6's scripts that we have in example folder
// it check that output contains/not contains cetane things
@@ -90,7 +90,7 @@ func TestGRPCInputOutput(t *testing.T) {

// Read the proto file from the testutils package
// it's same that we use in the examples
- proto, err := os.ReadFile(projectRootPath + "lib/testutils/grpcservice/route_guide.proto") //nolint:forbidigo
+ proto, err := os.ReadFile(projectRootPath + "internal/lib/testutils/grpcservice/route_guide.proto") //nolint:forbidigo
require.NoError(t, err)

for name, test := range tc {
diff --git a/internal/js/eventloop/eventloop_test.go b/internal/js/eventloop/eventloop_test.go
index 459960d7e..ed4f87877 100644
--- a/internal/js/eventloop/eventloop_test.go
+++ b/internal/js/eventloop/eventloop_test.go
@@ -199,7 +199,7 @@ func TestEventLoopRejectGoError(t *testing.T) {
return err
})
loop.WaitOnRegistered()
- require.EqualError(t, err, "Uncaught (in promise) GoError: some error\n\tat go.k6.io/k6/js/eventloop_test.TestEventLoopRejectGoError.func1 (native)\n\tat <eval>:1:31(2)\n")
+ require.EqualError(t, err, "Uncaught (in promise) GoError: some error\n\tat go.k6.io/k6/internal/js/eventloop_test.TestEventLoopRejectGoError.func1 (native)\n\tat <eval>:1:31(2)\n")
}

func TestEventLoopRejectThrow(t *testing.T) {
@@ -216,7 +216,7 @@ func TestEventLoopRejectThrow(t *testing.T) {
return err
})
loop.WaitOnRegistered()
- require.EqualError(t, err, "Uncaught (in promise) GoError: throw error\n\tat go.k6.io/k6/js/eventloop_test.TestEventLoopRejectThrow.func1 (native)\n\tat <eval>:1:31(2)\n")
+ require.EqualError(t, err, "Uncaught (in promise) GoError: throw error\n\tat go.k6.io/k6/internal/js/eventloop_test.TestEventLoopRejectThrow.func1 (native)\n\tat <eval>:1:31(2)\n")
}

func TestEventLoopAsyncAwait(t *testing.T) {
diff --git a/internal/js/modules/k6/webcrypto/cmd_run_test.go b/internal/js/modules/k6/webcrypto/cmd_run_test.go
index 68df57aaf..3ee0692fd 100644
--- a/internal/js/modules/k6/webcrypto/cmd_run_test.go
+++ b/internal/js/modules/k6/webcrypto/cmd_run_test.go
@@ -51,7 +51,7 @@ func TestExamplesInputOutput(t *testing.T) {
"level=error", // no error messages
}

- const examplesDir = "../../../../examples/webcrypto"
+ const examplesDir = "../../../../../examples/webcrypto"

// List of the directories containing the examples
// that we should run and check that they produce the expected output
diff --git a/lib/testutils/httpmultibin/nested_types/nested_types.proto b/internal/lib/testutils/httpmultibin/nested_types/nested_types.proto
similarity index 100%
rename from lib/testutils/httpmultibin/nested_types/nested_types.proto
rename to internal/lib/testutils/httpmultibin/nested_types/nested_types.proto
diff --git a/js/modules/require_impl.go b/js/modules/require_impl.go
index 5d10dd515..71098ec37 100644
--- a/js/modules/require_impl.go
+++ b/js/modules/require_impl.go
@@ -202,7 +202,7 @@ func getPreviousRequiringFile(vu VU) (string, error) {

for i, frame := range frames[1:] { // first one should be the current require
// TODO have this precalculated automatically
- if frame.FuncName() == "go.k6.io/k6/js.(*requireImpl).require-fm" {
+ if frame.FuncName() == "go.k6.io/k6/internal/js.(*requireImpl).require-fm" {
// we need to get the one *before* but as we skip the first one the index matches ;)
result := frames[i].SrcName()
if result == "file:///-" {
diff --git a/main.go b/main.go
index d2b2a33f8..84212739b 100644
--- a/main.go
+++ b/main.go
@@ -2,7 +2,7 @@
package main

import (
- "go.k6.io/k6/internal/cmd"
+ "go.k6.io/k6/cmd"
)

func main() {
"go.k6.io/k6/js/modulestest"

"github.com/stretchr/testify/require"
diff --git a/internal/js/modules/k6/webcrypto/tests/test_setup_test.go b/internal/js/modules/k6/webcrypto/tests/test_setup_test.go
index 42d42b9a9..2abab430d 100644
--- a/internal/js/modules/k6/webcrypto/tests/test_setup_test.go
+++ b/internal/js/modules/k6/webcrypto/tests/test_setup_test.go
@@ -5,9 +5,9 @@ package tests
import (
"testing"

- "go.k6.io/k6/js/compiler"
- k6encoding "go.k6.io/k6/js/modules/k6/encoding"
- "go.k6.io/k6/js/modules/k6/webcrypto"
+ "go.k6.io/k6/internal/js/compiler"
+ k6encoding "go.k6.io/k6/internal/js/modules/k6/encoding"
+ "go.k6.io/k6/internal/js/modules/k6/webcrypto"
"go.k6.io/k6/js/modulestest"

"github.com/stretchr/testify/require"
35 changes: 35 additions & 0 deletions internalize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh
mkdir -p internal

list=`comm -3 <(go list ./... | grep -v '^go.k6.io/k6/internal' | sort | uniq) <( cat publicly_used_imports.txt )`

for i in $list; do
if [[ $i == "go.k6.io/k6" ]] then
continue
fi
i=${i##go.k6.io/k6/}

mvpkg $i internal/$i
find $i -maxdepth 1 -type f | xargs -I '{}' -n 1 git mv '{}' internal/$i
done

git mv cmd/testdata internal/cmd/testdata
git mv cmd/tests/testdata internal/cmd/tests/testdata
git mv js/modules/k6/browser/tests/static internal/js/modules/k6/browser/tests/static
git mv js/modules/k6/webcrypto/tests internal/js/modules/k6/webcrypto/tests
git mv js/modules/k6/experimental/streams/tests internal/js/modules/k6/experimental/streams/tests
git mv js/modules/k6/experimental/websockets/autobahn_tests internal/js/modules/k6/experimental/websockets/autobahn_tests
git mv lib/testutils/httpmultibin/grpc_protoset_testing internal/lib/testutils/httpmultibin/grpc_protoset_testing
git mv output/cloud/expv2/integration/testdata internal/output/cloud/expv2/integration/testdata

patch -p1 < internalize.patch

# clean empty folders that are left over after all the moving
while find -type d -empty | grep -v .git | xargs rm -r
do
true
done

git add internal
git add cmd
git commit -a -n -m "chore: Move not publicly used APIs in internal package"
25 changes: 25 additions & 0 deletions publicly_used_imports.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
go.k6.io/k6/api/v1
go.k6.io/k6/api/v1/client
go.k6.io/k6/cloudapi
go.k6.io/k6/cmd/state
go.k6.io/k6/errext
go.k6.io/k6/errext/exitcodes
go.k6.io/k6/ext
go.k6.io/k6/js/common
go.k6.io/k6/js/modules
go.k6.io/k6/js/modules/k6
go.k6.io/k6/js/modules/k6/html
go.k6.io/k6/js/modules/k6/http
go.k6.io/k6/js/modulestest
go.k6.io/k6/js/promises
go.k6.io/k6/lib
go.k6.io/k6/lib/consts
go.k6.io/k6/lib/executor
go.k6.io/k6/lib/fsext
go.k6.io/k6/lib/netext
go.k6.io/k6/lib/netext/httpext
go.k6.io/k6/lib/types
go.k6.io/k6/metrics
go.k6.io/k6/output
go.k6.io/k6/output/cloud/expv2
go.k6.io/k6/output/csv

0 comments on commit 8543b57

Please sign in to comment.