How to use runTC39Test method of tc39 Package

Best K6 code snippet using tc39.runTC39Test


Source:tc39_test.go Github


Full Screen

...75 return nil, "", errors.New("negative type is set, but phase isn't")76 }77 return &meta, str, nil78}79func runTC39Test(base, name, src string, meta *tc39Meta, t testing.TB, ctx *tc39TestCtx) {80 vm := New()81 err, early := runTC39Script(base, name, src, meta.Includes, ctx, vm)82 if err != nil {83 if meta.Negative.Type == "" {84 t.Fatalf("%s: %v", name, err)85 } else {86 if meta.Negative.Phase == "early" && !early || meta.Negative.Phase == "runtime" && early {87 t.Fatalf("%s: error %v happened at the wrong phase (expected %s)", name, err, meta.Negative.Phase)88 }89 var errType string90 switch err := err.(type) {91 case *Exception:92 if o, ok := err.Value().(*Object); ok {93 if c := o.Get("constructor"); c != nil {94 if c, ok := c.(*Object); ok {95 errType = c.Get("name").String()96 } else {97 t.Fatalf("%s: error constructor is not an object (%v)", name, o)98 }99 } else {100 t.Fatalf("%s: error does not have a constructor (%v)", name, o)101 }102 } else {103 t.Fatalf("%s: error is not an object (%v)", name, err.Value())104 }105 case *CompilerSyntaxError:106 errType = "SyntaxError"107 case *CompilerReferenceError:108 errType = "ReferenceError"109 default:110 t.Fatalf("%s: error is not a JS error: %v", name, err)111 }112 if errType != meta.Negative.Type {113 vm.vm.prg.dumpCode(t.Logf)114 t.Fatalf("%s: unexpected error type (%s), expected (%s)", name, errType, meta.Negative.Type)115 }116 }117 } else {118 if meta.Negative.Type != "" {119 vm.vm.prg.dumpCode(t.Logf)120 t.Fatalf("%s: Expected error: %v", name, err)121 }122 }123}124func runTC39File(base, name string, t testing.TB, ctx *tc39TestCtx) {125 if skipList[name] {126 t.Logf("Skipped %s", name)127 return128 }129 p := path.Join(base, name)130 meta, src, err := parseTC39File(p)131 if err != nil {132 //t.Fatalf("Could not parse %s: %v", name, err)133 t.Errorf("Could not parse %s: %v", name, err)134 return135 }136 if meta.Es5id == "" {137 //t.Logf("%s: Not ES5, skipped", name)138 return139 }140 hasRaw := meta.hasFlag("raw")141 if hasRaw || !meta.hasFlag("onlyStrict") {142 //log.Printf("Running normal test: %s", name)143 //t.Logf("Running normal test: %s", name)144 runTC39Test(base, name, src, meta, t, ctx)145 }146 if !hasRaw && !meta.hasFlag("noStrict") {147 //log.Printf("Running strict test: %s", name)148 //t.Logf("Running strict test: %s", name)149 runTC39Test(base, name, "'use strict';\n"+src, meta, t, ctx)150 }151}152func (ctx *tc39TestCtx) runFile(base, name string, vm *Runtime) error {153 prg := ctx.prgCache[name]154 if prg == nil {155 fname := path.Join(base, name)156 f, err := os.Open(fname)157 if err != nil {158 return err159 }160 defer f.Close()161 b, err := ioutil.ReadAll(f)162 if err != nil {163 return err164 }165 str := string(b)166 prg, err = Compile(name, str, false)167 if err != nil {168 return err169 }170 ctx.prgCache[name] = prg171 }172 _, err := vm.RunProgram(prg)173 return err174}175func runTC39Script(base, name, src string, includes []string, ctx *tc39TestCtx, vm *Runtime) (err error, early bool) {176 early = true177 err = ctx.runFile(base, path.Join("harness", "assert.js"), vm)178 if err != nil {179 return180 }181 err = ctx.runFile(base, path.Join("harness", "sta.js"), vm)182 if err != nil {183 return184 }185 for _, include := range includes {186 err = ctx.runFile(base, path.Join("harness", include), vm)187 if err != nil {188 return189 }190 }191 var p *Program192 p, err = Compile(name, src, false)193 if err != nil {194 return195 }196 early = false197 _, err = vm.RunProgram(p)198 return199}200func runTC39Tests(base, name string, t *testing.T, ctx *tc39TestCtx) {201 files, err := ioutil.ReadDir(path.Join(base, name))202 if err != nil {203 t.Fatal(err)204 }205 for _, file := range files {206 if file.Name()[0] == '.' {207 continue208 }209 if file.IsDir() {210 runTC39Tests(base, path.Join(name, file.Name()), t, ctx)211 } else {212 if strings.HasSuffix(file.Name(), ".js") {213 runTC39File(base, path.Join(name, file.Name()), t, ctx)214 }215 }216 }217}218func TestTC39(t *testing.T) {219 if testing.Short() {220 t.Skip()221 }222 if _, err := os.Stat(tc39BASE); err != nil {223 t.Skipf("If you want to run tc39 tests, download them from and put into %s. The last working commit is 1ba3a7c4a93fc93b3d0d7e4146f59934a896837d. (%v)", tc39BASE, err)224 }225 ctx := &tc39TestCtx{226 prgCache: make(map[string]*Program),227 }228 //_ = "breakpoint"229 //runTC39File(tc39BASE, "test/language/types/number/8.5.1.js", t, ctx)230 //runTC39Tests(tc39BASE, "test/language", t, ctx)231 runTC39Tests(tc39BASE, "test/language/expressions", t, ctx)232 runTC39Tests(tc39BASE, "test/language/arguments-object", t, ctx)233 runTC39Tests(tc39BASE, "test/language/asi", t, ctx)234 runTC39Tests(tc39BASE, "test/language/directive-prologue", t, ctx)235 runTC39Tests(tc39BASE, "test/language/function-code", t, ctx)236 runTC39Tests(tc39BASE, "test/language/eval-code", t, ctx)237 runTC39Tests(tc39BASE, "test/language/global-code", t, ctx)238 runTC39Tests(tc39BASE, "test/language/identifier-resolution", t, ctx)239 runTC39Tests(tc39BASE, "test/language/identifiers", t, ctx)240 //runTC39Tests(tc39BASE, "test/language/literals", t, ctx) // octal sequences in strict mode241 runTC39Tests(tc39BASE, "test/language/punctuators", t, ctx)242 runTC39Tests(tc39BASE, "test/language/reserved-words", t, ctx)243 runTC39Tests(tc39BASE, "test/language/source-text", t, ctx)244 runTC39Tests(tc39BASE, "test/language/statements", t, ctx)245 runTC39Tests(tc39BASE, "test/language/types", t, ctx)246 runTC39Tests(tc39BASE, "test/language/white-space", t, ctx)247 runTC39Tests(tc39BASE, "test/built-ins", t, ctx)248 runTC39Tests(tc39BASE, "test/annexB/built-ins/String/prototype/substr", t, ctx)249}...

Full Screen

Full Screen


Using AI Code Generation


Full Screen

1import (2func main() {3 vm := otto.New()4 vm.Run(`5 tc39 = {6 runTC39Test: function (test) {7 console.log(test);8 }9 };10 value, err := vm.Get("tc39")11 if err != nil {12 panic(err)13 }14 tc39, err := value.Export()15 if err != nil {16 panic(err)17 }18 fmt.Println(tc39.(map[string]interface{})["runTC39Test"].(func

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?