Skip to content

Commit

Permalink
Remove test specifics from shared modulestest
Browse files Browse the repository at this point in the history
  • Loading branch information
joanlopez committed Apr 24, 2024
1 parent b73c40f commit 3ecab30
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 1,774 deletions.
11 changes: 0 additions & 11 deletions js/modulestest/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package modulestest

import (
"io"
"io/fs"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -34,16 +33,6 @@ func CompileFile(base, name string) (*goja.Program, error) {
return compile(name, b)
}

// CompileFileFromFS compiles a JS file like CompileFile, but using a [fs.FS] as base.
func CompileFileFromFS(base fs.FS, name string) (*goja.Program, error) {
b, err := fs.ReadFile(base, name)
if err != nil {
return nil, err
}

return compile(name, b)
}

func compile(name string, b []byte) (*goja.Program, error) {
program, err := goja.Compile(name, string(b), false)
if err != nil {
Expand Down
64 changes: 0 additions & 64 deletions js/modulestest/console.go

This file was deleted.

41 changes: 0 additions & 41 deletions js/modulestest/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ package modulestest

import (
"context"
"embed"
"fmt"
"io/fs"
"net/url"
"testing"

"github.com/dop251/goja"
"github.com/stretchr/testify/require"
"go.k6.io/k6/js/common"
"go.k6.io/k6/js/compiler"
"go.k6.io/k6/js/eventloop"
Expand Down Expand Up @@ -111,40 +107,3 @@ func (r *Runtime) innerSetupModuleSystem() error {
impl := modules.NewLegacyRequireImpl(r.VU, ms, url.URL{})
return r.VU.RuntimeField.Set("require", impl.Require)
}

//go:embed wptutils/*
var wptutils embed.FS

// NewRuntimeForWPT will create a new test runtime like NewRuntime, but ready to be used
// for Web Platform Tests (https://github.com/web-platform-tests/wpt).
func NewRuntimeForWPT(t testing.TB) *Runtime {
var err error
runtime := NewRuntime(t)

// We want to make the [console.log()] available for Web Platform Tests, as it
// is very useful for debugging, because we don't have a real debugger for JS code.
logger := runtime.VU.InitEnvField.Logger
require.NoError(t, runtime.VU.RuntimeField.Set("console", newConsole(logger)))

// We compile the Web Platform Tests harness scripts into a goja.Program,
// and execute them in the goja runtime in order to make the Web Platform
// assertion functions available to the tests.
files, err := fs.ReadDir(wptutils, "wptutils")
require.NoError(t, err)

for _, file := range files {
// Skip directories for safety,
// as we expect all files to be present in the root.
if file.IsDir() {
continue
}

program, err := CompileFileFromFS(wptutils, fmt.Sprintf("wptutils/%s", file.Name()))
require.NoError(t, err)

_, err = runtime.VU.Runtime().RunProgram(program)
require.NoError(t, err)
}

return runtime
}
26 changes: 0 additions & 26 deletions js/modulestest/wptutils/readable-stream-to-array.js

This file was deleted.

Loading

0 comments on commit 3ecab30

Please sign in to comment.