[add] migrate scirpt
This commit is contained in:
parent
4139a751a9
commit
cef5b38be5
2 changed files with 25 additions and 30 deletions
|
|
@ -11,33 +11,10 @@ import (
|
|||
func Load(cfg config.Config) error {
|
||||
exts := []string{"*.js"}
|
||||
return application.App.Walk("scripts", func(root, file string, isdir bool) error {
|
||||
if isdir {
|
||||
return nil
|
||||
}
|
||||
_, err := v8.Load(file, share.ID(root, file))
|
||||
return err
|
||||
}, exts...)
|
||||
|
||||
// return LoadFrom(filepath.Join(cfg.Root, "services"), "__yao_service.")
|
||||
}
|
||||
|
||||
// // LoadBuildIn 从制品中读取
|
||||
// func LoadBuildIn(dir string) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// // LoadFrom 从特定目录加载共享库
|
||||
// func LoadFrom(dir string, prefix string) error {
|
||||
|
||||
// if share.DirNotExists(dir) {
|
||||
// log.Error("%s does not exists", dir)
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// // 加载共享脚本
|
||||
// err := share.Walk(dir, ".js", func(root, filename string) {
|
||||
// name := share.SpecName(root, filename)
|
||||
// err := gou.Yao.Load(filename, fmt.Sprintf("%s%s", prefix, name))
|
||||
// if err != nil {
|
||||
// log.Error("加载脚本失败 %s", err.Error())
|
||||
// }
|
||||
// })
|
||||
// return err
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -2,10 +2,28 @@ package script
|
|||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
v8 "github.com/yaoapp/gou/runtime/v8"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/test"
|
||||
)
|
||||
|
||||
func TestScript(t *testing.T) {
|
||||
// res, err := gou.Yao.New("time", "hello").Call("world")
|
||||
// assert.Nil(t, err)
|
||||
// assert.Equal(t, "name:world", res)
|
||||
func TestLoad(t *testing.T) {
|
||||
test.Prepare(t, config.Conf)
|
||||
defer test.Clean()
|
||||
|
||||
Load(config.Conf)
|
||||
check(t)
|
||||
}
|
||||
|
||||
func check(t *testing.T) {
|
||||
ids := map[string]bool{}
|
||||
for id := range v8.Scripts {
|
||||
ids[id] = true
|
||||
}
|
||||
assert.True(t, ids["tests.task.mail"])
|
||||
assert.True(t, ids["tests.api"])
|
||||
assert.True(t, ids["runtime.basic"])
|
||||
assert.True(t, ids["runtime.bridge"])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue