Skip to content
Closed
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
15 changes: 13 additions & 2 deletions internal/cmd/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@ func newIOFSBridge(fs fsext.Fs, pwd string) fs.FS {

// Open implements fs.Fs Open
func (b *ioFSBridge) Open(name string) (fs.File, error) {
f, err := b.fsext.Open(path.Join(b.pwd, name))
_ = fsext.Walk(b.fsext, "/", func(path string, _ fs.FileInfo, _ error) error {
fmt.Println("walk: ", path)
return nil
})
fmt.Println("ioFSBridge.Open", name)
name = filepath.ToSlash(filepath.Clean(fsext.FilePathSeparator + name))
fmt.Println("ioFSBridge.Open post clean up", name)
if !path.IsAbs(name) {
name = path.Join(b.pwd, name)
}
fmt.Println("ioFSBridge.Open post isAbs", name)
f, err := b.fsext.Open(name)
if err != nil {
return nil, fmt.Errorf("opening file via launcher's bridge: %w", err)
}
Expand Down Expand Up @@ -324,7 +335,7 @@ func analyze(gs *state.GlobalState, args []string) (k6deps.Dependencies, error)
}
dopts.Script.Name = sourceRootPath
dopts.Script.Contents = src.Data
dopts.Fs = newIOFSBridge(gs.FS, pwd)
dopts.Fs = newIOFSBridge(gs.FS, filepath.ToSlash(pwd))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason for not doing as same as readsource is doing?

pwdURL := &url.URL{Scheme: "file", Path: filepath.ToSlash(filepath.Clean(pwd)) + "/"}

}

return k6deps.Analyze(dopts)
Expand Down
55 changes: 55 additions & 0 deletions internal/cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,61 @@ func TestAbortedByScriptSetupErrorWithDependency(t *testing.T) {
assert.Contains(t, stdout, "bogus summary")
}

func TestRunFromNotBaseDirectory(t *testing.T) {
t.Parallel()
depScript := `
export const p = 5;
`
mainScript := `
import { p } from "../../../b/dep.js";
export default function() {
console.log("p = " + p);
};
`

ts := NewGlobalTestState(t)
require.NoError(t, fsext.WriteFile(ts.FS, filepath.Join(ts.Cwd, "a/b/c/test.js"), []byte(mainScript), 0o644))
require.NoError(t, fsext.WriteFile(ts.FS, filepath.Join(ts.Cwd, "b/dep.js"), []byte(depScript), 0o644))

ts.Cwd = filepath.Join(ts.Cwd, "./a/")
ts.CmdArgs = []string{"k6", "run", "-v", "--log-output=stdout", "b/c/test.js"}

cmd.ExecuteWithGlobalState(ts.GlobalState)

stdout := ts.Stdout.String()
t.Log(stdout)
require.Contains(t, stdout, `p = 5`)
}

func TestRunFromSeparateDriveWindows(t *testing.T) {
t.Parallel()
if runtime.GOOS != "windows" {
t.Skip("test only for windows")
}
depScript := `
export const p = 5;
`
mainScript := `
import { p } from "../../../b/dep.js";
export default function() {
console.log("p = " + p);
};
`

ts := NewGlobalTestState(t)
require.NoError(t, fsext.WriteFile(ts.FS, filepath.Join(ts.Cwd, "a/b/c/test.js"), []byte(mainScript), 0o644))
require.NoError(t, fsext.WriteFile(ts.FS, filepath.Join(ts.Cwd, "b/dep.js"), []byte(depScript), 0o644))

ts.Cwd = "f:\\something somewhere\\and another\\"
ts.CmdArgs = []string{"k6", "run", "-v", "--log-output=stdout", "c:\\test\\a\\b\\c\\test.js"}

cmd.ExecuteWithGlobalState(ts.GlobalState)

stdout := ts.Stdout.String()
t.Log(stdout)
require.Contains(t, stdout, `p = 5`)
}

func runTestWithNoLinger(_ *testing.T, ts *GlobalTestState) {
cmd.ExecuteWithGlobalState(ts.GlobalState)
}
Expand Down
11 changes: 1 addition & 10 deletions vendor/github.com/grafana/k6deps/internal/rootfs/rootfs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading